Creating a DynamoDB table on the AWS cloud with Terraform for use with other serverless applications. In this DynamoDB table contains partition key, sort key and a Time to Live (TTL) attribute. The Capacity mode is set as On-demand.
This repository uses the GitHub CI/CD pipeline to deploy DynamoDB on AWS.
The main.yml file handles the CD process. It contains several steps as follows.
aws-actions/configure-aws-credentials@v1This provides AWS credentials for virtual environments hosted on GitHub (Runners).actions/checkout@v2Checkout the code from Git repositoryhashicorp/setup-terraform@v2sets up Terraform CLI in workflowTerraform Initinitializes working directoryTerraform Validatevalidate the configuration internallyTerraform Plancreates the execution planTerraform Applyexecutes the actions
By default, Terraform stores state locally in terraform.tfstate file. When working with Terraform in a team, use of a local file makes Terraform usage complicated because each user must make sure they always have the latest state data before running Terraform and make sure that nobody else runs Terraform at the same time.
With remote state, Terraform writes the state data to a remote data store (In this case S3), which can then be shared between all members of a team. With support of DynamoDB, Terraform will lock state for all operations. This prevents others from acquiring the lock and potentially corrupting state.