2
votes

I'm creating a CloudFormation template for an EC2 instance that I'll be using to manage Active Directory servers I already have deployed in my VPC. I'm having an issue while defining the AWS::EC2::Instance resource. It may be a YAML syntax issue, but I'm having trouble seeing the problem.

When the stack is being created it rolls back with error "Value of property SsmAssociations must be of type List". The documentation is somewhat sparse in terms of examples. Amazon EC2 Instance SsmAssociations

Here's the snippet of YAML that's in question:

Resources: 
  EC2Instance:
    Type: AWS::EC2::Instance
    Properties:
      IamInstanceProfile: !Ref InstanceProfile
      SsmAssociations:
        DocumentName: !Ref InstanceProfile
        AssociationParameters:
          -
            Key: "directoryId"
            Value: 
              - 
                Fn::ImportValue:
                  Fn::Join:
                  - ''
                  - - !Ref ADStackName
                    - '-'
                    - 'DirectoryId'
          - 
            Key: "directoryName"
            Value: 
              - 
                Fn::ImportValue:
                  Fn::Join:
                  - ''
                  - - !Ref ADStackName
                    - '-'
                    - 'DirectoryName'
          - 
            Key: "dnsIpAddresses"
            Value:
              - 
                Fn::ImportValue:
                  Fn::Join:
                  - ''
                  - - !Ref ADStackName
                    - '-'
                    - 'ADServer1PrivateIP'
              - 
                Fn::ImportValue:
                  Fn::Join:
                  - ''
                  - - !Ref ADStackName
                    - '-'
                    - 'ADServer2PrivateIP'
      KeyName: !Ref EC2KeyPair 

Thanks for your help.

1

1 Answers

4
votes

According to the documentation of the AWS::EC2::Instance, it is stated that the SsmAssociations has

Type: List of Amazon EC2 Instance SsmAssociations.

(which is also what your error message states). However, in your YAML declaration you have provided a single SsmAssociations. Try change this to the following:

Resources: 
  EC2Instance:
    Type: AWS::EC2::Instance
    Properties:
      IamInstanceProfile: !Ref InstanceProfile
      SsmAssociations:
        # Notice the addition of the "-" on the line below to declare a yaml list
        - 
          DocumentName: !Ref InstanceProfile
          AssociationParameters:
          # add the rest of the declaration