jmccann / drone-terraform

Drone plugin for triggering Terraform deployments
http://plugins.drone.io/jmccann/terraform/
Apache License 2.0
86 stars 93 forks source link

Tf 0.9.4 #41

Closed msuterski closed 7 years ago

msuterski commented 7 years ago

This adds support for the new init command in terraform. It accepts and sets most of the options for the command.

With introduction of the init, the remote config command was removed from terraform 0.9.x

jmccann commented 7 years ago

Thanks for the PR. I haven't played with 0.9 at all yet. Had some questions.

  1. If I have a remote tfstate generated from 0.8 will using this still work with the "old" tfstate?
  2. Have you tested this in a pipeline?

From looking at the changes themselves it LGTM so far.

msuterski commented 7 years ago

re 1. Yes. How the remote stats work did not change. What changed is how TF defines the location of those state files.

re 2:

This is how I use the plugin:

pipeline:
  deploy:
    image: msuterski/drone-terraform:0.6-0.9.4
    plan: true
    init_options:
      backend_config: "path=terraform.tfstate"
    when:
      event: push

Output from drone 0.6

$ rm -rf .terraform
time="2017-05-11T15:11:50Z" level=info msg="Drone Terraform Plugin Version" Revision= 
$ terraform init -backend-config=path=terraform.tfstate -input=false
Initializing the backend...
Successfully configured the backend "gcs"! Terraform will automatically
use this backend unless the backend configuration changes.
Terraform has been successfully initialized!
You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.

If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your environment. If you forget, other
commands will detect it and remind you to do so if necessary.

$ terraform get
$ terraform validate
$ terraform plan -out=plan.tfout

Error loading state: [WARN] Error retrieving object<redacted>/terraform.tfstate: googleapi: got HTTP response code 403 with body: Caller does not have storage.objects.get access to object <redacted>/terraform.tfstate.
time="2017-05-11T15:11:52Z" level=fatal msg="Failed to execute a command" error="exit status 1" 
...

Trying to figure the GCP key thing now...

msuterski commented 7 years ago

Got the secrets thing working. That's what is happening when one can not read...

$ rm -rf .terraform
$ terraform init -backend-config=path=<redacted>/terraform.tfstate -input=false
time="2017-05-11T15:43:56Z" level=info msg="Drone Terraform Plugin Version" Revision= 
Initializing the backend...
Successfully configured the backend "gcs"! Terraform will automatically
use this backend unless the backend configuration changes.
Terraform has been successfully initialized!
You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.

If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your environment. If you forget, other
commands will detect it and remind you to do so if necessary.
$ terraform get
$ terraform validate
$ terraform plan -out=plan.tfout
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.

fastly_service_v1.marcin: Refreshing state... (ID: <redacted>)
No changes. Infrastructure is up-to-date.

This means that Terraform did not detect any differences between your
configuration and real physical resources that exist. As a result, Terraform
doesn't need to do anything.
$ rm -rf .terraform
jmccann commented 7 years ago

@msuterski Are you done making changes? You feel this is ready to merge? So far I'm 👍

msuterski commented 7 years ago

Yes. I'm done with the changes. I've added the plugin to our pipelines and works fine.

Thanks a lot.

jmccann commented 7 years ago

Thank you!