【问题标题】:Porting a cloudformation template to terraform将 cloudformation 模板移植到 terraform
【发布时间】:2021-03-01 05:54:11
【问题描述】:

我正在遵循 Hashicorp 网站上关于在 Terraform 中包装 CF 模板的指示。整个代码相当多,但 CF 模板有效,所以问题在于“包装”...

Terraform plan 给了我这个错误输出:

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

因此,“AWSTemplateFormatVersion”行似乎是它不喜欢的。因此,我猜它正在上升的'A'。

这是我关注的 Hashicorp 页面,我想知道是否有任何合适的转义字符,或者是否有人可以看到我的 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....

感谢您提供的任何指导。

【问题讨论】:

    标签: json amazon-web-services terraform amazon-cloudformation


    【解决方案1】:

    至少有两个问题是显而易见的:

    1. source = "../../aws_modules/aws-db-event-subscription" 无效。在aws_cloudformation_stack 中有没有属性称为source。你可以删除它。

    2. 您的template_body 不应{ 开头:

      template_body = <<STACK
        {
    

    这是因为您在模板中使用 YAML,而不是 JSON。

    【讨论】:

    • 太棒了。谢谢你。我使用 CF 中的 Develop 实用程序将我的 yaml 转换为 JSON,这样更容易做到。
    • @Scouse_Bob 没问题。很高兴这个答案很有帮助。
    猜你喜欢
    • 2018-04-14
    • 1970-01-01
    • 1970-01-01
    • 2018-07-10
    • 1970-01-01
    • 2017-11-24
    • 2021-12-09
    • 2011-02-25
    • 2021-01-10
    相关资源
    最近更新 更多