0
votes

I have one CFT that creates an EBS volume. Then I have a second CFT that attaches the volume to the instance. I use a Custom Resource which runs a lambda to find the EbsVolumeId and the InstanceId

The 2 CFT's are part of a jenkins pipeline and its possible that the playbook that uses the CFT to create the EBS volume can be skipped and thus there is no EbsVolumeId to reference.

So in the CFT that attaches the EBS volume, I tried adding a Condition

Resources:
  MountPoint:
    Type: AWS::EC2::VolumeAttachment
    Condition: AttachEBS
    Properties:
      InstanceId: !GetAtt SCSHelper.InstanceId
      VolumeId: !GetAtt SCSHelper.EbsVolumeId

The custom resource looks like

SCSHelper:
  Type: Custom::SCSHelper

So I have to define the condition before the resources:

Conditions:
  AttachEBS: !Not [!Equals http:// !GetAtt SCSHelper.EbsVolumeId , None ]

The problem is the Conditions is failing with:

An error occurred (ValidationError) when calling the CreateStack operation: Template format error: Unresolved dependencies https://forums.aws.amazon.com/. Cannot reference resources in the Conditions block of the template An error occurred (ValidationError) when calling the CreateStack operation: Template format error: Unresolved dependencies https://forums.aws.amazon.com/.

So it appears that the SCSHelper.EbsVolumeId attribute is not available for the condition to use.

Is there a way to make this work or is there a better way to conditionally run the CFT that attaches the EBS volume?

Thanks in advance...

1

1 Answers

0
votes

The important section of the Conditions documentation is this

Parameters

Define the input values that you want to evaluate in your conditions. Conditions will result in true or false based on values from these input parameters.

Conditions in CloudFormation can be based on Parameters alone. They can't take in-flight resource values into account, as these values aren't known at compile time.