Using Terraform to create a systems manager document

0

Hi I need some help I am trying to create a systems manager document using terraform this is what I have but I get Yaml is not will formatted errors appreciate help:

resource "aws_ssm_association" "testa" { name = aws_ssm_document.test.name schedule_expression = "cron(0 0 0 ? * * *)" targets { key = "tag:run_ssm_document" values = ["yes"] } }

resource "aws_ssm_document" "test" { name = "test" document_format = "YAML" document_type = "Automation"

content =<<DOC { schemaVersion:"0.3", assumeRole: parameters: {},

mainSteps: [ { -name:runtestpose action: "aws:executeScript" inputs: Runtime: python3.6 Handler: script_handler Script:| def script_handler(events, context): import boto3 ec2 = boto3.client('ec2')
print("hello world") } } ] DOC
}

已提問 1 年前檢視次數 1475 次
1 個回答
0
已接受的答案

Hello.

Since "document_format" is set to YAML, I think an error will occur if "mainSteps" is not written in YAML.
https://docs.aws.amazon.com/systems-manager/latest/userguide/documents-schemas-features.html#automation-doc-syntax-examples
https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ssm_document

resource "aws_ssm_association" "testa" { name = aws_ssm_document.test.name schedule_expression = "cron(0 0 0 ? * * *)" targets { key = "tag:run_ssm_document" values = ["yes"] } }

resource "aws_ssm_document" "test" {
    name = "test"
    document_format = "YAML"
    document_type = "Automation"

    content =<<DOC
schemaVersion:"0.3"
assumeRole: parameters: {}
mainSteps:
     - name:runtestpose
       action: "aws:executeScript" 
       inputs: 
         Runtime: python3.6
         Handler: script_handler
         Script: | - 
           def script_handler(events, context): 
             import boto3 
             ec2 = boto3.client('ec2')
             print("hello world") 
DOC
}
profile picture
專家
已回答 1 年前
profile picture
專家
已審閱 1 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南