Skip to content

Commit

Permalink
Merge pull request #3 from mcparaf/main
Browse files Browse the repository at this point in the history
draft: meraki networks mvp support
  • Loading branch information
jon-humphries authored Jul 8, 2024
2 parents 2e3c9f8 + e478ce2 commit 0b55a32
Show file tree
Hide file tree
Showing 5 changed files with 872 additions and 66 deletions.
46 changes: 46 additions & 0 deletions generate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env python3

###

import json

template = """
### marcin generated
### resource name: {RESOURCE_NAME}
### values: {VALUES}
locals {{
networks_{RESOURCE_NAME} = flatten([
for domain in try(local.meraki.domains, []) : [
for org in try(domain.organizations, []) : [
for network in try(org.networks, []) : {{
network_id = meraki_networks.networks["${{domain.name}}/${{org.name}}/${{network.name}}"].id
data = network.{RESOURCE_NAME}
}} if try(network.{RESOURCE_NAME}, null) != null
]
]
])
}}
resource "meraki_networks_{RESOURCE_NAME}" "net_{RESOURCE_NAME}" {{
for_each = {{ for data in local.networks_{RESOURCE_NAME} : data.network_id => data.data }}
network_id = each.key
{values_render}
}}
"""

def generate_template(resource, values):
values_render = ""
for v in values:
values_render += " {v} = try(each.value.{v}, null)\n".format(v=v)
return template.format(RESOURCE_NAME=resource, VALUES=values, values_render=values_render.strip())

with open("/Users/maparafi/test_meraki/schema.json") as f:
contents = f.read()

j = json.loads(contents)

for k, v in j["provider_schemas"]["registry.terraform.io/cisco-open/meraki"]["resource_schemas"].items():
if k.startswith("meraki_networks_wireless"):
print(generate_template(k[16:], [kk for kk, vv in v["block"]["attributes"].items() if kk != "network_id"]))
Loading

0 comments on commit 0b55a32

Please sign in to comment.