Browse Source

Merge pull request #43 from jmccann/multi_backend_config

Multiple backend-config options
pull/44/head
Jacob McCann 8 years ago
committed by GitHub
parent
commit
48763d4874
  1. 55
      DOCS.md
  2. 6
      plugin.go

55
DOCS.md

@ -54,19 +54,20 @@ pipeline:
+ sensitive: true + sensitive: true
``` ```
Example configuration with state tracked via remote: Example configuration with state tracked via remote. You will need a
[backend configuration](https://www.terraform.io/docs/backends/config.html)
specified in a `.tf` file. You can then pass additional options via the `.drone.yml`.
```diff ```diff
pipeline: pipeline:
terraform: terraform:
image: jmccann/drone-terraform:1 image: jmccann/drone-terraform:1
plan: false plan: false
+ remote: + init_options:
+ backend: S3 + backend-config:
+ config: + - "bucket=my-terraform-config-bucket"
+ bucket: my-terraform-config-bucket + - "key=tf-states/my-project"
+ key: tf-states/my-project + - "region=us-east-1"
+ region: us-east-1
``` ```
You may want to run terraform against internal resources, like an internal You may want to run terraform against internal resources, like an internal
@ -145,12 +146,11 @@ pipeline:
dev_terraform: dev_terraform:
image: jmccann/drone-terraform:1 image: jmccann/drone-terraform:1
plan: false plan: false
remote: init_options:
backend: S3 backend_config:
config: - "bucket=my-terraform-config-bucket"
bucket: my-terraform-config-bucket - "key=tf-states/my-project"
key: tf-states/my-project - "region=us-east-1"
region: us-east-1
+ secrets: + secrets:
+ AWS_ACCESS_KEY_ID: DEV_AWS_ACCESS_KEY_ID + AWS_ACCESS_KEY_ID: DEV_AWS_ACCESS_KEY_ID
+ AWS_SECRET_ACCESS_KEY: DEV_AWS_SECRET_ACCESS_KEY + AWS_SECRET_ACCESS_KEY: DEV_AWS_SECRET_ACCESS_KEY
@ -158,12 +158,11 @@ pipeline:
prod_terraform: prod_terraform:
image: jmccann/drone-terraform:1 image: jmccann/drone-terraform:1
plan: false plan: false
remote: init_options:
backend: S3 backend_config:
config: - "bucket=my-terraform-config-bucket"
bucket: my-terraform-config-bucket - "key=tf-states/my-project"
key: tf-states/my-project - "region=us-east-1"
region: us-east-1
+ secrets: + secrets:
+ AWS_ACCESS_KEY_ID: PROD_AWS_ACCESS_KEY_ID + AWS_ACCESS_KEY_ID: PROD_AWS_ACCESS_KEY_ID
+ AWS_SECRET_ACCESS_KEY: PROD_AWS_SECRET_ACCESS_KEY + AWS_SECRET_ACCESS_KEY: PROD_AWS_SECRET_ACCESS_KEY
@ -174,15 +173,19 @@ pipeline:
plan plan
: if true, calculates a plan but does __NOT__ apply it. : if true, calculates a plan but does __NOT__ apply it.
remote init_options
: contains the configuration for the Terraform remote state tracking. : contains the configuration for the Terraform backend.
remote.backend init_options.backend-config
: the Terraform remote state backend to use. : This specifies additional configuration to merge for the backend. This can be
specified multiple times. Flags specified later in the line override those
specified earlier if they conflict.
remote.config init_options.lock
: a map of configuration parameters for the remote state backend. : Lock the state file when locking is supported.
Each value is passed as a `-backend-config=<key>=<value>` option.
init_options.lock-timeout
: Duration to retry a state lock.
vars vars
: a map of variables to pass to the Terraform `plan` and `apply` commands. : a map of variables to pass to the Terraform `plan` and `apply` commands.

6
plugin.go

@ -31,7 +31,7 @@ type (
} }
InitOptions struct { InitOptions struct {
BackendConfig string `json:"backend-config"` BackendConfig []string `json:"backend-config"`
Lock *bool `json:"lock"` Lock *bool `json:"lock"`
LockTimeout string `json:"lock-timeout"` LockTimeout string `json:"lock-timeout"`
} }
@ -122,8 +122,8 @@ func initCommand(config InitOptions) *exec.Cmd {
"init", "init",
} }
if config.BackendConfig != "" { for _, v := range config.BackendConfig {
args = append(args, fmt.Sprintf("-backend-config=%s", config.BackendConfig)) args = append(args, fmt.Sprintf("-backend-config=%s", v))
} }
// True is default in TF // True is default in TF

Loading…
Cancel
Save