CI/CD for Docker infrastructure using Terraform
Build, change, and destroy Docker infrastructure using Terraform.
Use template →1steps:
2 - label: ":terraform: terraform init"
3 key: "init"
4 plugins:
5 - docker#v5.9.0:
6 image: hashicorp/terraform:1.5
7 command: ["init", "-input=false"]
8 - artifacts#v1.9.2:
9 upload: [".terraform", ".terraform.lock.hcl"]
10 compressed: terraform.tgz
11
12 - label: ":terraform: terraform plan"
13 depends_on: "init"
14 key: "plan"
15 plugins:
16 - artifacts#v1.9.2:
17 download: [".terraform", ".terraform.lock.hcl"]
18 compressed: terraform.tgz
19 - docker#v5.9.0:
20 image: hashicorp/terraform:1.5
21 command: ["plan", "-out=tfplan", "-input=false"]
22 volumes:
23 - /var/run/docker.sock:/var/run/docker.sock
24 artifact_paths:
25 - "tfplan"
26
27 - block: "Apply?"
28
29 - label: ":terraform: terraform apply"
30 plugins:
31 - artifacts#v1.9.2:
32 download: ["tfplan"]
33 - artifacts#v1.9.2:
34 download: [".terraform", ".terraform.lock.hcl"]
35 compressed: terraform.tgz
36 - docker#v5.9.0:
37 image: hashicorp/terraform:1.5
38 command: ["apply", "-input=false", "-auto-approve", "tfplan"]
39 volumes:
40 - /var/run/docker.sock:/var/run/docker.sock
CI/CD for Docker using Terraform
Build, change, and destroy Docker infrastructure using Terraform.
Use template →CI/CD for Docker infrastructure using Terraform
This template gives you a continuous integration (CI) pipeline for building, changing, and destroying Docker infrastructure using Terraform.
At a glance:
How it works
This template:
- Validates the Terraform configuration in a Docker image.
- Initializes Terraform and plans changes, outputting a plan file, which is available as an artifact.
- Blocks for input before conditionally applying the proposed Terraform plan.
The pipeline runs all steps in a Docker container with the HashiCorp Terraform image.
Next steps
After you select Use template, you’ll:
- Connect the Git repository with your Terraform configuration.
- Configure the compute—run locally, on-premises, or in the cloud.
- Run the pipeline.
You can then play around with the pipeline settings. For example, run the pipeline locally while you iterate on the definition or set a schedule to trigger a nightly build.
If you need help, please check our documentation, raise an issue , or reach out to support.