Home > OS >  Get cloudformation evaluated condition value
Get cloudformation evaluated condition value

Time:01-24

Is it possible to know how cloudformation evaluated a condition?

I have this stack:

Parameters:
  BucketName:
    Default: ''
    Type: String
Conditions:
  CreateBucket: !Not 
    - !Equals 
      - !Ref BucketName
      - 'skip'
Resources:
  Bucket:
    Type: 'AWS::S3::Bucket'
    Condition: CreateBucket

I tried to create an Output:

Outputs:
  CreateBucket:
    Description: "CreateBucket"
    Value: !Ref CreateBucket
    Export:
      Name: "CreateBucket"

But validation fails with:

aws cloudformation validate-template --template-body file://"bucket.yml"

An error occurred (ValidationError) when calling the ValidateTemplate operation: Unresolved resource dependencies [CreateBucket] in the Outputs block of the template

CodePudding user response:

It seems that the inability to output conditions is a specification. Condition is not among the elements that can be included in Output Value.

Outputs - AWS CloudFormation

The value of an output can include literals, parameter references, pseudo-parameters, a mapping value, or intrinsic functions.

CodePudding user response:

You can use If function in the output:

Outputs:
  CreateBucket:
    Description: "CreateBucket"
    Value: !If [CreateBucket, "true", "false"]
    Export:
      Name: "CreateBucket"
  • Related