Variables
Variables can be specified in the spec.variables
section. There are two ways to how variables are used:
- Variable needed by your Terraform module
- Environment Variables (possibly needed for your Terraform provider)
Variables for Terraform Modules
These variables are needed by your module, they can be specified as follows:
apiVersion: run.terraform-operator.io/v1alpha1
kind: Terraform
...
spec:
...
variables:
- key: the_name_of_the_variable
value: value_of_the_variable
# valueFrom:
# secretKeyRef:
# name: aws-credentials
# key: AWS_ACCESS_KEY
# configMapKeyRef
# name: common-cfg
# key: some-key
You can specify the value directly in the value
field. Variables can also be pulled from a secretkeyRef or configMapKeyRef, this can be done by specifying the valueFrom
field
Variables as Environment Variables
Yon can specify variables to be set as environment variables, these variables will not be used in your terraform module, but maybe needed by the Terraform provider. Lets take the AWS Provider as an example.
The provider expects certain variables to be set to authenticate. You can specify environment variables by flagging the environmentVariable
as follows:
apiVersion: run.terraform-operator.io/v1alpha1
kind: Terraform
...
spec:
...
variables:
- key: the_name_of_the_variable
environmentVariable: true
value: value_of_the_variable
# valueFrom:
# secretKeyRef:
# name: aws-credentials
# key: AWS_ACCESS_KEY
# configMapKeyRef
# name: common-cfg
# key: some-key
Variables from a dependency
You can use a variable from another workflow/run, this will save you the trouble of using the terraform_remote_state data resource
This currently only works for workflows/runs that are in the same namespace
apiVersion: run.terraform-operator.io/v1alpha1
kind: Terraform
metadata:
name: terraform-run1
spec:
terraformVersion: 1.1.7
module:
source: IbraheemAlSaady/test/module
version: 0.0.3
variables:
- key: length
value: "4"
outputs:
- key: number
moduleOutputName: number
---
apiVersion: run.terraform-operator.io/v1alpha1
kind: Terraform
metadata:
name: terraform-run2
spec:
terraformVersion: 1.1.7
module:
source: IbraheemAlSaady/test/module
version: 0.0.3
## this must be specified in order for the variable dependencyRef to work
dependsOn:
- name: terraform-run1
variables:
- key: length
dependencyRef:
name: terraform-run1
## this is the key from the "terraform-run1" output field
key: number