Skip to content

Latest commit

 

History

History
81 lines (56 loc) · 2.12 KB

terraform_usage.md

File metadata and controls

81 lines (56 loc) · 2.12 KB

Use terraform in the devops-toolkit

Terraform document

Some document to help you start with terraform

Start the container

Navigate to your workspace folder, then run:

devops-toolkit-cli init demo_terraform01
devops-toolkit-cli run demo_terraform01

# You now in the container terminal. Execute the terraform command normally
terraform --version

It will mount the workspace code to container and you then can execute desired scripts inside the devops-toolkit container

Run with Docker command

Note

To use the existing container instead of creating one, use docker exec command instead of docker run

docker exec -it my_devops_toolkit /bin/bash

Common Run Modes

For instructions on common run modes, visit DevOps Toolkit Common Run Mode.

Use case 1: Run terraform sample code provided in the container

docker run --rm --network host -it -v ~/.dtc:/dtc tungbq/devops-toolkit:latest
# You now in the container terminal
#  Navigate to Terraform sample
pushd samples/terraform/basic
# Init the terraform
terraform init
# Apply change, select 'yes' to confirm
terraform apply
# Once done, destroy the infra, select 'yes' to confirm
terraform destroy
popd

Use case 2: Clone external code inside container

docker run --rm --network host -it -v ~/.dtc:/dtc tungbq/devops-toolkit:latest
# You now in the container terminal

# Now run your cloned script
# Clone code
mkdir terraform_workspace; cd terraform_workspace
git clone <YOUR-REPO> terraform-examples

cd terraform-examples
# Run terraform here: init-plan-apply,...

Use case 3: Mount external code to container

Clone the code to the host then mount to container

# Given that we have code somewhere in you machine
docker run --rm -v "$(pwd)":/root/terraform_workspace -v ~/.dtc:/dtc --network host -it tungbq/devops-toolkit:latest
# Run the terraform code as usual

Troubleshooting