How get “cidrblock” of a subnet in the “outputs” of a AWS Cloudformation?

a 夏天 提交于 2019-12-23 17:43:35

问题


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


回答1:


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:


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"
  }
}


来源:https://stackoverflow.com/questions/33391999/how-get-cidrblock-of-a-subnet-in-the-outputs-of-a-aws-cloudformation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!