|
| 1 | +# Use terraform in the devops-toolkit |
| 2 | + |
| 3 | +To use the existing container isntead of creating one, use `docker exec` command instead of `docker run` |
| 4 | + |
| 5 | +```bash |
| 6 | +docker exec -it my_devops_toolkit /bin/bash |
| 7 | +``` |
| 8 | + |
| 9 | +## Use case 1: Run terraform sample code provided in the container |
| 10 | + |
| 11 | +```bash |
| 12 | +docker run --rm --network host -it devops-toolkit:latest |
| 13 | +# You now in the container terminal |
| 14 | +# Navigate to Terraform sample |
| 15 | +pushd samples/terraform/basic |
| 16 | +# Init the terraform |
| 17 | +terraform init |
| 18 | +# Apply change, select 'yes' to confirm |
| 19 | +terraform apply |
| 20 | +# Once done, destroy the infra, select 'yes' to confirm |
| 21 | +terraform destroy |
| 22 | +popd |
| 23 | +``` |
| 24 | + |
| 25 | +## Use case 2: Clone external code inside container |
| 26 | + |
| 27 | +```bash |
| 28 | +docker run --rm --network host -it devops-toolkit:latest |
| 29 | +# You now in the container terminal |
| 30 | + |
| 31 | +# Now run your cloned script |
| 32 | +# Clone code |
| 33 | +mkdir terraform_workspace; cd terraform_workspace |
| 34 | +git clone <YOUR-REPO> terraform-examples |
| 35 | + |
| 36 | +cd terraform-examples |
| 37 | +# Run terraform here: init-plan-apply,... |
| 38 | +``` |
| 39 | + |
| 40 | +## Use case 3: Mount external code to container |
| 41 | + |
| 42 | +Clone the code to the host then mount to container |
| 43 | + |
| 44 | +```bash |
| 45 | +# Given that we have code somewhere in you machine |
| 46 | +docker run --rm -v "$(pwd)":/root/terraform_workspace --network host -it devops-toolkit:latest |
| 47 | +# Run the terraform code as usual |
| 48 | +``` |
| 49 | + |
| 50 | +## Troubleshooting |
| 51 | + |
| 52 | +- For any issues, check [this reference](../troubleshooting/TROUBLESHOOTING.md) |
0 commit comments