This repository is intended to register an idea to bootstrap a study or QA terraform project using LocalStack to simulate AWS.
The backend is configured to store tfstate in local S3 bucket and to store tfstate lock in local DynamoDB, both running in a LocalStack docker container.
Follow the next steps to create initial configuration and test if everything is setup correctly.
To use this local setup you will need the following software available in your machine:
- docker
- docker-compose
- terraform cli
- awscli
Change to localstack directory and run:
docker-compose up -d
Create a configuration for AWS with dummy creadentials.
The only important information to localstack is the region.
Credentials validation is actually disabled.
aws configure
Change to main directory and run terraform:
terraform init
and terraform apply
aws --endpoint=http://localhost:4566 s3 ls
2021-01-25 22:05:18 terraform-state
aws --endpoint=http://localhost:4566 aws dynamodb list-tables
{
"TableNames": [
"terraformlock"
]
}
Change to dev directory and run terraform:
terraform init
and terraform apply
aws --endpoint=http://localhost:4566 sqs list-queues
{
"QueueUrls": [
"https://localhost:4566/000000000000/sample-queue"
]
}
aws --endpoint=http://localhost:4566 s3 ls terraform-state/dev/
2021-01-25 22:17:34 1242 terraform.tfstate
aws --endpoint=http://localhost:4566 dynamodb scan --table-name terraformlock --output json
{
"Items": [
{
"Digest": {
"S": "6295c01f8c53c7a74bfad08f566d20c4"
},
"LockID": {
"S": "terraform-state/dev/terraform.tfstate-md5"
}
}
],
"Count": 1,
"ScannedCount": 1,
"ConsumedCapacity": null
}
In order to not get annoyed on having to always provide --endpoint=http://localhost:4566
in your study machine, you can do the following:
- Create an alias that will always point to the local enpoint as:
alias awslocal='aws --endpoint-url http://localhost:4566'
. - Put the alias in your
.bashrc
or.zshrc
to have it permanent in your terminal session. - If you create the alias named as "aws" you can also make use of awscli autocomplete with your localstack endpoint.