Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inherit extra_atlantis_dependencies from included parent terragrunt files #59

Closed
ryan-dyer-sp opened this issue Sep 24, 2020 · 11 comments
Closed
Assignees
Labels
enhancement New feature or request

Comments

@ryan-dyer-sp
Copy link

ryan-dyer-sp commented Sep 24, 2020

I just stumbled across this tool and think it would extremely useful for us, however it seems to not fully understand out repo structure and our use of the include block in leaf terragrunt.hcl files.

Setup:

  • mono repo with:
    -- /modules
    -- /providers/<env>/terragrunt.hcl
    -- /providers/<env>/project/region/resource/terragrunt.hcl
    -- /providers/common_vars/common_tags.yaml

All leaf terragrunt.hcls include their "parent" terragrunt.hcl.
The parent terragrunt.hcl has locals that are used for the purpose of tagging resources:

locals {
  common_tags      = yamldecode(fileexists("${find_in_parent_folders("../common_vars/common_tags.yaml", "nonexistant")}") ? file("${find_in_parent_folders("../common_vars/common_tags.yaml")}") : "{}")
  environment_tags = yamldecode(fileexists("${find_in_parent_folders("environment_tags.yaml", "nonexistant")}") ? file("${find_in_parent_folders("environment_tags.yaml")}") : "{}")
  regional_tags    = yamldecode(fileexists("${find_in_parent_folders("region_tags.yaml", "nonexistant")}") ? file("${find_in_parent_folders("region_tags.yaml")}") : "{}")
  application_tags = yamldecode(fileexists("${find_in_parent_folders("application_tags.yaml", "nonexistant")}") ? file("${find_in_parent_folders("application_tags.yaml")}") : "{}")
  instance_tags    = yamldecode(fileexists("${find_in_parent_folders("instance_tags.yaml", "nonexistant")}") ? file("${find_in_parent_folders("instance_tags.yaml")}") : "{}")
  local_tags       = yamldecode(fileexists("${path_relative_to_include()}/local_tags.yaml") ? file("${path_relative_to_include()}/local_tags.yaml") : "{}")
}

inputs = {
  tags        = merge(merge(merge(merge(merge(merge(local.common_tags, local.environment_tags), local.application_tags), local.regional_tags), local.instance_tags), local.local_tags), local.overwrite_tags)
}

Then all modules simply reference var.tags for any of their tag fields. This allows us to easily create and overwrite default tags at every level.

I tried adding the extra_atlantis_dependencies with the find(filesabove), but those files never showed up in any of the leaf autoplan dependencies. Instead the generator created a providers/env project which serves no purpose.

Any advise? Is there an option I'm missing for it to properly understand this?

Thanks!

@dmattia
Copy link
Member

dmattia commented Sep 24, 2020

Thanks for opening this!

Just so I can understand bet, where are you adding the extra_atlantis_dependencies local values? In your parent files, or in your leaf nodes?

As a note, terragrunt local values do not transfer between parents and child modules

@ryan-dyer-sp
Copy link
Author

defining the extra_... in the parent terragrunt. This is not something we want to have to add for 100s of leaf terragrunt.hcl files.

@dmattia dmattia added the enhancement New feature or request label Sep 24, 2020
@dmattia dmattia self-assigned this Sep 24, 2020
@dmattia
Copy link
Member

dmattia commented Sep 24, 2020

Sure, I can take this as a feature request to pass down the extra_atlantis_dependencies from a parent to all children, merging in values.

Then as far as you question about generating projects for the parent terragrunt.hcl files, you can use the --ignore-parent-terragrunt flag so that files without a terraform block with a source attribute do not have projects made for them in your atlantis.yaml output

@dmattia dmattia changed the title doesnt seem to understand the include block of terragrunt.hcl Inherit extra_atlantis_dependencies from included parent terragrunt files Sep 24, 2020
@ryan-dyer-sp
Copy link
Author

Great please let me know if you need assistance with testing.

Also I have noticed it doesn't seem to capture files referenced by extra arguments and varfiles. Unless .tf captures files from other directories, but I don't believe this is the case.

@dmattia
Copy link
Member

dmattia commented Sep 25, 2020

That is also a great point! I haven't used extra_argument files, so I missed that feature, but that should be quite easy to add.

I'll see if I can get to a few of these open issues today or this weekend 😄

@dmattia
Copy link
Member

dmattia commented Sep 25, 2020

Linking issue: #60

@dmattia
Copy link
Member

dmattia commented Sep 28, 2020

Release v0.9.1 is out now, which enables merging in extra_atlantis_dependencies from parents to children.

I started using this feature in my company's monorepo already, and it seems to work / be a useful improvement, so thank you for the suggestion! Please let me know if you have any issues using the new features.

As an example, here is what I have in one of my top level parent modules:

locals {
  extra_atlantis_dependencies = [
    abspath("common.tf"),
    abspath("terragrunt-config-prod.hcl")
  ]
}

@dmattia dmattia closed this as completed Sep 28, 2020
@dmattia
Copy link
Member

dmattia commented Sep 28, 2020

@ryan-dyer-sp

@awasilyev
Copy link

Was that really released?
Just checked v0.9.0...v0.9.1 - nothing related.

Asking because hitting same issue with the latest (v1.12.3) version.

@awasilyev
Copy link

@dmattia

@dmattia
Copy link
Member

dmattia commented Feb 8, 2022

Ya caught me in an embarrassing moment, release v0.9.1 was just because I forgot to bump the version properly in v0.9.0. So the actual changelog to check is from v0.8.0 to v0.9.1: v0.8.0...v0.9.1 which includes this PR: #61.

It's certainly possible that there's still a bug here @awasilyev, so feel free to open a new issue if you'd like. The currently tested feature is that if both a parent and a child have extra_atlantis_dependencies that the two lists will merge.

The test here: https://github.com/transcend-io/terragrunt-atlantis-config/blob/master/cmd/generate_test.go#L237-L242 is an assertion that this output file: https://github.com/transcend-io/terragrunt-atlantis-config/blob/master/cmd/golden/mergeParentDependencies.yaml is generated from this project directory: https://github.com/transcend-io/terragrunt-atlantis-config/tree/master/test_examples/parent_with_extra_deps

If you notice an edge case in your project that's different from that test, or believe that the test may be wonky and does not cover what you need, I would love to work on that in a new issue 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants