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

Hacky attempt at AWS Provider patching to help users work around Terraform bug #1326

Merged
merged 17 commits into from
Sep 2, 2020

Conversation

brikis98
Copy link
Member

@brikis98 brikis98 commented Sep 1, 2020

This PR adds an aws-provider-patch command that can be used to override attributes in nested provider blocks. This is an attempt at a hacky workaround for a Terraform bug where import does not work if you are using any modules that have provider blocks nested in within them. With this PR, users could run:

terragrunt aws-provider-patch --terragrunt-override-attr region=eu-west-1

And Terragrunt will:

  1. Run terraform init to download the code for all your modules into .terraform/modules.
  2. Scan all the Terraform code in .terraform/modules, find AWS provider blocks, and hard-code the region param
    to eu-west-1 for each one.

Once you do this, you'll hopefully be able to run import on that module. After that, you can delete the modified .terraform/modules and go back to normal.

Note that I wanted to document this command somewhere, so I updated the CLI docs to include all Terragrunt commands, and not just options. Therefore, as a side effect, this PR also fixes #1306.

@brikis98
Copy link
Member Author

brikis98 commented Sep 1, 2020

I got the patching code working, but there's a bit of an issue: Terraform downloads modules into .terraform/modules, but it downloads the entire repo into that folder, and not just a single module... So the patching code either:

  1. Updates every file in the entire repo, which is wasteful, and potentially results in parsing files that perhaps shouldn't be parsed.
  2. We have to parse .terraform/modules/modules.json to know exactly in which folders to look... But I'm not sure if that's a stable API we can rely on.

cli/aws_provider_patch.go Outdated Show resolved Hide resolved
cli/aws_provider_patch.go Outdated Show resolved Hide resolved
cli/aws_provider_patch.go Outdated Show resolved Hide resolved
cli/aws_provider_patch.go Outdated Show resolved Hide resolved
Copy link
Contributor

@yorinasub17 yorinasub17 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implementation LGTM, although it's a bit scary to be relying on an internal representation/api.

cli/aws_provider_patch.go Outdated Show resolved Hide resolved
@brikis98 brikis98 changed the title [WIP] Quick attempt at AWS Provider patching Hacky attempt at AWS Provider patching to help users work around Terraform bug Sep 1, 2020
@brikis98
Copy link
Member Author

brikis98 commented Sep 1, 2020

Update: I decided to bite the bullet and parse the .terraform/modules/modules.json format after all. Not sure of a better approach.

Note that I wanted to document this command somewhere, so I updated the CLI docs to include all Terragrunt commands, and not just options. Therefore, as a side effect, this PR also fixes #1306. I've updated the description of this PR as well, and I believe it's now ready for review.

yorinasub17
yorinasub17 previously approved these changes Sep 1, 2020
Copy link
Contributor

@yorinasub17 yorinasub17 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

test/integration_test.go Outdated Show resolved Hide resolved
Pick up lots of bug fixes
@brikis98
Copy link
Member Author

brikis98 commented Sep 1, 2020

Can I haz one more review plz? 😄

Copy link
Contributor

@yorinasub17 yorinasub17 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updates LGTM

@brikis98
Copy link
Member Author

brikis98 commented Sep 2, 2020

Thanks for the review! Merging now.

@brikis98 brikis98 merged commit af15b43 into master Sep 2, 2020
@brikis98 brikis98 deleted the provider-overwritte branch September 2, 2020 07:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add reference docs for terragrunt specific commands
2 participants