uwieuwe4
uwieuwe4

Reputation: 153

How to use attributes in an Inspec command?

I defined some basic Inspec tests to check if a loadbalancer is active:

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

I use a variable called "proxy" which contains the ARN of the Loadbalancer. Unfortunately the variable is not recognized as such because it is inside the command.

Upvotes: 0

Views: 1545

Answers (1)

Mr.
Mr.

Reputation: 10122

you should use string interpolation to get the value of your string variable.

assuming proxy['value'] returns the value of the proxy variable. then you can do it as follows:

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

Upvotes: 1

Related Questions