Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import json
|
3 |
+
|
4 |
+
# Simulate some mock existing resources (you can customize this)
|
5 |
+
existing_resources = {
|
6 |
+
"storageAccount1": {
|
7 |
+
"type": "Microsoft.Storage/storageAccounts",
|
8 |
+
"location": "East US",
|
9 |
+
"status": "existing"
|
10 |
+
}
|
11 |
+
}
|
12 |
+
|
13 |
+
# Function to simulate ARM template deployment evaluation
|
14 |
+
def simulate_deployment(arm_template):
|
15 |
+
try:
|
16 |
+
# Load ARM template from pasted JSON
|
17 |
+
template = json.loads(arm_template)
|
18 |
+
|
19 |
+
# Initialize lists for tracking resources to be created, updated, or deleted
|
20 |
+
resources_to_create = []
|
21 |
+
resources_to_update = []
|
22 |
+
resources_to_delete = []
|
23 |
+
|
24 |
+
# Check the resources in the template
|
25 |
+
for resource in template.get('resources', []):
|
26 |
+
resource_name = resource.get('name')
|
27 |
+
resource_type = resource.get('type')
|
28 |
+
location = resource.get('location')
|
29 |
+
|
30 |
+
# Simulate creation or update
|
31 |
+
if resource_name in existing_resources:
|
32 |
+
if (existing_resources[resource_name]['type'] == resource_type
|
33 |
+
and existing_resources[resource_name]['location'] == location):
|
34 |
+
resources_to_update.append(resource_name)
|
35 |
+
else:
|
36 |
+
resources_to_create.append(resource_name) # Re-create if major properties change
|
37 |
+
else:
|
38 |
+
resources_to_create.append(resource_name)
|
39 |
+
|
40 |
+
# Simulate deletion (if something in the template isn't in the mock cloud)
|
41 |
+
for resource_name in existing_resources:
|
42 |
+
if resource_name not in [r.get('name') for r in template.get('resources', [])]:
|
43 |
+
resources_to_delete.append(resource_name)
|
44 |
+
|
45 |
+
# Return results
|
46 |
+
return resources_to_create, resources_to_update, resources_to_delete
|
47 |
+
|
48 |
+
except json.JSONDecodeError:
|
49 |
+
st.error("Invalid JSON format. Please check your ARM template.")
|
50 |
+
return [], [], []
|
51 |
+
|
52 |
+
# Streamlit UI
|
53 |
+
st.title("ARM Template Simulator")
|
54 |
+
st.subheader("Paste your ARM template below to simulate its deployment.")
|
55 |
+
|
56 |
+
# Input box for ARM template
|
57 |
+
template_input = st.text_area("Paste ARM Template JSON here:", height=300)
|
58 |
+
|
59 |
+
# Button to simulate the evaluation
|
60 |
+
if st.button("Simulate Template"):
|
61 |
+
if template_input:
|
62 |
+
resources_to_create, resources_to_update, resources_to_delete = simulate_deployment(template_input)
|
63 |
+
|
64 |
+
# Display results
|
65 |
+
st.subheader("Simulation Results:")
|
66 |
+
|
67 |
+
st.write("### Resources to be Created:")
|
68 |
+
if resources_to_create:
|
69 |
+
st.write(resources_to_create)
|
70 |
+
else:
|
71 |
+
st.write("No new resources will be created.")
|
72 |
+
|
73 |
+
st.write("### Resources to be Updated:")
|
74 |
+
if resources_to_update:
|
75 |
+
st.write(resources_to_update)
|
76 |
+
else:
|
77 |
+
st.write("No resources will be updated.")
|
78 |
+
|
79 |
+
st.write("### Resources to be Deleted:")
|
80 |
+
if resources_to_delete:
|
81 |
+
st.write(resources_to_delete)
|
82 |
+
else:
|
83 |
+
st.write("No resources will be deleted.")
|
84 |
+
else:
|
85 |
+
st.error("Please paste an ARM template to simulate.")
|