Support for CloudFormation Custom Resource in Terraform

amazon-cloudformationamazon-web-servicesterraform

I've scoured the Terraform docs for the AWS provider and couldn't find support for CloudFormation::CustomResource in terraform.

I've created my Lambda Functions and now I would like to pass my arguments to my lambda function. The way this is done in CloudFormation is via a custom resource.

I however can't seem to find support for this in Terraform. Am I missing something?
Thanks.

Best Answer

The aws_cloudformation_stack resource allows the creation of CloudFormation stacks in Terraform, thus exposing all of CloudFormation's features within a Terraform configuration:

resource "aws_cloudformation_stack" "example" {
  name = "example-custom-resource"

  template_body = <<STACK
{
  "Resources" : {
    "ExampleCustomResource": {
      "Type" : "Custom::ExampleResource",
      "Properties" : {
        "ServiceToken": "...",
        (other properties specific to the resource)
      }
    }
  }
}
STACK
}

The Type attribute here can be any string starting with Custom::. The ServiceToken identifies which custom resource provider will handle this custom resource. Any other properties that the custom resource supports can be provided as additional attributes in the Properties object.

Since the format of template_body is just a standard CloudFormation template, the documentation for CustomResource gives the full details on how this feature works.

Terraform does not directly support CloudFormation custom resources as a native Terraform resource, but the aws_cloudformation_stack resource is provided as a way to get the best of both worlds, giving access to CloudFormation-specific features when needed.

Related Topic