Validate Terraform code

1dirs -c
2for DIR in $(find ./examples -type d); do
3   pushd $DIR
4   terraform init
5   terraform fmt -check
6   terraform validate
7   popd
8 done

Execute Terraform

 1export DO_PAT="dop_v1_xxxxxxxxxxxxxxxx"
 2doctl auth init --context rkub
 3
 4# inside a dir with a tf file 
 5terraform init
 6terraform validate
 7terraform plan -var "do_token=${DO_PAT}"
 8terraform apply -var "do_token=${DO_PAT}" -auto-approve
 9
10# clean apply
11terraform plan -out=infra.tfplan -var "do_token=${DO_PAT}"
12terraform apply infra.tfplan
13
14# Control
15terraform show terraform.tfstate
16
17# Destroy
18terraform plan -destroy -out=terraform.tfplan -var "do_token=${DO_PAT}"
19terraform apply terraform.tfplan
  • Connect to Droplet with private ssh key
1ssh root@$(terraform output -json ip_address_workers | jq -r '.[0]') -i .key