4
votes

I am writing a AWS Code formation. I have to print the Cidrblock of a subnet. But that does not work. Please help

"Resources": {
    "Subnet": {
          "Type": "AWS::EC2::Subnet",
          "Properties": {
            "VpcId": {
              "Ref": "VPC"
            },
            "CidrBlock": "10.0.0.0/16",
          }
    },
    Outputs : {
      "SubnetCIDR": {
          "Value": {
            "Fn::GetAtt": [
              "Subnet",
              "CidrBlock"
            ]
          },
          "Description": "The CIDR"
        },
    }

This does not work. The following error message is shown while uploading the template:

Template validation error: Template error: resource Subnet does not support attribute type CidrBlock in Fn::GetAtt

2
can u define what is doesnot work mean?Kumar Saurabh
I have added the error message.Mahesh Bisl

2 Answers

5
votes

Not supported.

http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-subnet.html

If you look at the doc, the only supported attribute is AvailabilityZone

2
votes

Since you seem to be hard coding the CIDR block anyway, you could set it as a parameter and then just reference the parameter in both places.

"Parameters" : {
  "CidrBlock" : {
    "Type" : "String",
    "Default" : "10.0.0.0/16"
  }
},
"Resources" : {
  "Subnet" : {
    "Type" : "AWS::EC2::Subnet",
    "Properties" : {
      "VpcId" : {
        "Ref" : "VPC"
      },
      "CidrBlock" : { "Ref" : "CidrBlock" }
    }
  }
},
"Outputs" : {
  "SubnetCIDR" : {
    "Value" : { "Ref" : "CidrBlock" },
    "Description": "The CIDR"
  }
}