-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
Enabling JSON output for Terraform instead of writing the HCL syntax … #8145
Enabling JSON output for Terraform instead of writing the HCL syntax … #8145
Conversation
Hi @mccare. Thanks for your PR. I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
/ok-to-test |
This is great! I was working on adding native HCL2 support but it will require touching every task's terraform struct to add hcl tags which is much more invasive than i was hoping, so having json support is a good middle ground. Are you able to test the output with both 0.11 and 0.12? If it only works with 0.12 we may want to make the feature flag's name specifically call that out. I believe we still run into the issue with the default route and VPC additional CIDR block names that start with digits, is that correct? We'll still need to conditionally rename those somehow. we'll want to mention this in Can you add an integration test for this? The test would go in |
On first sight it seems that terraform 0.11 supports .tf.json files. Release notes for 0.12.0 list in the improvement section that
But I couldn't find what features this were exactly. (and if they are used by kops) So I would restrict JSON output to terraform 0.12 (also creating the required_version). In addition, I could fail generating json output if kubernetes.tf is present in the target directory (since terraform seems combines the two and then complains) Naming issues are not resolved by using JSON as format (so a name beginning with a number is still invalid). I'll have a look at the integration tests. |
d035046
to
9ab0359
Compare
Added one integration test. You have to unset the feature flag after the test otherwise the test suite would fail. I needed to add (yet) another parameter to the runTestAWS to check for the kubernetes.tf.json file (instead of kubernetes.tf). Are there other options? (one struct for parameters?) I'm new to go. |
f0ecd69
to
a2630ff
Compare
Ok, I renamed the route resource and tested terraform plan with both 0.11 and 0.12 and they both succeeded. This feature flag wont be fully functional until we get the route and vpc additional cidr resources renamed though. I'll try to test the applys sometime soon but if someone is willing to do that, that would be great. |
a2630ff
to
08aa6c6
Compare
08aa6c6
to
8d25737
Compare
/test pull-kops-verify-staticcheck |
8d25737
to
98d5d17
Compare
Added an error if the kubernetes.tf file is still present (no JSON file will be generated then). The error message contains a note to read the release notes. For moving state (for the rename)
Moving the state with terraform 0.12 did not work since the name was invalid. |
98d5d17
to
625dd2f
Compare
2692e8f
to
4e622a0
Compare
4e622a0
to
2b03384
Compare
@mccare can you rebase to pull in the resource renaming that merged as well as fix the integration_test conflict? |
…tf file. JSON syntax is officially supported in 0.12 and a terraform version requirement will be set. For previous installations you need to delete the .tf file by hand. JSON generation will fail if kubernetes.tf is present. Added Integration Test using minimal test setup Added documentation. For terraform 0.12 support the resource names need to be changed still
2b03384
to
549f54d
Compare
@rifelpet fixed the tests and rebased the commit. |
I tested this on a I also tested this on an existing cluster and kops binary: generate terraform 0.11 output, plan and apply it with 0.11. Then use this branch to generate 0.12 output, plan and apply that with 0.12 and confirm no changes. Everything looks great! This is a big next step 🎉 I'm thinking of adding a test that downloads terraform and actually runs a /approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: mccare, rifelpet The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
…of-#8145-upstream-release-1.17 Automated cherry pick of #8145: Enabling JSON output for Terraform instead of writing the HCL
Enabling output of JSON instead of HCL v1, writing kubernetes.tf.json instead of kubernetes.tf. JSON can be consumed by terraform 0.12. ( https://www.terraform.io/docs/configuration/syntax-json.html )
Tried it on AWS and GCE test cluster.
If you enable this feature, you need to delete the previously generated kubernetes.tf file. Also, this feature will require minimum version of terraform 0.12.