Home > Back-end >  Terraform - Receiving Error with CloudFormation Capabilities
Terraform - Receiving Error with CloudFormation Capabilities

Time:11-04

I am new to Terraform so I am sure that I am just missing something simple, but when attempting to deploy a CloudFormation stack, I am encountering an error when applying capabilities.

Here is my stack resource:

resource "aws_cloudformation_stack" "member_remediation" {
  name         = "smx-sharr-member-remediation"
  capabilities = [CAPABILITY_IAM, CAPABILITY_AUTO_EXPAND]

  parameters = {
    SecHubAdminAccount                    = var.parameter_SecHubAdmin
    CreateS3BucketForRedshiftAuditLogging = var.parameter_CreateS3
    LogGroupName                          = var.parameter_LogGroupName
    LoadAFSBPMemberStack                  = var.parameter_LoadAFSBPStack
    LoadCIS120MemberStack                 = var.parameter_LoadCISStack
    LoadPCI321MemberStack                 = var.parameter_LoadPCIStack
  }

  template_body = file("${path.module}/cf-templates/aws-sharr-member.yml")
}

This is what the stack provides when trying to deploy in the console:

Stack Capabilities

And here is the error Terraform is providing to me when performing a plan:

Exception Error in plan -
Error: Invalid reference

on .terraform/modules/aws-securityhub-master/module/main.tf line 1120, in resource "aws_cloudformation_stack" "member_remediation":
1120: capabilities = [CAPABILITY_IAM, CAPABILITY_AUTO_EXPAND]

A reference to a resource type must be followed by at least one attribute
access, specifying the resource name.

Error: Invalid reference

on .terraform/modules/aws-securityhub-master/module/main.tf line 1120, in resource "aws_cloudformation_stack" "member_remediation":
1120: capabilities = [CAPABILITY_IAM, CAPABILITY_AUTO_EXPAND]

A reference to a resource type must be followed by at least one attribute
access, specifying the resource name.

I'm not sure what attribute or resource reference the capability is requiring OR how to write it up in the resource layout. I am not finding many examples of CF stacks being deployed leveraging the capabilities option.

Any help is greatly appreciated!

NOTE: I have looked over the following question on Stack Overflow already - it didn't help me in this case:

AWS CloudFormation Stack update error: Requires capabilities : [CAPABILITY_IAM]

CodePudding user response:

The argument type for capabilities is set(string). It appears you are attempting to resolve undefined first class expressions. You probably meant to cast the elements as literal strings, which we can do with the normal syntax:

capabilities = ["CAPABILITY_IAM", "CAPABILITY_AUTO_EXPAND"]
  • Related