This terraformation infrastructure is simulating a multi-tenant environment for a company called HumanGov, and requisites are:
- Not share any resource
- Each province is supposed to have its own AWS infrastructure
- The terraformation state file and its lock are supposed to handled in the cloud, to avoid overwriting.
Please, make sure that terminal prompt folder is the project's root folder, then run the command below.
aws s3api create-bucket --bucket humangov-terraform-state-ykbt --region us-east-1
It is to avoid more than one terraform apply
running at the same moment.
aws dynamodb create-table \
--table-name tcb-devops-state-lock-table \
--attribute-definitions AttributeName=LockID,AttributeType=S \
--key-schema AttributeName=LockID,KeyType=HASH \
--provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5 \
--region us-east-1
The commands below create .terraform
folder in the project's terraform folder, downloading all providers' binary files, besides to set up an aws bucket as a common place to store terraform.state file, and defining a DynamoDB table as the locker to ensure the team shares the same terraform state. During this process, a warning question will ask whether you're aware that when initiating the terraform.tfstate file will be placed into the defined S3 bucket (defined in step 1), so just type "yes".
cd terraform && terraform init
- This set will make the screen output more verbose.
export TF_LOG = true
- This set will dump all screen messages into a log file, which the name can be whatever you want.`
export TF_LOG_PATH = terraform.log
Just checking if the code is written correctly.
terraform validate
Just checking if the whole infrastructure is going to be created.
terraform plan -out=terraform_plan
or
terraform plan
Applies the infrastructure as planned.
terraform apply
or
terraform apply -auto-approve
or
terraform apply terraform_plan