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
}

asked 9 months ago1102 views
1 Answer
0
Accepted Answer

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
EXPERT
answered 9 months ago
profile picture
EXPERT
reviewed 9 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions