0
0
mirror of https://github.com/thegeeklab/wp-opentofu.git synced 2024-11-13 23:40:39 +00:00
wp-opentofu/DOCS.md

272 lines
7.6 KiB
Markdown
Raw Normal View History

2016-12-23 15:47:33 +00:00
---
date: 2016-01-01T00:00:00+00:00
title: Terraform
author: jmccann
tags: [ infrastructure, build tool ]
repo: jmccann/drone-terraform
logo: terraform.svg
image: jmccann/drone-terraform
---
2018-04-25 13:02:32 +00:00
The Terraform plugin applies the infrastructure configuration contained within the repository. The below pipeline configuration demonstrates simple usage which will run a `validate`, `plan` and `apply`:
2015-11-10 14:52:53 +00:00
```yaml
pipeline:
2015-11-10 14:52:53 +00:00
terraform:
2018-04-25 13:02:32 +00:00
image: jmccann/drone-terraform:5
```
2016-12-23 15:47:33 +00:00
Example configuration passing `vars` to terraform commands:
2016-12-23 15:47:33 +00:00
```diff
pipeline:
terraform:
2018-04-25 13:02:32 +00:00
image: jmccann/drone-terraform:5
2016-12-23 15:47:33 +00:00
+ vars:
+ app_name: my-project
+ app_version: 1.0.0
```
2018-04-25 13:02:32 +00:00
Example of explicitly specifying `actions` to perform a dry run.
```diff
pipeline:
terraform:
image: jmccann/drone-terraform:5
+ actions:
+ - validate
+ - plan
```
2017-09-06 15:24:24 +00:00
Example configuration passing secrets to terraform. Please read
https://www.terraform.io/docs/configuration/variables.html#environment-variables
for more details.
**Drone 0.6+**:
2016-12-23 15:47:33 +00:00
```diff
pipeline:
terraform:
2018-04-25 13:02:32 +00:00
image: jmccann/drone-terraform:5
2016-12-23 15:47:33 +00:00
+ secrets:
2017-09-06 15:24:24 +00:00
+ - source: terraform_secret
+ target: tf_var_my_secret
```
**Drone 0.5**:
```diff
pipeline:
terraform_1:
2018-04-25 13:02:32 +00:00
image: jmccann/drone-terraform:5
2017-09-06 15:24:24 +00:00
+ environment:
+ TF_VAR_MY_SECRET: ${TERRAFORM_SECRET}
terraform_2:
2018-04-25 13:02:32 +00:00
image: jmccann/drone-terraform:5
plan: false
+ sensitive: true
+ vars:
+ my_secret: ${TERRAFORM_SECRET}
2015-11-10 14:52:53 +00:00
```
2016-02-11 18:16:01 +00:00
You may be passing sensitive vars to your terraform commands. If you do not want
the terraform commands to display in your drone logs then set `sensitive` to `true`.
The output from the commands themselves will still display, it just won't show
2016-12-23 15:47:33 +00:00
what command is actually being ran.
2016-02-11 18:16:01 +00:00
2016-12-23 15:47:33 +00:00
```diff
pipeline:
2016-02-11 18:16:01 +00:00
terraform:
2018-04-25 13:02:32 +00:00
image: jmccann/drone-terraform:5
2016-12-23 15:47:33 +00:00
+ sensitive: true
2016-02-11 18:16:01 +00:00
```
Example configuration for overriding the terraform version. This will increase
plugin execution time as it will download/unpack the version of terraform
specified instead of using the embedded version that is included.
```diff
pipeline:
terraform:
2018-04-25 13:02:32 +00:00
image: jmccann/drone-terraform:5
+ tf_version: 0.10.3
```
2017-05-12 15:58:53 +00:00
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`.
2016-12-23 15:47:33 +00:00
```diff
pipeline:
terraform:
2018-04-25 13:02:32 +00:00
image: jmccann/drone-terraform:5
+ init_options:
+ backend-config:
+ - "bucket=my-terraform-config-bucket"
+ - "key=tf-states/my-project"
+ - "region=us-east-1"
```
2016-12-23 15:47:33 +00:00
You may want to run terraform against internal resources, like an internal
OpenStack deployment. Sometimes these resources are signed by an internal
CA Certificate. You can inject your CA Certificate into the plugin by using
`ca_certs` key as described above. Below is an example.
2016-12-23 15:47:33 +00:00
```diff
pipeline:
terraform:
2018-04-25 13:02:32 +00:00
image: jmccann/drone-terraform:5
2016-12-23 15:47:33 +00:00
+ ca_cert: |
+ -----BEGIN CERTIFICATE-----
+ asdfsadf
+ asdfsadf
+ -----END CERTIFICATE-------
```
2016-12-23 15:47:33 +00:00
You may want to assume another role before running the terraform commands.
This is useful for cross account access, where a central account has privileges
to assume roles in other accounts. Using the current credentials, this role will
be assumed and exported to environment variables.
See [the discussion](https://github.com/hashicorp/terraform/issues/1275) in the Terraform issues.
2016-12-23 15:47:33 +00:00
```diff
pipeline:
terraform:
2018-04-25 13:02:32 +00:00
image: jmccann/drone-terraform:5
2016-12-23 15:47:33 +00:00
+ role_arn_to_assume: arn:aws:iam::account-of-role-to-assume:role/name-of-role
```
2016-12-23 15:47:33 +00:00
You may want to change directories before applying the terraform commands.
This parameter is useful if you have multiple environments in different folders
and you want to use different drone configurations to apply different environments.
```diff
pipeline:
terraform:
2018-04-25 13:02:32 +00:00
image: jmccann/drone-terraform:5
2016-12-23 15:47:33 +00:00
+ root_dir: some/path/here
```
2016-12-23 15:47:33 +00:00
You may want to only target a specific list of resources within your terraform
code. To achieve this you can specify the `targets` parameter. If left undefined
all resources will be planned/applied against as the default behavior.
2016-12-23 15:47:33 +00:00
```diff
pipeline:
terraform:
2018-04-25 13:02:32 +00:00
image: jmccann/drone-terraform:5
2016-12-23 15:47:33 +00:00
+ targets:
+ - aws_security_group.generic_sg
+ - aws_security_group.app_sg
```
You may want to limit the number of concurrent operations as Terraform walks its graph.
If you want to change Terraform's default parallelism (currently equal to 10) then set the `parallelism` parameter.
2016-12-23 15:47:33 +00:00
```diff
pipeline:
terraform:
2018-04-25 13:02:32 +00:00
image: jmccann/drone-terraform:5
2016-12-23 15:47:33 +00:00
+ parallelism: 2
```
2018-04-25 13:02:32 +00:00
Destroying the service can be done by specifying `plan-destroy` and `destroy` actions. Keep in mind that Fastly won't allow a service with active version be destroyed. Use `force_destroy` option in the service definition for terraform to handle it.
2017-08-08 21:31:32 +00:00
2019-08-05 18:05:41 +00:00
```diff
2017-08-08 21:31:32 +00:00
pipeline:
destroy:
2018-04-25 13:02:32 +00:00
image: jmccann/drone-terraform:5
+ actions:
+ - plan-destroy
+ - destroy
2017-08-08 21:31:32 +00:00
```
2019-02-04 17:21:54 +00:00
Formatting the Terraform configuration files can be done by specifying the `fmt` action. Use `fmt_options` parameter to handle formatting options.
2019-08-05 18:05:41 +00:00
```diff
2019-02-04 17:21:54 +00:00
pipeline:
fmt:
image: jmccann/drone-terraform:5
+ actions:
+ - fmt
+ fmt_options:
+ write: false
+ diff: true
+ check: true
```
You may want to run some executions in parallel without having racing condition problems with the .terraform dir and
plan's output file.
```diff
pipeline:
backend-service:
image: jmccann/drone-terraform:<version>
+ tf_data_dir: .backend-service.terraform
frontend-service:
image: jmccann/drone-terraform:<version>
+ tf_data_dir: .frontend-service.terraform
```
2016-12-23 15:47:33 +00:00
# Parameter Reference
2018-04-25 13:02:32 +00:00
actions
: List of terraform actions to perform with the plugin. List includes:
2019-02-04 17:21:54 +00:00
`fmt`, `validate`, `plan`, `apply`, `plan-destroy`, `destroy`.
2016-12-23 15:47:33 +00:00
init_options
: contains the configuration for the Terraform backend.
init_options.backend-config
: 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.
2016-12-23 15:47:33 +00:00
init_options.lock
2017-10-04 18:12:49 +00:00
: Lock the state file when locking is supported. Default `true`.
2016-12-23 15:47:33 +00:00
init_options.lock-timeout
2017-10-04 18:12:49 +00:00
: Duration to wait for a state lock. Default `0s`.
2016-12-23 15:47:33 +00:00
2019-02-04 17:21:54 +00:00
fmt_options
: contains the configuration for the fmt action.
fmt_options.list
: List files whose formatting differs (disabled if using STDIN). Default `true`.
fmt_options.write
: Write result to source file instead of STDOUT (disabled if using STDIN or -check). Default `true`.
fmt_options.diff
: Display diffs of formatting changes. Default `false`.
fmt_options.check
: Check if the input is formatted. Exit status will be 0 if all input is properly formatted and non-zero otherwise. Default `false`.
2016-12-23 15:47:33 +00:00
vars
: a map of variables to pass to the Terraform `plan` and `apply` commands.
Each value is passed as a `-var <key>=<value>` option.
var_files
: a list of variable files to pass to the Terraform `plan` and `apply` commands.
Each value is passed as a `-var-file <value>` option.
2016-12-23 15:47:33 +00:00
ca_cert
: ca cert to add to your environment to allow terraform to use internal/private resources
sensitive
: (default: `false`) - Whether or not to suppress terraform commands to stdout.
role_arn_to_assume
: A role to assume before running the terraform commands.
root_dir
: The root directory where the terraform files live. When unset, the top level directory will be assumed.
parallelism
: The number of concurrent operations as Terraform walks its graph.
tf_data_dir
: changes the location where Terraform keeps its per-working-directory data, such as the current remote backend configuration.