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

Allow to parse the configuration_aliases syntax in Terraform v0.15 #43

Merged
merged 1 commit into from
May 27, 2021

Conversation

minamijoyo
Copy link
Owner

@minamijoyo minamijoyo commented May 26, 2021

Fixes #40

The tfupdate mainly uses the hclwrite parser to preserve comments, but the hclwrite doesn't have enough AST for an object type, as a compromise, the tfupdate also uses the hclsyntax parser to detect old version.

Terraform v0.15 introduced a new configuration_aliases syntax.
https://www.terraform.io/upgrade-guides/0-15.html#alternative-provider-configurations-within-modules

It's not directly related version updating but it contains provider references and it causes a parse error without an EvalContext.

The ideal solution would be extending the hclwrite to be able to parse such a complicated object, but it's not realistic to expect it to be possible in the short term. So I decided to add a new hack on top of the existing hack to achieve the short term goal.

After seeking a temporary solution, I found that the terraform-config-inspect parses the configuration_aliases by using a hcl.ExprMap which doesn't require to decode fully references.

I feel the implementation is messy and fragile. It's probably better not to re-implement by ourselves and depend on the terraform-config-inspect. However the terraform-config-inspect loads a root module not a file, and the current implementation of tfupdate detects and updates version in a single file. It's hard to use it for now. Using the terraform-config-inspect would require additional refactors for splitting the implementation to detecting and updating. To minimize the patch, I fixed only how to parse the required_providers block.

@minamijoyo minamijoyo force-pushed the support-configuration-aliases branch from ea94578 to 9157bc5 Compare May 27, 2021 01:50
@minamijoyo minamijoyo changed the title [WIP] Allow to parse the configuration_aliases syntax in Terraform v0.15 Allow to parse the configuration_aliases syntax in Terraform v0.15 May 27, 2021
@minamijoyo minamijoyo force-pushed the support-configuration-aliases branch from 9157bc5 to ccef41a Compare May 27, 2021 01:56
Fixes #40

The tfupdate mainly uses the hclwrite parser to preserve comments, but
the hclwrite doesn't have enough AST for an object type, as a
compromise, the tfupdate also uses the hclsyntax parser to detect old
version.

Terraform v0.15 introduced a new configuration_aliases syntax.
https://www.terraform.io/upgrade-guides/0-15.html#alternative-provider-configurations-within-modules

It's not directly related version updating but it contains provider
references and it causes a parse error without an EvalContext.

The ideal solution would be extending the hclwrite to be able to parse
such a complicated object, but it's not realistic to expect it to be
possible in the short term. So I decided to add a new hack on top of the
existing hack to achieve the short term goal.

After seeking a temporary solution, I found that the
terraform-config-inspect parses the configuration_aliases by using a
hcl.ExprMap which doesn't require to decode fully references.

I feel the implementation is messy and fragile. It's probably better not
to re-implement by ourselves and depend on the terraform-config-inspect.
However the terraform-config-inspect loads a root module not a file, and
the current implementation of tfupdate detects and updates version in a
single file. It's hard to use it for now. Using the
terraform-config-inspect would require additional refactors for
splitting the implementation to detecting and updating. To minimize the
patch, I fixed only how to parse the required_providers block.
@minamijoyo minamijoyo force-pushed the support-configuration-aliases branch from ccef41a to f5a46c4 Compare May 27, 2021 01:58
@minamijoyo minamijoyo merged commit 1c38e5a into master May 27, 2021
@minamijoyo minamijoyo deleted the support-configuration-aliases branch May 27, 2021 01:59
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.

Support configuration_aliases argument
1 participant