Creating a DynamoDB Table on AWS Using Terraform
π Hello, and welcome to my DevOps journey! π I am Priyanka Varshney,π οΈ As an aspiring DevOps engineer, I'm all about bridging the gap between development and operations, making software delivery seamless and efficient. π»π§ On this Hashnode blog, I'll be sharing my learnings, experiences and adventures as I dive deep into the world of continuous integration, automation, and cloud technologies. βοΈβοΈ Let's connect, learn, and grow as a vibrant DevOps community. Follow my Hashnode blog, and let's embrace the DevOps adventure together! π€π

In the previous blog, we learned how to create a local resource or file using Terraform concepts.
Now, let's take it a step further and create a DynamoDB table on AWS using Terraform.
Prerequisites
Launch an EC2 instance and install Terraform (refer to the previous blog if needed).
Ensure your EC2 instance has internet access to download dependencies.
Step 1: Create the DynamoDB Configuration File
Open the Vim editor to create a Terraform file:
vim DynamoDB.tfPaste the following Terraform configuration to create a DynamoDB table:
resource "aws_dynamodb_table" "terraform_lock" { name = "terraform_state" billing_mode = "PAY_PER_REQUEST" hash_key = "LockID" attribute { name = "LockID" type = "S" } }Define the Terraform Provider
Create a new file to specify the AWS provider configuration:
vim terraform.tfAdd the following content:
terraform { required_providers { aws = { source = "hashicorp/aws" version = "5.92.0" } } }
Step 3: Initialize Terraform
Run the following command to initialize your Terraform project:
terraform initThis will download the necessary provider plugins.
Step 4: Install and Configure AWS CLI
Install the AWS CLI to connect Terraform with your AWS account:
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" sudo apt-get install unzip unzip awscliv2.zip sudo ./aws/installNow configure the CLI with your credentials:
aws configureYou'll be prompted for:
Access Key ID
Secret Access Key
Default region (e.g.,
us-east-1)Output format (you can leave this as
json)
Note : Need to install the Unzip in order to unzip the file sudo apt-get install unzip
Step 5: Create IAM User and Access Keys
Go to the IAM service and click on users from the Dashboard.

Create a user named Terra-admin and give the permission AmazonS3FullAccess by clicking on attach policies directly.

- Click on next and then create user.
Now Terra-admin user is created successfully.

- To obtain the access key, navigate to the user profile, select "Security Credentials," create a security key, and then choose the "Command Line Interface (CLI)" option. After that, confirm your action and proceed by clicking "Next."

5. Now you will get two access key ID

Now you can copy paste the keys in your local machine

Step 6: Apply Terraform Configuration
Now you're ready to create the DynamoDB table:
terraform applyType
yeswhen prompted to confirm.
Step 7: Verify the Table Using AWS CLI
To list all DynamoDB tables:
aws dynamodb list-tables
You should see your terraform_state table listed.
You can also visit the DynamoDB console on AWS to visually confirm the table was created successfully.
β Congratulations! You've now provisioned a DynamoDB table on AWS using Terraform.
Happy learning :)