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

Pass variables to Terraform example #79

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,37 @@ to `true`, the following outputs is available for subsequent steps that call the

- `exitcode` - The exit code of the call to the `terraform` binary.

## Examples

### Passing variables to Terraform

Since Terraform cloud does not support run variables at this time.
Currently the only to way to pass variables is by creating a `*.auto.tfvars` variables file.

In this example, we will create a `pipeline.auto.tfvars` file and append all of the variables which we need to pass on to Terraform.

Add the following step in your workflow file

```yaml
- name: Setup Terraform variables
working-directory: ./terraform
id: vars
run: |-
cat > pipeline.auto.tfvars <<EOF
image_tag = "${{ github.sha }}"
EOF
```

And also define these variables in one of your Terraform configuration files. For example, we will add the following in `variables.tf`

```
variable "image_tag" {
}
```

`image_tag` will be available in terraform which you can access via `var.image_tag`


## License

[Mozilla Public License v2.0](https://github.com/hashicorp/setup-terraform/blob/master/LICENSE)
Expand Down