简体   繁体   English

将 cloudformation 模板移植到 terraform

[英]Porting a cloudformation template to terraform

I am following a direction on Hashicorp's site regarding wrapping a CF Template in Terraform.我正在关注 Hashicorp 网站上关于在 Terraform 中包装 CF 模板的指示。 There's a fair amount to the whole code, but the CF Template works, so the issue is with the "wrapping"...整个代码相当多,但 CF 模板有效,所以问题在于“包装”......

Terraform plan gives me this error output: 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

So it seems that the "AWSTemplateFormatVersion" line is what it does not like.所以看起来“AWSTemplateFormatVersion”行是它不喜欢的。 Hence the'A' it is picking up, I guess.因此,我猜它正在拾取“A”。

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?这是我正在关注的 Hashicorp 页面,我想知道是否有任何合适的转义字符,或者是否有人可以看到我的 JSON 有任何直接的格式问题?

https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudformation_stack 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. source = "../../aws_modules/aws-db-event-subscription"无效。 There is no attribute called source in aws_cloudformation_stack . aws_cloudformation_stack 中没有名为source属性 You can remove it.你可以删除它。

  2. Your template_body should not begin with { in:您的template_body不应以{开头

  template_body = <<STACK
    {

This is because you are using YAML for your template, not JSON.这是因为您的模板使用的是 YAML,而不是 JSON。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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