Azure / terraform-azurerm-caf-enterprise-scale

Azure landing zones Terraform module
https://aka.ms/alz/tf
MIT License
869 stars 574 forks source link

custom library folder - Bug #470

Closed mikeilunga closed 2 years ago

mikeilunga commented 2 years ago

Community Note

Versions

terraform: v1.1.3

azure provider: v3.24.0

module: 2.4.0

Description

When deploying policies and management groups to our custom landing zones, we specify a "custom library path" folder location and the respective policies are configured as expected. However, the archetype artefacts are not placed in the specified path and can only be managed and maintained in the .terraform directory.

Describe the bug

The following variable "library_path" should allow me to choose a custom library folder, this will help with the management of code as we are using Azure DevOps repo to store this code so ideally, we do not want to store the file in a temp directory. Moreover, we were able to complete these steps in a previous iteration of the code version "1.1.2"

Steps to Reproduce

  1. add variable variable "library_path" { type = string description = "Achetype library path" default = ""}

  2. add value in tfvars library_path = "/modules/archetypes/lib"

  3. Create/ensure the respective folder directories are in place

  4. Run terraform apply and once resources are deployed.

  5. Check if the archetypes are in the custom directory.

Screenshots

Additional context

Screenshot 1 - example of custom library path not working Screenshot 2 - example of custom library path working in the previous version 1.1.2

Screenshot 1

jtracey93 commented 2 years ago

Hey @mikeilunga,

Have you seen and followed: https://github.com/Azure/terraform-azurerm-caf-enterprise-scale/wiki/%5BExamples%5D-Deploy-Custom-Landing-Zone-Archetypes

The archetypes are not pulled into the repo, you must define custom lib artefacts and reference them, if you wish, in the module variables.

e.g. creating a policy assignment https://github.com/Azure/terraform-azurerm-caf-enterprise-scale/wiki/%5BExamples%5D-Assign-a-Built-in-Policy

Let us know

krowlandson commented 2 years ago

@mikeilunga I don't believe anything in the module has changed to directly effect this behaviour but we do iterate the minimum supported Terraform version. It might be that this impacts how relative paths are handled.

Please can you try prefixing your path with ${path.root} as per the following example from our test module and let us know if that helps?

https://github.com/Azure/terraform-azurerm-caf-enterprise-scale/blob/cc22c56ed6849ef900b02c6f538fdfa266368fc5/tests/modules/test_003_add_mgmt_conn/main.tf#L29

mikeilunga commented 2 years ago

${path.root}

@krowlandson - I've just tested with the above prefix and this has not worked I'm afraid.

krowlandson commented 2 years ago

@mikeilunga are you able to share your code from management_groups.tf and enterprisescale-mg.tfvars please?

Given the above suggestion didn't work, I've re-read your issue and am unclear on what exactly isn't working.

What do you have in your lib folder, and what behaviour are you expecting? Also exactly how has this changed since upgrading version?

mikeilunga commented 2 years ago

Hey @mikeilunga,

Have you seen and followed: https://github.com/Azure/terraform-azurerm-caf-enterprise-scale/wiki/%5BExamples%5D-Deploy-Custom-Landing-Zone-Archetypes

The archetypes are not pulled into the repo, you must define custom lib artefacts and reference them, if you wish, in the module variables.

e.g. creating a policy assignment https://github.com/Azure/terraform-azurerm-caf-enterprise-scale/wiki/%5BExamples%5D-Assign-a-Built-in-Policy

Let us know

Hey @mikeilunga,

Have you seen and followed: https://github.com/Azure/terraform-azurerm-caf-enterprise-scale/wiki/%5BExamples%5D-Deploy-Custom-Landing-Zone-Archetypes

The archetypes are not pulled into the repo, you must define custom lib artefacts and reference them, if you wish, in the module variables.

e.g. creating a policy assignment https://github.com/Azure/terraform-azurerm-caf-enterprise-scale/wiki/%5BExamples%5D-Assign-a-Built-in-Policy

Let us know

@jtracey93 - thanks for this. This did point me in the right direction with the path route variable suggested by @krowlandson.

All good now :-)

mikeilunga commented 2 years ago

@mikeilunga are you able to share your code from management_groups.tf and enterprisescale-mg.tfvars please?

Given the above suggestion didn't work, I've re-read your issue and am unclear on what exactly isn't working.

What do you have in your lib folder, and what behaviour are you expecting? Also exactly how has this changed since upgrading version?

I was following the custom landing zone approach, but the custom library variable. But this has now worked after copying the entire archetypes directory and using the suggested variable.

krowlandson commented 2 years ago

I was following the custom landing zone approach, but the custom library variable. But this has now worked after copying the entire archetypes directory and using the suggested variable.

Thank you for the updates @mikeilunga.

It would still be great to better understand your implementation here as the custom library is complementary to the one within the module so you shouldn't have to copy one into the other.

krowlandson commented 2 years ago

Trigger ADO Sync