简体   繁体   中英

How can I use multiple lines inside `!If` condition in cloudformation?

I am using !If condition in cloudformation template. Below code has a condition ShouldAddWebHook to add or remove Triggers in AWS::CodeBuild::Project project. When I run deploy command I got this error. Why it complains about !If condition?

while scanning a simple key
  in "<unicode string>", line 93, column 7:
          !If
          ^ (line: 93)
could not find expected ':'
  in "<unicode string>", line 94, column 9:
            - ShouldAddWebHook
            ^ (line: 94)

Below is cloudformation template:


Conditions:
    ShouldAddWebHook: !Equals [ !Ref ShouldAddWebHook, "true" ]

Resources:
  CodeBuildProjectDeployment:
    Type: AWS::CodeBuild::Project
    Properties:
      Name: test
      Artifacts:
        Type: NO_ARTIFACTS
      Environment:
        Type: LINUX_CONTAINER
        ComputeType: BUILD_GENERAL1_SMALL
        Image: aws/codebuild/amazonlinux2-x86_64-standard:2.0
      Source:
        Type: BITBUCKET
        Location: !Ref BitbucketCloneUrl
        GitCloneDepth: 26
        BuildSpec: buildspec.yml
      TimeoutInMinutes: 10
      BadgeEnabled: true
      !If
        - ShouldAddWebHook
        - Triggers:
            Webhook: true
            FilterGroups:
              - - Pattern: PUSH
                  Type: EVENT
        - !Ref "AWS::NoValue"

Your !If can't be "hanging" like this. It should be associated with some property. You can try the following:

Resources:
  CodeBuildProjectDeployment:
    Type: AWS::CodeBuild::Project
    Properties:
      Name: test
      Artifacts:
        Type: NO_ARTIFACTS
      Environment:
        Type: LINUX_CONTAINER
        ComputeType: BUILD_GENERAL1_SMALL
        Image: aws/codebuild/amazonlinux2-x86_64-standard:2.0
      Source:
        Type: BITBUCKET
        Location: !Ref BitbucketCloneUrl
        GitCloneDepth: 26
        BuildSpec: buildspec.yml
      TimeoutInMinutes: 10
      BadgeEnabled: true
      Triggers:
        !If
          - ShouldAddWebHook
          - Webhook: true
            FilterGroups:
              - - Pattern: PUSH
                  Type: EVENT
          - !Ref "AWS::NoValue"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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