Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BlockDeviceMappingProperty Under Condition_If #16045

Closed
davidurias opened this issue Aug 13, 2021 · 3 comments
Closed

BlockDeviceMappingProperty Under Condition_If #16045

davidurias opened this issue Aug 13, 2021 · 3 comments
Labels
bug This issue is a bug. needs-triage This issue or PR still needs to be triaged.

Comments

@davidurias
Copy link

davidurias commented Aug 13, 2021

When using If to deploy or not Secondary EBS Devices, those secondary devices in the AWS CFN Template are created with the first letter as lowercase and must be Uppercase as required by CFN,

Python.
Create an ec2.CfnInstance resource.

Set conditionals under the block_device_mapping as follow:

block_device_mappings=[
                ec2.CfnInstance.BlockDeviceMappingProperty(
                    device_name="/dev/sda1",
                    ebs=ec2.CfnInstance.EbsProperty(
                        volume_type="gp3",
                        volume_size=Param_Ebs_Root.value_as_number,
                        delete_on_termination=True,
                        encrypted=True
                    )
                ),
                Fn.condition_if(If_2nd_ebs.logical_id,
                                value_if_true=ec2.CfnInstance.BlockDeviceMappingProperty(
                                                device_name="xvdf",
                                                ebs=ec2.CfnInstance.EbsProperty(
                                                    volume_type="gp3",
                                                    volume_size=Param_Ebs_Root.value_as_number,
                                                    delete_on_termination=True,
                                                    encrypted=True
                                                )
                                            ),
                                value_if_false=Aws.NO_VALUE
                                )
                ,
                Fn.condition_if(If_3rd_ebs.logical_id,
                                value_if_true=ec2.CfnInstance.BlockDeviceMappingProperty(
                                    device_name="xvdg",
                                    ebs=ec2.CfnInstance.EbsProperty(
                                        volume_type="gp3",
                                        volume_size=Param_Ebs_3rd.value_as_number,
                                        delete_on_termination=True,
                                        encrypted=True
                                    )
                                ),
                                value_if_false=Aws.NO_VALUE
                                )
                ,
            ],

Do a syntethsize and you will get the following result:

"BlockDeviceMappings": [
          {
            "DeviceName": "/dev/sda1",
            "Ebs": {
              "DeleteOnTermination": true,
              "Encrypted": true,
              "VolumeSize": {
                "Ref": "ParamEbsRoot"
              },
              "VolumeType": "gp3"
            }
          },
          {
            "Fn::If": [
              "If2ndEbs",
              {
                "deviceName": "xvdf",
                "ebs": {
                  "deleteOnTermination": true,
                  "encrypted": true,
                  "volumeSize": {
                    "Ref": "ParamEbsRoot"
                  },
                  "volumeType": "gp3"
                }
              },
              {
                "Ref": "AWS::NoValue"
              }
            ]
          },
          {
            "Fn::If": [
              "If3rdEbs",
              {
                "deviceName": "xvdg",
                "ebs": {
                  "deleteOnTermination": true,
                  "encrypted": true,
                  "volumeSize": {
                    "Ref": "ParamEbs3rd"
                  },
                  "volumeType": "gp3"
                }
              },
              {
                "Ref": "AWS::NoValue"
              }
            ]
          }
        ]

Which is not correct,

Regards,

Environment

  • **CDK CLI Version : 1.118.0
  • **Node.js Version: 7.19.1
  • **OS : Mac Os 11.4
  • **Language (Version): Python 3.9
@davidurias davidurias added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Aug 13, 2021
@peterwoodworth
Copy link
Contributor

Sorry for the long response time here, and thank you for reporting this issue

This issue is documented, so I'm going to close this in favor of #8396. Please see that thread for more information and some workarounds.

@peterwoodworth
Copy link
Contributor

Sorry for the long response time here, and thank you for reporting this issue

This issue is documented, so I'm going to close this in favor of #8396. Please see that thread for more information and some workarounds.

@github-actions
Copy link

github-actions bot commented Oct 6, 2021

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. needs-triage This issue or PR still needs to be triaged.
Projects
None yet
Development

No branches or pull requests

2 participants