Skip to content

Add BlockDeviceMappings tags inside of "Type": "AWS::EC2::Instance"

0

In CloudFormation if I have the following snippet of code

        "TMEC2": {
            "Type": "AWS::EC2::Instance",
            "Properties": {
                "InstanceType": { "Ref": "InstanceType" },
                "ImageId": {
                    "Fn::FindInMap": [
                        { "Fn::FindInMap": [ "EC2Images", { "Ref": "InstanceImage" }, "EC2ImageMap" ] },
                        { "Ref": "AWS::Region" },
                        { "Ref": "AWS::AccountId" }
                    ]
                },
                "BlockDeviceMappings": [
                    {
                        "DeviceName": "/dev/sdf",
                        "Ebs": { "VolumeType": "gp3", "VolumeSize": "50", "DeleteOnTermination": "false", "Encrypted": "true", "KmsKeyId": { "Ref": "TDSKeyEBSTMMain" } }
                    }
                ],

Is it possible to add tags to the EBS block device for like Tag-> Name Key-> instancename::/dev/sda.

Or is there a way to grab the EBS Volume resource name so I can apply the tags using the Volume resource?

asked a year ago622 views
2 Answers
0
Accepted Answer

If you want the volumes to have the same tags as the instance, you can enable the PropagateTagsToVolumeOnCreation property on the EC2::Instance to achieve that.

If you want different tags, you'll have to create the volumes separately from the instance with the resource type AWS::EC2::Volume and use AWS::EC2::VolumeAttachment to attach them to your instance.

EXPERT
answered a year ago
EXPERT
reviewed a year ago
0

In AWS CloudFormation, you cannot directly add tags to EBS volumes through the BlockDeviceMappings of an AWS::EC2::Instance resource. However, you can create the EBS volume as a separate AWS::EC2::Volume resource and then attach it to the instance. This approach allows you to add tags to the EBS volume.

You can modify your CloudFormation template to achieve this:Create the EBS Volume as a separate resource: Define the EBS volume with the desired tags. Attach the EBS Volume to the EC2 instance: Use an AWS::EC2::VolumeAttachment resource to attach the volume to the instance.

EXPERT
answered a year ago
EXPERT
reviewed a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.