簡體   English   中英

將 cloudformation 模板移植到 terraform

[英]Porting a cloudformation template to terraform

我正在關注 Hashicorp 網站上關於在 Terraform 中包裝 CF 模板的指示。 整個代碼相當多,但 CF 模板有效,所以問題在於“包裝”......

Terraform 計划給了我這個錯誤輸出:

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....

感謝您提供的任何指導。

至少有兩個問題是顯而易見的:

  1. source = "../../aws_modules/aws-db-event-subscription"無效。 aws_cloudformation_stack 中沒有名為source屬性 你可以刪除它。

  2. 您的template_body不應以{開頭

  template_body = <<STACK
    {

這是因為您的模板使用的是 YAML,而不是 JSON。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM