简体   繁体   中英

Porting a cloudformation template to terraform

I am following a direction on Hashicorp's site regarding wrapping a CF Template in Terraform. There's a fair amount to the whole code, but the CF Template works, so the issue is with the "wrapping"...

Terraform plan gives me this error output:

terraform plan

Error: aws_cloudformation_stack.Momma: "template_body" contains an invalid JSON: invalid character 'A' looking for beginning of object key string

Error: aws_cloudformation_stack.Momma: : invalid or unknown key: source

So it seems that the "AWSTemplateFormatVersion" line is what it does not like. Hence the'A' it is picking up, I guess.

This is the Hashicorp page I am following, I'm wondering if there are any escape characters that are appropriate or, if anyone can see any immediate formatting issues with my JSON?

https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudformation_stack

terraform {}

provider "aws" {
  version = "= 2.61"
  region  = "ap-southeast-2"
}

resource "aws_cloudformation_stack" "Momma" {
  source = "../../aws_modules/aws-db-event-subscription"
  name   = "Momma-Stack"

  template_body = <<STACK
    {
AWSTemplateFormatVersion: 2010-09-09
Description: Team Server
Metadata:
  'AWS::CloudFormation::Interface':
    ParameterGroups:
      - Label:
          default: Deployment Options
        Parameters:
          - Environment
          - KeyPairName
          - VPCID
          - Subnet1ID
          - RemoteAccessCIDR
          - Owner
    ParameterLabels:
      KeyPairName:
        Default: Key Pair Name
      RemoteAccessCIDR:
        Default: External Access CIDR
      VPCID:
        Default: VPC ID
      Owner:
        Default: MommaTeam....

Thank you for any guidance offered.

There are at least two issues that are apparent:

  1. source = "../../aws_modules/aws-db-event-subscription" is invalid. There is no attribute called source in aws_cloudformation_stack . You can remove it.

  2. Your template_body should not begin with { in:

  template_body = <<STACK
    {

This is because you are using YAML for your template, not JSON.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM