diff --git a/README.md b/README.md index 8b89288..1d6d22b 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,7 @@ module "meraki" { | [api\_key](#input\_api\_key) | n/a | `string` | n/a | yes | | [model](#input\_model) | As an alternative to YAML files, a native Terraform data structure can be provided as well. | `map(any)` | `{}` | no | | [write\_default\_values\_file](#input\_write\_default\_values\_file) | Write all default values to a YAML file. Value is a path pointing to the file to be created. | `string` | `""` | no | +| [write\_merged\_yaml\_file](#input\_write\_merged\_yaml\_file) | The path where the merged YAML output should be written | `string` | `""` | no | | [yaml\_directories](#input\_yaml\_directories) | List of paths to YAML directories. | `list(string)` | `[]` | no | | [yaml\_files](#input\_yaml\_files) | List of paths to YAML files. | `list(string)` | `[]` | no | ## Outputs @@ -66,6 +67,7 @@ module "meraki" { | Name | Type | |------|------| +| [local_file.merged_yaml_output](https://registry.terraform.io/providers/hashicorp/local/latest/docs/resources/file) | resource | | [local_sensitive_file.defaults](https://registry.terraform.io/providers/hashicorp/local/latest/docs/resources/sensitive_file) | resource | | [meraki_network.network](https://registry.terraform.io/providers/CiscoDevNet/meraki/0.1.2/docs/resources/network) | resource | | [meraki_network_device_claim.net_device_claim](https://registry.terraform.io/providers/CiscoDevNet/meraki/0.1.2/docs/resources/network_device_claim) | resource | diff --git a/meraki_organization.tf b/meraki_organization.tf index 47df84b..95af640 100644 --- a/meraki_organization.tf +++ b/meraki_organization.tf @@ -362,12 +362,10 @@ resource "meraki_organization_policy_object" "policy_object" { category = each.value.category name = each.value.name type = each.value.type - - # Conditionally apply fields - cidr = try(each.value.cidr, null) - fqdn = try(each.value.fqdn, null) - mask = try(each.value.mask, null) - ip = try(each.value.ip, null) + cidr = try(each.value.cidr, null) + fqdn = try(each.value.fqdn, null) + mask = try(each.value.mask, null) + ip = try(each.value.ip, null) } locals { @@ -375,34 +373,24 @@ locals { for domain in try(local.meraki.domains, []) : [ for organization in try(domain.organizations, []) : [ for group in try(organization.policy_objects_groups, []) : { - org_id = data.meraki_organization.organization[organization.name].id - name = group.name - category = group.category - object_names = try(group.object_ids, []) # This refers to the names from YAML, which will be mapped to IDs + org_id = data.meraki_organization.organization[organization.name].id + name = group.name + category = group.category + object_ids = try(group.object_names, []) } if try(organization.policy_objects_groups, null) != null ] ] ]) - - # Map object names to their IDs - policy_object_id_map = { - for obj in meraki_organization_policy_object.policy_object : obj.name => obj.id - } } -# Create Policy Object Groups +# Create Policy Object Groups (if applicable) resource "meraki_organization_policy_object_group" "policy_object_group" { for_each = { for group in local.policy_object_groups : group.name => group } organization_id = each.value.org_id - category = each.value.category name = each.value.name - - # Use the object names provided in YAML and map them to their corresponding object IDs - object_ids = [ - for obj_name in each.value.object_names : local.policy_object_id_map[obj_name] - ] - depends_on = [meraki_organization_policy_object.policy_object] + category = each.value.category + object_ids = each.value.object_ids } //TODO Organization Appliance VPN Settings diff --git a/merge.tf b/merge.tf index 6a3e941..a67cdae 100644 --- a/merge.tf +++ b/merge.tf @@ -28,6 +28,12 @@ data "utils_yaml_merge" "defaults" { input = [file("${path.module}/defaults/defaults.yaml"), yamlencode(local.user_defaults)] } +resource "local_file" "merged_yaml_output" { + count = var.write_merged_yaml_file != "" ? 1 : 0 + content = data.utils_yaml_merge.model.output + filename = var.write_merged_yaml_file +} + resource "local_sensitive_file" "defaults" { count = var.write_default_values_file != "" ? 1 : 0 content = data.utils_yaml_merge.defaults.output diff --git a/variables.tf b/variables.tf index 7d1f3cf..21fe694 100644 --- a/variables.tf +++ b/variables.tf @@ -25,3 +25,9 @@ variable "write_default_values_file" { variable "api_key" { type = string } + +variable "write_merged_yaml_file" { + type = string + description = "The path where the merged YAML output should be written" + default = "" +}