aztfmod / rover

The rover is a docker container in charge of the deployment of the Terraform platform engineering for Azure
MIT License
172 stars 142 forks source link

Allow scope limiting to prevent forced re-creation #200

Closed samuelyee closed 2 years ago

samuelyee commented 2 years ago

Even if there is no change to the existing resource, rover will sometime force a re-creation of the resource. It can be disruptive especially for storage with existing objects.

Consider the following example where the creation of storage module is dependent on a variable app_rg_name for a specific named Azure resource group: configuration.tfvars

resource_groups = {
  app_re1 = {
    name   = "app-re1"
    region = "region1"
  }
}

solution.tf

locals {
  app_rg_name = lookup(var.resource_groups, "app_re1", null) == null ? null : var.resource_groups["app_re1"]["name"]
}

module "storage" {  
  count  = local.app_rg_name == null ? 0 : 1
  source = "./tf_modules/storage" 
  resource_group_name = local.app_rg_name
}

If I were just to add another new resource group without affecting the storage module e.g. configuration.tfvars

resource_groups = {
  app_re1 = {
    name   = "app-re1"
    region = "region1"
  }
 app_re2 = {
    name   = "app-re2"
    region = "region1"
  }
}

It will force a re-creation of the storage module when running plan or apply, even though there is no change to the module.

After spending much time without clues, I realised that I have to set the local variable "app_rg_name" to a fixed value rather than conditional to avoid a forced re-creation. Would be good if you can add a mechanism, such as -target to limit the scope of plan/apply, for avoiding a forced re-creation and debugging.

LaurentLesle commented 2 years ago

Thanks for reporting those re-creation issues. In the last 6 months we had improved the aztfmod module to handle those situations and bring a more stable behaviour when you add new resource groups. I propose you re-test with the latest aztfmod module https://registry.terraform.io/modules/aztfmod/caf/azurerm/latest

Closing it now.