The DevOps team has been tasked with creating a secure DynamoDB table and enforcing fine-grained access control using IAM. This setup will allow secure and restricted access to the table from trusted AWS services only.
As a member of the Nautilus DevOps Team, your task is to perform the following using Terraform:
Create a DynamoDB Table: Create a table named devops-table with minimal configuration.
Create an IAM Role: Create an IAM role named devops-role that will be allowed to access the table.
Create an IAM Policy: Create a policy named devops-readonly-policy that should grant read-only access (GetItem, Scan, Query) to the specific DynamoDB table and attach it to the role.
Create the main.tf file (do not create a separate .tf file) to provision the table, role, and policy.
Create the variables.tf file with the following variables:
KKE_TABLE_NAME: name of the DynamoDB tableKKE_ROLE_NAME: name of the IAM roleKKE_POLICY_NAME: name of the IAM policyCreate the outputs.tf file with the following outputs:
kke_dynamodb_table: name of the DynamoDB tablekke_iam_role_name: name of the IAM rolekke_iam_policy_name: name of the IAM policyDefine the actual values for these variables in the terraform.tfvars file.
Ensure that the IAM policy allows only read access and restricts it to the specific DynamoDB table created.
Notes:
The Terraform working directory is /home/bob/terraform.
Right-click under the EXPLORER section in VS Code and select Open in Integrated Terminal to launch the terminal.
Before submitting the task, ensure that terraform plan returns No changes. Your infrastructure matches the configuration.
Let’s create the terraform.tfvars with these values:
KKE_TABLE_NAME = "devops-table"
KKE_ROLE_NAME = "devops-role"
KKE_POLICY_NAME = "devops-readonly-policy"
Let’s create the variables.tf for these variable:
variable "KKE_TABLE_NAME" {}
variable "KKE_ROLE_NAME" {}
variable "KKE_POLICY_NAME" {}
Now, let’s create the main.tf file and copy-paste contents form this terraform file
Now, let’s create the outputs.tf file with these contents:
output "kke_dynamodb_table" {
value = aws_dynamodb_table.kk_dynamodb.name
}
output "kke_iam_role_name" {
value = aws_iam_role.kk_role.name
}
output "kke_iam_policy_name" {
value = aws_iam_policy.kk_policy.name
}
Let’s run the terraform action commands:
terraform init
terraform plan
terraform apply -auto-approve
"*" for production security"${table_arn}/*" to access indexes, streams, and other table sub-resourcesGetItem, BatchGetItem, Query, Scan, DescribeTable for true read-only accessdynamodb:List* and dynamodb:Describe* can expose account-wide informationaws_iam_role_policy_attachment instead of aws_iam_policy_attachmenttable_arn/* for complete accessterraform.tfvars filesvariable "name" {} syntax in variables.tfaws_dynamodb_table.name.namename, hash_key, billing_mode, and attribute are requiredPAY_PER_REQUEST for variable workloadsS (String), N (Number), B (Binary)