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

Add Terraform 0.12 support #8825

Merged
merged 4 commits into from
Apr 7, 2020
Merged

Conversation

rifelpet
Copy link
Member

@rifelpet rifelpet commented Mar 31, 2020

This adds support for HCL2 via a FeatureFlag (default: enabled)

The feature flag name is Terraform-0.12 but I'm find with using something else if people prefer.

  • kops update cluster --target terraform will now create .tf files in Terraform 0.12 syntax.
  • KOPS_FEATURE_FLAG=-Terraform-0.12 kops update cluster --target terraform will need to be used to preserve the old behavior.

The git changes in tests/integration/update_cluster demonstrate how the .tf file will change.

I've updated the ./hack/verify-terraform.sh script to now validate .tf files with Terraform 0.12 by default and the syntax passes validation. The Google provider does report an error regarding a missing machine_type but that is independent of this PR (before this PR the GCE Terraform output wouldn't even work with Terraform 0.11 because of a version requirement conflict. Kops required Google Terraform provider >= 3.0 but 3.0 requires Terraform 0.12)

HCL2 uses the go-cty dynamic type library which is why the additional field tags are added to every Terraform struct in the tasks packages.

The HCL library doesn't support writing some of the syntax easily, so much of upup/pkg/fi/cloudup/terraform/hcl2.go implements byte-level functionality for what Kops needs. See hashicorp/hcl#347 and hashicorp/hcl#356 for examples and discussion around those limitations.

closes #7052

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Mar 31, 2020
@k8s-ci-robot k8s-ci-robot added area/provider/aws Issues or PRs related to aws provider area/provider/digitalocean Issues or PRs related to digitalocean provider approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Mar 31, 2020
@rifelpet rifelpet force-pushed the hcl2-native branch 2 times, most recently from 9225b26 to a46027a Compare April 2, 2020 16:00
@schollii
Copy link

schollii commented Apr 2, 2020

Until an official version of kops contains the above PR merged, are we stuck with using TF 0.11? E.g. can we use latest official kops 1.17 with terraform 0.12: kops will generate HCL rather than HCL2 but I think terraform 0.12 should be able to handle HCL generated by kops, has anyone tried? I'm asking here rather than hashicorp github because the answer depends not just on the official TF 0.12 support for HCL, but also on HCL that kops generates, is it fully compliant etc. One of my colleagues was having issues with the kubernetes.tf file generated.

}

resource "google_compute_instance_template" "master-us-test1-a-ha-gce-example-com" {
can_ip_forward = true
Copy link
Member Author

Choose a reason for hiding this comment

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

it looks like google_compute_instance_template isn't getting rendered properly. My guess is because it uses type embedding, i'll investigate further.

type terraformInstanceTemplate struct {
terraformInstanceCommon
NamePrefix string `json:"name_prefix"`
}

/hold

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Apr 6, 2020
@justinsb
Copy link
Member

justinsb commented Apr 7, 2020

I think we can merge this, and we can look at the terraform breakage in a follow on, if it's confined to that one special case. Worst case we just expand out the struct (or write our own tf12 renderer, now that the format is a little more reasonable?)

I verified that we didn't break tf11 output by stopping at the intermediate stage and verifying that the tests still passed.

/approve
/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 7, 2020
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: justinsb, 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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@rifelpet
Copy link
Member Author

rifelpet commented Apr 7, 2020

ok, I'm fine with that. If we dont fix GCE before the next release we can always instruct GCE users to revert back to the old behavior via feature flag. I'll try to look into it soon though

/hold cancel

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Apr 7, 2020
@k8s-ci-robot k8s-ci-robot merged commit ef10d54 into kubernetes:master Apr 7, 2020
@k8s-ci-robot k8s-ci-robot added this to the v1.18 milestone Apr 7, 2020
@rifelpet rifelpet deleted the hcl2-native branch August 6, 2020 02:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/provider/aws Issues or PRs related to aws provider area/provider/digitalocean Issues or PRs related to digitalocean provider cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

terraform 0.12 support
4 participants