如何在 Inspec 命令中使用属性?
How to use attributes in an Inspec command?
我定义了一些基本的 Inspec 测试来检查负载均衡器是否处于活动状态:
proxy = attribute('proxy_netlb_arn')
control 'Checks if all the ECE Load balancers are active ' do
impact 1.0
title 'Checks if all the ECE Load balancers are active'
describe command("aws elbv2 describe-load-balancers --load-balancer-arn proxy['value'] | jq -r '.[][].State.Code'") do
its('stdout') { should match "active" }
end
end
我使用一个名为 "proxy" 的变量,其中包含负载均衡器的 ARN。不幸的是,该变量未被识别,因为它在命令中。
您应该使用 string interpolation 来获取您的字符串变量的值。
假设 proxy['value']
returns proxy
变量的值。那么你可以按如下方式进行:
proxy = attribute('proxy_netlb_arn')
control 'Checks if all the ECE Load balancers are active ' do
impact 1.0
title 'Checks if all the ECE Load balancers are active'
describe command("aws elbv2 describe-load-balancers --load-balancer-arn #{proxy['value']} | jq -r '.[][].State.Code'") do
its('stdout') { should match "active" }
end
end
我定义了一些基本的 Inspec 测试来检查负载均衡器是否处于活动状态:
proxy = attribute('proxy_netlb_arn')
control 'Checks if all the ECE Load balancers are active ' do
impact 1.0
title 'Checks if all the ECE Load balancers are active'
describe command("aws elbv2 describe-load-balancers --load-balancer-arn proxy['value'] | jq -r '.[][].State.Code'") do
its('stdout') { should match "active" }
end
end
我使用一个名为 "proxy" 的变量,其中包含负载均衡器的 ARN。不幸的是,该变量未被识别,因为它在命令中。
您应该使用 string interpolation 来获取您的字符串变量的值。
假设 proxy['value']
returns proxy
变量的值。那么你可以按如下方式进行:
proxy = attribute('proxy_netlb_arn')
control 'Checks if all the ECE Load balancers are active ' do
impact 1.0
title 'Checks if all the ECE Load balancers are active'
describe command("aws elbv2 describe-load-balancers --load-balancer-arn #{proxy['value']} | jq -r '.[][].State.Code'") do
its('stdout') { should match "active" }
end
end