terragrunt-atlantis-config icon indicating copy to clipboard operation
terragrunt-atlantis-config copied to clipboard

Question: Finding file dependencies used in resource

Open ryan-dyer-sp opened this issue 4 years ago • 3 comments

Hey David, question for you. We have a module/resource with the following definition.

resource "vault_policy" "policies" {
  for_each = toset(var.policies)

  name   = each.key
  policy = templatefile("files/${each.key}.hcl.tmpl", { environment = var.environment })
}

How do I get these template files to show up as a dependency on the project?

I tried adding

locals {
  extra_atlantis_dependencies = formatlist("files/%s.hcl.tmpl", var.policies)
}

to the terragrunt file, but it doesnt seem to like that.

ryan-dyer-sp avatar Feb 04 '21 15:02 ryan-dyer-sp

Hi @ryan-dyer-sp - You would kind of add something like this to your child terragrunt.

locals {
(...)
  # CICD for Atlantis
  extra_atlantis_dependencies = [
    "files/*.hcl.tmp
  ]
}

This tool (terragrunt-atlantis-config) only needs to know what files need to be added to the workspace of your atlantis.yaml config file.

kitos9112 avatar Feb 04 '21 15:02 kitos9112

@kitos9112 Thanks but I dont want a wildcard for changes to any policy to impact a project that doesnt have that specific file as a dependency.

ryan-dyer-sp avatar Feb 04 '21 16:02 ryan-dyer-sp

In that case, you could create an aux. variable at local level beforehand and reuse it later within the extra_atlantis_dependencies Is there any way you can create a local which contains your policies instead of using var.policies?

locals {
(...)
 local.policies = <MyPolicies>
  my_files = formatlist("files/%s.hcl.tmpl", local.policies)
  # CICD for Atlantis
  extra_atlantis_dependencies = local.my_files

kitos9112 avatar Feb 04 '21 16:02 kitos9112