terraform-google-modules / terraform-google-container-vm

Deploys containers on Compute Engine instances
https://registry.terraform.io/modules/terraform-google-modules/container-vm/google
Apache License 2.0
155 stars 79 forks source link

Add support for Terraform v0.12 #25

Closed ziporah closed 5 years ago

ziporah commented 5 years ago

I believe the current version of the module is incompatible with terraform v0.12-rc1

after succesfully applying a configuration with terraform v0.11 run

terraform-v0.12-rc1 0.12upgrade

This command will rewrite the configuration files in the given directory so
that they use the new syntax features from Terraform v0.12, and will identify
any constructs that may need to be adjusted for correct operation with
Terraform v0.12.

We recommend using this command in a clean version control work tree, so that
you can easily see the proposed changes as a diff against the latest commit.
If you have uncommited changes already present, we recommend aborting this
command and dealing with them before running this command again.

Would you like to upgrade the module in the current directory?
  Only 'yes' will be accepted to confirm.

  Enter a value: yes

-----------------------------------------------------------------------------

Upgrade complete!

The configuration files were upgraded successfully. Use your version control
system to review the proposed changes, make any necessary adjustments, and
then commit.

And then init terraform again:

10:11 $ terraform-v0.12-rc1 init
Initializing modules...
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x28 pc=0x84f291]

goroutine 1 [running]:
github.com/hashicorp/terraform/vendor/github.com/hashicorp/go-version.(*Version).String(0x0, 0x0, 0x0)
    /home/jo/go/src/github.com/hashicorp/terraform/vendor/github.com/hashicorp/go-version/version.go:349 +0x51
github.com/hashicorp/terraform/vendor/github.com/hashicorp/go-version.(*Version).Compare(0x0, 0xc42031bc70, 0x1f)
    /home/jo/go/src/github.com/hashicorp/terraform/vendor/github.com/hashicorp/go-version/version.go:118 +0x40
github.com/hashicorp/terraform/vendor/github.com/hashicorp/go-version.(*Version).Equal(0x0, 0xc42031bc70, 0xc420502c10)
    /home/jo/go/src/github.com/hashicorp/terraform/vendor/github.com/hashicorp/go-version/version.go:283 +0x35
github.com/hashicorp/terraform/vendor/github.com/hashicorp/go-version.constraintEqual(0x0, 0xc42031bc70, 0xc42061ee28)
    /home/jo/go/src/github.com/hashicorp/terraform/vendor/github.com/hashicorp/go-version/constraint.go:142 +0x35
github.com/hashicorp/terraform/vendor/github.com/hashicorp/go-version.(*Constraint).Check(0xc42058eac0, 0x0, 0xc420039208)
    /home/jo/go/src/github.com/hashicorp/terraform/vendor/github.com/hashicorp/go-version/constraint.go:92 +0x3c
github.com/hashicorp/terraform/vendor/github.com/hashicorp/go-version.Constraints.Check(0xc42032a590, 0x1, 0x1, 0x0, 0xc420039288)
    /home/jo/go/src/github.com/hashicorp/terraform/vendor/github.com/hashicorp/go-version/constraint.go:72 +0x55
github.com/hashicorp/terraform/configs/configload.(*Loader).moduleWalkerLoad(0xc4205c6280, 0xc4200ca900, 0x0, 0x7ff13f1b0000, 0x0, 0x1, 0xc42061f010)
    /home/jo/go/src/github.com/hashicorp/terraform/configs/configload/loader_load.go:67 +0x289
github.com/hashicorp/terraform/configs/configload.(*Loader).(github.com/hashicorp/terraform/configs/configload.moduleWalkerLoad)-fm(0xc4200ca900, 0x4106f8, 0x120, 0x198f9a0, 0xc4202be901, 0xc4200ca900)
    /home/jo/go/src/github.com/hashicorp/terraform/configs/configload/loader_load.go:27 +0x34
github.com/hashicorp/terraform/configs.ModuleWalkerFunc.LoadModule(0xc420162630, 0xc4200ca900, 0x1, 0x1, 0x0, 0x0, 0x0)
    /home/jo/go/src/github.com/hashicorp/terraform/configs/config_build.go:110 +0x30
github.com/hashicorp/terraform/configs.buildChildModules(0xc4202bed00, 0x1cbad00, 0xc420162630, 0x4106f8, 0x10, 0x185a360, 0x1)
    /home/jo/go/src/github.com/hashicorp/terraform/configs/config_build.go:58 +0x52a
github.com/hashicorp/terraform/configs.BuildConfig(0xc420185f10, 0x1cbad00, 0xc420162630, 0xc420185f10, 0x0, 0x0, 0x0)
    /home/jo/go/src/github.com/hashicorp/terraform/configs/config_build.go:24 +0x76
github.com/hashicorp/terraform/configs/configload.(*Loader).LoadConfig(0xc4205c6280, 0x1a93d6d, 0x1, 0x0, 0x1, 0x2819e20, 0x0)
    /home/jo/go/src/github.com/hashicorp/terraform/configs/configload/loader_load.go:27 +0xea
github.com/hashicorp/terraform/command.(*Meta).loadConfig(0xc420369860, 0x1a93d6d, 0x1, 0xc42061f700, 0x1, 0x1, 0x0)
    /home/jo/go/src/github.com/hashicorp/terraform/command/meta_config.go:66 +0x155
github.com/hashicorp/terraform/command.(*InitCommand).Run(0xc420369860, 0xc42000a070, 0x0, 0x0, 0xc42008b660)
    /home/jo/go/src/github.com/hashicorp/terraform/command/init.go:246 +0xb7f
github.com/hashicorp/terraform/vendor/github.com/mitchellh/cli.(*CLI).Run(0xc4200fa640, 0xc4200fa640, 0xc420575d10, 0x1)
    /home/jo/go/src/github.com/hashicorp/terraform/vendor/github.com/mitchellh/cli/cli.go:255 +0x1eb
main.wrappedMain(0x0)
    /home/jo/go/src/github.com/hashicorp/terraform/main.go:223 +0xc5b
main.realMain(0x0)
    /home/jo/go/src/github.com/hashicorp/terraform/main.go:100 +0xbb
main.main()
    /home/jo/go/src/github.com/hashicorp/terraform/main.go:36 +0x2e

!!!!!!!!!!!!!!!!!!!!!!!!!!! TERRAFORM CRASH !!!!!!!!!!!!!!!!!!!!!!!!!!!!

Terraform crashed! This is always indicative of a bug within Terraform.
A crash log has been placed at "crash.log" relative to your current
working directory. It would be immensely helpful if you could please
report the crash with Terraform[1] so that we can fix this.

When reporting bugs, please include your terraform version. That
information is available on the first line of crash.log. You can also
get it by running 'terraform --version' on the command line.

[1]: https://github.com/hashicorp/terraform/issues

!!!!!!!!!!!!!!!!!!!!!!!!!!! TERRAFORM CRASH !!!!!!!!!!!!!!!!!!!!!!!!!!!!
ziporah commented 5 years ago

The tests will fail, because the current test image is using terraform v0.11 I could not find a v0.12 image (yet) The latest image available was : this one

ziporah commented 5 years ago

Issue also exists with terraform v0.12.0. I did some local tests to build a new gcr.io/cloud-foundation-cicd/cft/kitchen-terraform image which uses the latest terraform and google 2.7.0 providers

-BUILD_TERRAFORM_VERSION := 0.11.13
+BUILD_TERRAFORM_VERSION := 0.12.0
 BUILD_CLOUD_SDK_VERSION := 239.0.0
-BUILD_PROVIDER_GOOGLE_VERSION := 1.19.1
+BUILD_PROVIDER_GOOGLE_VERSION := 2.7.0

=> forcing the kitchen.yaml to ignore the terraform version

@@ -16,6 +16,7 @@
 driver:
   name: "terraform"
   command_timeout: 1800
+  verify_version: false

Allows me to generate a valid configuration and test for the single instance. I believe more changes are required to make the other tests work. (test output)[https://gist.github.com/ziporah/b927628247ded05e76d07b383a7a0db0]

aaron-lane commented 5 years ago

Hi @ziporah!

If I understand correctly, the initial crash which you shared was resolved by using a supported version of the Google provider, but there is still a need to change this module in order to support Terraform v0.12. Is that correct? Additionally, is #26 the fix for this issue?

ziporah commented 5 years ago

I believe you will need all the commits in my master branch for the tests to work, we will need a new terraform-kitchen image and Makefile adjustments to use that image before the tests will work. I'm using my master branch to deploy on our environment now, and that works. Furthermore this syntax:

  source = "github.com/terraform-google-modules/terraform-google-container-vm"
  version = "0.1.0"

isn't allowed anymore. When you want to use a specific version, you will need to use the official repository of terraform with this syntax, which is not yet in my master branch:

  source = "google-terraform-modules/terraform-google-container-vm/google"
  version = "0.1.0"
orkenstein commented 5 years ago

Also getting this:

Error: Invalid argument name

  on .terraform/modules/gce-container/terraform-google-modules-terraform-google-container-vm-c968dee/main.tf line 38, in resource "null_resource" "validate_restart_policy":
  38:   "ERROR: Invalid `restart_policy` ${var.restart_policy} was provided. Must be one of `OnFailure`, `UnlessStopped`, `Always`, or `No`" = true

Argument names must not be quoted.
ziporah commented 5 years ago

yes, you also need to transform the code to fix this. this is the relevant commit to fix it: commit after which you'll stumble in the next error, basicaly everything in my master branch has to be added, but since the test framework is not yet upgraded, I can't validate the code yet

orkenstein commented 5 years ago

@ziporah thanks, waiting for release then

aaron-lane commented 5 years ago

@ziporah a draft of cft/kitchen-terraform:2.0.0 is available which includes Terraform v0.12 and Kitchen-Terraform v4.9.0. Please test your work with that image.