Task16: To enable secure inter-service communication, the DevOps team needs to configure access to an SNS topic using IAM roles and policies. The objective is to allow EC2 instances to publish messages to the topic using proper permissions and role assumptions. Please complete the following tasks: 1. Create an SNS topic named nautilus-sns-topic . 2. Create an IAM role named nautilus-sns-role with EC2 as the trusted entity. 3. Attach an inline IAM policy named nautilus-sns-policy that grants permission to publish messages to the SNS topic. 4. Use the main.tf file (do not create a separate .tf file) to provision the sns-topic, role and policy. 5. Create the locals.tf with the following names: * KKE_SNS_TOPIC_NAME :name of the sns topic created. * KKE_ROLE_NAME : name of the role created. * KKE_POLICY_NAME : name of the policy created. 6. Create the outputs.tf file to the output the following: * The name of the SNS topic using the output variable kke_sns_topic_name . * The name of the role using the output variable kke_role_name . * The name of the policy using the output variable kke_policy_name .
My solution: main.tf
resource “aws_sns_topic” “nautilus-sns-topic” {
name = local.KKE_SNS_TOPIC_NAME
}
resource “aws_iam_role” “nautilus-sns-role” {
name = local.KKE_ROLE_NAME
assume_role_policy = jsonencode({
Version = “2012-10-17”
Statement = [
{
Action = “sts:AssumeRole”
Effect = “Allow”
Sid = “”
Principal = {
Service = “ec2.amazonaws.com”
}
},
]
})
}
resource “aws_iam_role_policy” “nautilus-sns-policy” {
name = local.KKE_POLICY_NAME
role = aws_iam_role.nautilus-sns-role.id
policy = jsonencode({
Version = “2012-10-17”
Statement = [
{
Action = [
“sns:Publish”,
]
Effect = “Allow”
Resource = aws_sns_topic.nautilus-sns-topic.arn
},
]
})
}
resource “aws_iam_instance_profile” “nautilus_instance_profile” {
name = “${local.KKE_ROLE_NAME}-instance-profile”
role = aws_iam_role.nautilus-sns-role.name
}
Task16 verification failed with below message:
**Managed IAM Policy 'nautilus-sns-policy' is not attached to role.**
But Task 16 question clearly asked us to create inline IAM policy for SNS publish permission.
Please check and clarify whether verification expects **aws_iam_role_policy_attachment** or **aws_iam_policy_attachment** resource as well or something else.