【发布时间】:2016-03-10 08:55:02
【问题描述】:
我正在尝试编写一个 JQ 过滤器,用于根据资源属性从 AWS cloudformation 模板中过滤特定资源。
例如,从以下(缩短的)cloudformation 模板开始时:
{
"Resources": {
"vpc001": {
"Type": "AWS::EC2::VPC",
"Properties": {
"CidrBlock": "10.1.0.0/16",
"InstanceTenancy": "default",
"EnableDnsSupport": "true",
"EnableDnsHostnames": "true"
}
},
"ig001": {
"Type": "AWS::EC2::InternetGateway",
"Properties": {
"Tags": [
{
"Key": "Name",
"Value": "ig001"
}
]
}
}
}
}
我想构建一个 jq 过滤器,使我能够根据(一个或多个)属性字段过滤掉特定资源。
例如:
当过滤 Type="AWS::EC2::InternetGateway" 时,结果应该是
{
"Resources": {
"ig001": {
"Type": "AWS::EC2::InternetGateway",
"Properties": {
"Tags": [
{
"Key": "Name",
"Value": "ig001"
}
]
}
}
}
}
一个额外的好处是能够过滤一个“或”的值组合。 因此,“AWS::EC2::InternetGateway”或“AWS::EC2::VPC”的过滤器应生成原始文档。
任何建议或见解将不胜感激。
发送!
【问题讨论】:
标签: json amazon-cloudformation jq