From b24795656e7be37c8f437d15c5b9ed81c0576091 Mon Sep 17 00:00:00 2001 From: Matt White <16320656+matt-FFFFFF@users.noreply.github.com> Date: Thu, 7 Mar 2024 17:48:05 +0000 Subject: [PATCH 1/5] fix: compat with 0.10.0 --- main.tf | 25 ++++------------ terraform.tf | 8 +++--- variables.tf | 80 +++++----------------------------------------------- 3 files changed, 16 insertions(+), 97 deletions(-) diff --git a/main.tf b/main.tf index e59a357..ae6f555 100644 --- a/main.tf +++ b/main.tf @@ -1,13 +1,5 @@ data "alz_archetype_keys" "this" { - base_archetype = var.base_archetype - policy_assignments_to_add = keys(var.policy_assignments_to_add) - policy_assignments_to_remove = var.policy_assignments_to_remove - policy_definitions_to_add = var.policy_definitions_to_add - policy_definitions_to_remove = var.policy_definitions_to_remove - policy_set_definitions_to_add = var.policy_set_definitions_to_add - policy_set_definitions_to_remove = var.policy_set_definitions_to_remove - role_definitions_to_add = var.role_definitions_to_add - role_definitions_to_remove = var.role_definitions_to_remove + base_archetype = var.base_archetype } data "alz_archetype" "this" { @@ -17,17 +9,10 @@ data "alz_archetype" "this" { log_analytics_workspace_id = var.default_log_analytics_workspace_id private_dns_zone_resource_group_id = var.default_private_dns_zone_resource_group_id } - display_name = var.display_name - base_archetype = var.base_archetype - parent_id = var.parent_id - policy_assignments_to_add = var.policy_assignments_to_add - policy_assignments_to_remove = var.policy_assignments_to_remove - policy_definitions_to_add = var.policy_definitions_to_add - policy_definitions_to_remove = var.policy_definitions_to_remove - policy_set_definitions_to_add = var.policy_set_definitions_to_add - policy_set_definitions_to_remove = var.policy_set_definitions_to_remove - role_definitions_to_add = var.role_definitions_to_add - role_definitions_to_remove = var.role_definitions_to_remove + display_name = var.display_name + base_archetype = var.base_archetype + parent_id = var.parent_id + policy_assignments_to_modify = var.policy_assignments_to_modify } resource "azurerm_management_group" "this" { diff --git a/terraform.tf b/terraform.tf index ab42ba6..d584cd8 100644 --- a/terraform.tf +++ b/terraform.tf @@ -3,19 +3,19 @@ terraform { required_providers { alz = { source = "azure/alz" - version = ">= 0.5.1" + version = "~> 0.10" } azurerm = { source = "hashicorp/azurerm" - version = ">= 3.74.0" + version = "~> 3.74" } time = { source = "hashicorp/time" - version = ">= 0.9.1" + version = "~> 0.9" } random = { source = "hashicorp/random" - version = ">= 3.5.0" + version = "~> 3.5" } } } diff --git a/variables.tf b/variables.tf index 46bffb1..81785c5 100644 --- a/variables.tf +++ b/variables.tf @@ -73,16 +73,12 @@ Included to work around some race conditions in Azure. DESCRIPTION } -variable "policy_assignments_to_add" { +variable "policy_assignments_to_modify" { type = map(object({ - display_name = optional(string, null) - enforcement_mode = optional(string, null) - identity = optional(string, null) - identity_ids = optional(list(string), null) - policy_definition_id = optional(string, null) - policy_definition_name = optional(string, null) - policy_set_definition_name = optional(string, null) - parameters = optional(string, null) + enforcement_mode = optional(string, null) + identity = optional(string, null) + identity_ids = optional(list(string), null) + parameters = optional(string, null) non_compliance_message = optional(set(object({ message = string policy_definition_reference_id = optional(string, null) @@ -90,13 +86,12 @@ variable "policy_assignments_to_add" { })) default = {} description = < Date: Thu, 7 Mar 2024 20:36:40 +0000 Subject: [PATCH 2/5] feat: complete compat to alz provider v0.10 --- README.md | 152 ++++++++++-------------------- examples/alzreference/README.md | 3 +- examples/alzreference/_footer.md | 0 examples/default/README.md | 40 ++++++++ examples/default/_footer.md | 0 examples/default/_header.md | 3 + examples/default/main.tf | 0 examples/dynamic-input/README.md | 32 +++++-- examples/dynamic-input/_footer.md | 0 variables.tf | 32 ++++++- 10 files changed, 147 insertions(+), 115 deletions(-) create mode 100644 examples/alzreference/_footer.md create mode 100644 examples/default/README.md create mode 100644 examples/default/_footer.md create mode 100644 examples/default/_header.md create mode 100644 examples/default/main.tf create mode 100644 examples/dynamic-input/_footer.md diff --git a/README.md b/README.md index f14d63e..aa9bc6f 100644 --- a/README.md +++ b/README.md @@ -13,25 +13,25 @@ The following requirements are needed by this module: - [terraform](#requirement\_terraform) (>= 1.0.0) -- [alz](#requirement\_alz) (>= 0.5.1) +- [alz](#requirement\_alz) (~> 0.10) -- [azurerm](#requirement\_azurerm) (>= 3.74.0) +- [azurerm](#requirement\_azurerm) (~> 3.74) -- [random](#requirement\_random) (>= 3.5.0) +- [random](#requirement\_random) (~> 3.5) -- [time](#requirement\_time) (>= 0.9.1) +- [time](#requirement\_time) (~> 0.9) ## Providers The following providers are used by this module: -- [alz](#provider\_alz) (>= 0.5.1) +- [alz](#provider\_alz) (~> 0.10) -- [azurerm](#provider\_azurerm) (>= 3.74.0) +- [azurerm](#provider\_azurerm) (~> 3.74) -- [random](#provider\_random) (>= 3.5.0) +- [random](#provider\_random) (~> 3.5) -- [time](#provider\_time) (>= 0.9.1) +- [time](#provider\_time) (~> 0.9) ## Resources @@ -147,89 +147,69 @@ Type: `bool` Default: `true` -### [policy\_assignments\_to\_add](#input\_policy\_assignments\_to\_add) +### [policy\_assignments\_to\_modify](#input\_policy\_assignments\_to\_modify) -Description: A map of policy assignment objects to add or update the alz archetype with. -When updating a policy assignment, you only need to specify the properties you want to change. +Description: A map of policy assignment objects to modify the ALZ archetype with. +You only need to specify the properties you want to change. The key is the name of the policy assignment. The value is a map of the properties of the policy assignment. -- `display_name` - (Optional) The display name of the policy assignment. - `enforcement_mode` - (Optional) The enforcement mode of the policy assignment. Possible values are `Default` and `DoNotEnforce`. - `identity` - (Optional) The identity of the policy assignment. Possible values are `SystemAssigned` and `UserAssigned`. - `identity_ids` - (Optional) A set of ids of the user assigned identities to assign to the policy assignment. - `non_compliance_message` - (Optional) A set of non compliance message objects to use for the policy assignment. Each object has the following properties: - `message` - (Required) The non compliance message. - `policy_definition_reference_id` - (Optional) The reference id of the policy definition to use for the non compliance message. -- `parameters` - (Optional) A JSON string of parameters to use for the policy assignment. Use `jsonencode()` to convert a map of the parameter names to values. -- `policy_definition_id` - (Optional) The id of the policy definition to assign to the policy assignment. Conflicts with `policy_definition_name` and `policy_set_definition_name`. -- `policy_definition_name` - (Optional) The name of the policy definition to assign to the policy assignment. Conflicts with `policy_definition_id` and `policy_set_definition_name`. -- `policy_set_definition_name` - (Optional) The name of the policy set definition to assign to the policy assignment. Conflicts with `policy_definition_id` and `policy_definition_name`. +- `parameters` - (Optional) A JSON string of parameters to use for the policy assignment. E.g. `jsonencode({"param1": "value1", "param2": 2})`. +- `resource_selectors` - (Optional) A list of resource selector objects to use for the policy assignment. Each object has the following properties: + - `name` - (Required) The name of the resource selector. + - `selectors` - (Optional) A list of selector objects to use for the resource selector. Each object has the following properties: + - `kind` - (Required) The kind of the selector. Allowed values are: `resourceLocation`, `resourceType`, `resourceWithoutLocation`. `resourceWithoutLocation` cannot be used in the same resource selector as `resourceLocation`. + - `in` - (Optional) A set of strings to include in the selector. + - `not_in` - (Optional) A set of strings to exclude from the selector. +- `overrides` - (Optional) A list of override objects to use for the policy assignment. Each object has the following properties: + - `kind` - (Required) The kind of the override. + - `value` - (Required) The value of the override. Supported values are policy effects: . + - `selectors` - (Optional) A list of selector objects to use for the override. Each object has the following properties: + - `kind` - (Required) The kind of the selector. + - `in` - (Optional) A set of strings to include in the selector. + - `not_in` - (Optional) A set of strings to exclude from the selector. Type: ```hcl map(object({ - display_name = optional(string, null) - enforcement_mode = optional(string, null) - identity = optional(string, null) - identity_ids = optional(list(string), null) - policy_definition_id = optional(string, null) - policy_definition_name = optional(string, null) - policy_set_definition_name = optional(string, null) - parameters = optional(string, null) + enforcement_mode = optional(string, null) + identity = optional(string, null) + identity_ids = optional(list(string), null) + parameters = optional(string, null) non_compliance_message = optional(set(object({ message = string policy_definition_reference_id = optional(string, null) })), null) + resource_selectors = optional(list(object({ + name = string + selectors = optional(list(object({ + kind = string + in = optional(set(string), null) + not_in = optional(set(string), null) + })), []) + }))) + overrides = optional(list(object({ + kind = string + value = string + selectors = optional(list(object({ + kind = string + in = optional(set(string), null) + not_in = optional(set(string), null) + })), []) + }))) })) ``` Default: `{}` -### [policy\_assignments\_to\_remove](#input\_policy\_assignments\_to\_remove) - -Description: A set of policy assignment names to remove from the `base_archetype`. - -Type: `set(string)` - -Default: `[]` - -### [policy\_definitions\_to\_add](#input\_policy\_definitions\_to\_add) - -Description: A set of policy definition names to add to the `base_archetype`. -The definition must exist in one of the loaded lib directories. - -Type: `set(string)` - -Default: `[]` - -### [policy\_definitions\_to\_remove](#input\_policy\_definitions\_to\_remove) - -Description: A set of policy definition names to remove from the `base_archetype`. - -Type: `set(string)` - -Default: `[]` - -### [policy\_set\_definitions\_to\_add](#input\_policy\_set\_definitions\_to\_add) - -Description: A set of policy set definition names to add to the `base_archetype`. -The definition must exist in one of the loaded lib directories. - -Type: `set(string)` - -Default: `[]` - -### [policy\_set\_definitions\_to\_remove](#input\_policy\_set\_definitions\_to\_remove) - -Description: A set of policy set definition names to remove from the `base_archetype`. - -Type: `set(string)` - -Default: `[]` - ### [role\_assignments](#input\_role\_assignments) Description: A map of role assignments to associated principals and role definitions to the management group. @@ -254,23 +234,6 @@ map(object({ Default: `{}` -### [role\_definitions\_to\_add](#input\_role\_definitions\_to\_add) - -Description: A set of role definition names to add to the `base_archetype`. -The definition must exist in one of the loaded lib directories. - -Type: `set(string)` - -Default: `[]` - -### [role\_definitions\_to\_remove](#input\_role\_definitions\_to\_remove) - -Description: A set of role definition names to remove from the `base_archetype`. - -Type: `set(string)` - -Default: `[]` - ### [subscription\_ids](#input\_subscription\_ids) Description: A set of subscription ids to move under this management group. @@ -299,25 +262,8 @@ Description: The id of the management group. No modules. -## Contributing - -This project welcomes contributions and suggestions. Most contributions require you to agree to a -Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us -the rights to use your contribution. For details, visit . - -When you submit a pull request, a CLA bot will automatically determine whether you need to provide -a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions -provided by the bot. You will only need to do this once across all repos using our CLA. - -This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). -For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or -contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. - -## Trademarks + +## Data Collection -This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft -trademarks or logos is subject to and must follow -[Microsoft's Trademark & Brand Guidelines](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks/usage/general). -Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. -Any use of third-party trademarks or logos are subject to those third-party's policies. +The software may collect information about you and your use of the software and send it to Microsoft. Microsoft may use this information to provide services and improve our products and services. You may turn off the telemetry as described in the repository. There are also some features in the software that may enable you and Microsoft to collect data from users of your applications. If you use these features, you must comply with applicable law, including providing appropriate notices to users of your applications together with a copy of Microsoft’s privacy statement. Our privacy statement is located at . You can learn more about data collection and use in the help documentation and our privacy statement. Your use of the software operates as your consent to these practices. \ No newline at end of file diff --git a/examples/alzreference/README.md b/examples/alzreference/README.md index 4582032..5081219 100644 --- a/examples/alzreference/README.md +++ b/examples/alzreference/README.md @@ -142,7 +142,7 @@ The following requirements are needed by this module: - [terraform](#requirement\_terraform) (>= 1.0.0) -- [alz](#requirement\_alz) (>= 0.5.1) +- [alz](#requirement\_alz) (>= 0.6.3) - [azurerm](#requirement\_azurerm) (>= 3.74.0) @@ -246,5 +246,4 @@ Source: Azure/naming/azurerm Version: >= 0.3.0 - \ No newline at end of file diff --git a/examples/alzreference/_footer.md b/examples/alzreference/_footer.md new file mode 100644 index 0000000..e69de29 diff --git a/examples/default/README.md b/examples/default/README.md new file mode 100644 index 0000000..e3d3ebe --- /dev/null +++ b/examples/default/README.md @@ -0,0 +1,40 @@ + +# Default + +TBC + +```hcl + +``` + + +## Requirements + +No requirements. + +## Providers + +No providers. + +## Resources + +No resources. + + +## Required Inputs + +No required inputs. + +## Optional Inputs + +No optional inputs. + +## Outputs + +No outputs. + +## Modules + +No modules. + + \ No newline at end of file diff --git a/examples/default/_footer.md b/examples/default/_footer.md new file mode 100644 index 0000000..e69de29 diff --git a/examples/default/_header.md b/examples/default/_header.md new file mode 100644 index 0000000..3d0b187 --- /dev/null +++ b/examples/default/_header.md @@ -0,0 +1,3 @@ +# Default + +TBC diff --git a/examples/default/main.tf b/examples/default/main.tf new file mode 100644 index 0000000..e69de29 diff --git a/examples/dynamic-input/README.md b/examples/dynamic-input/README.md index 5c6c533..2fb410c 100644 --- a/examples/dynamic-input/README.md +++ b/examples/dynamic-input/README.md @@ -12,9 +12,10 @@ resource "random_pet" "this" { } module "naming" { - source = "Azure/naming/azurerm" - suffix = [random_pet.this.id] - prefix = ["test-avm-ptn-alz"] + source = "Azure/naming/azurerm" + version = ">= 0.3.0" + suffix = [random_pet.this.id] + prefix = ["test-avm-ptn-alz"] } module "alz_management_resources" { @@ -39,6 +40,11 @@ module "management_groups_layer_1" { default_location = local.location default_log_analytics_workspace_id = module.alz_management_resources.log_analytics_workspace.id subscription_ids = try(each.value.subscription_ids, []) + delays = merge(local.default_delays, { + before_management_group_creation = { + create = "0s" + } + }) } module "management_groups_layer_2" { @@ -51,6 +57,7 @@ module "management_groups_layer_2" { default_location = local.location default_log_analytics_workspace_id = module.alz_management_resources.log_analytics_workspace.id subscription_ids = try(each.value.subscription_ids, []) + delays = local.default_delays } module "management_groups_layer_3" { @@ -63,6 +70,7 @@ module "management_groups_layer_3" { default_location = local.location default_log_analytics_workspace_id = module.alz_management_resources.log_analytics_workspace.id subscription_ids = try(each.value.subscription_ids, []) + delays = local.default_delays } module "management_groups_layer_4" { @@ -75,6 +83,7 @@ module "management_groups_layer_4" { default_location = local.location default_log_analytics_workspace_id = module.alz_management_resources.log_analytics_workspace.id subscription_ids = try(each.value.subscription_ids, []) + delays = local.default_delays } module "management_groups_layer_5" { @@ -87,6 +96,7 @@ module "management_groups_layer_5" { default_location = local.location default_log_analytics_workspace_id = module.alz_management_resources.log_analytics_workspace.id subscription_ids = try(each.value.subscription_ids, []) + delays = local.default_delays } module "management_groups_layer_6" { @@ -99,6 +109,7 @@ module "management_groups_layer_6" { default_location = local.location default_log_analytics_workspace_id = module.alz_management_resources.log_analytics_workspace.id subscription_ids = try(each.value.subscription_ids, []) + delays = local.default_delays } ``` @@ -107,17 +118,21 @@ module "management_groups_layer_6" { The following requirements are needed by this module: -- [azurerm](#requirement\_azurerm) (>= 2.79.0) +- [terraform](#requirement\_terraform) (>= 1.0.0) -- [random](#requirement\_random) (>= 3.5.1) +- [alz](#requirement\_alz) (>= 0.6.3) + +- [azurerm](#requirement\_azurerm) (>= 3.74.0) + +- [random](#requirement\_random) (>= 3.5.0) ## Providers The following providers are used by this module: -- [azurerm](#provider\_azurerm) (>= 2.79.0) +- [azurerm](#provider\_azurerm) (>= 3.74.0) -- [random](#provider\_random) (>= 3.5.1) +- [random](#provider\_random) (>= 3.5.0) ## Resources @@ -193,7 +208,6 @@ Version: Source: Azure/naming/azurerm -Version: - +Version: >= 0.3.0 \ No newline at end of file diff --git a/examples/dynamic-input/_footer.md b/examples/dynamic-input/_footer.md new file mode 100644 index 0000000..e69de29 diff --git a/variables.tf b/variables.tf index 81785c5..d0d8098 100644 --- a/variables.tf +++ b/variables.tf @@ -83,6 +83,23 @@ variable "policy_assignments_to_modify" { message = string policy_definition_reference_id = optional(string, null) })), null) + resource_selectors = optional(list(object({ + name = string + selectors = optional(list(object({ + kind = string + in = optional(set(string), null) + not_in = optional(set(string), null) + })), []) + }))) + overrides = optional(list(object({ + kind = string + value = string + selectors = optional(list(object({ + kind = string + in = optional(set(string), null) + not_in = optional(set(string), null) + })), []) + }))) })) default = {} description = <. + - `selectors` - (Optional) A list of selector objects to use for the override. Each object has the following properties: + - `kind` - (Required) The kind of the selector. + - `in` - (Optional) A set of strings to include in the selector. + - `not_in` - (Optional) A set of strings to exclude from the selector. DESCRIPTION } From 6ee556ed3293afdb26a99cffd450f19cc8604067 Mon Sep 17 00:00:00 2001 From: Matt White <16320656+matt-FFFFFF@users.noreply.github.com> Date: Thu, 7 Mar 2024 20:42:18 +0000 Subject: [PATCH 3/5] chore: pre-release --- .gitignore | 3 +++ examples/alzreference/main.tf | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 470f60f..63241b5 100644 --- a/.gitignore +++ b/.gitignore @@ -44,3 +44,6 @@ avmmakefile .DS_Store avm.tflint.merged.hcl avm.tflint_example.merged.hcl + +# Ignore the provider download cache +.alzlib diff --git a/examples/alzreference/main.tf b/examples/alzreference/main.tf index 75bb979..24fe373 100644 --- a/examples/alzreference/main.tf +++ b/examples/alzreference/main.tf @@ -5,14 +5,14 @@ resource "random_pet" "this" { module "naming" { source = "Azure/naming/azurerm" - version = ">= 0.3.0" + version = "~> 0.3" suffix = [random_pet.this.id] prefix = ["test-avm-ptn-alz"] } module "alz_management_resources" { source = "Azure/alz-management/azurerm" - version = "~> 0.1.0" + version = "~> 0.1" automation_account_name = module.naming.automation_account.name location = local.default_location From 7cf41295972551b4541e8574faf7ef2bdd455aae Mon Sep 17 00:00:00 2001 From: Matt White <16320656+matt-FFFFFF@users.noreply.github.com> Date: Fri, 8 Mar 2024 10:17:25 +0000 Subject: [PATCH 4/5] chore: lint --- examples/default/main.tf | 4 ++++ examples/dynamic-input/outputs.tf | 1 + locals.telemetry.tf | 27 +++++++++++++-------------- locals.version.tf.json | 2 +- main.telemetry.tf | 2 +- terraform.tf | 8 ++++---- 6 files changed, 24 insertions(+), 20 deletions(-) diff --git a/examples/default/main.tf b/examples/default/main.tf index e69de29..c257092 100644 --- a/examples/default/main.tf +++ b/examples/default/main.tf @@ -0,0 +1,4 @@ +terraform { + required_version = ">= 1.0.0" + required_providers {} +} diff --git a/examples/dynamic-input/outputs.tf b/examples/dynamic-input/outputs.tf index da73573..a6c920e 100644 --- a/examples/dynamic-input/outputs.tf +++ b/examples/dynamic-input/outputs.tf @@ -7,4 +7,5 @@ output "test" { management_groups_layer_5 = local.management_groups_layer_5 management_groups_layer_6 = local.management_groups_layer_6 } + description = "An object containing the management groups for each layer." } diff --git a/locals.telemetry.tf b/locals.telemetry.tf index e485d5a..610a756 100644 --- a/locals.telemetry.tf +++ b/locals.telemetry.tf @@ -18,21 +18,20 @@ locals { 64 ) # This is an empty ARM deployment template. - telem_arm_template_content = <