transcend-io / terragrunt-atlantis-config

Generate Atlantis config for Terragrunt projects.
https://transcend.io/blog/why-we-use-terragrunt
MIT License
617 stars 98 forks source link

Question: Finding file dependencies used in resource #114

Open ryan-dyer-sp opened 3 years ago

ryan-dyer-sp commented 3 years ago

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.

kitos9112 commented 3 years ago

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.

ryan-dyer-sp commented 3 years ago

@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.

kitos9112 commented 3 years ago

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