'Change a key values based on a different value
I have the following YAML file :
affinityCookieTtlSec: 0
backends:
- balancingMode: UTILIZATION
capacityScaler: 0.0
group: https://www.googleapis.com/compute/v1/projects/production/regions/us/instanceGroups/prod-instance-service-green
maxRatePerInstance: 900.0
maxUtilization: 0.8
- balancingMode: UTILIZATION
capacityScaler: 1.0
group: https://www.googleapis.com/compute/v1/projects/production/regions/us/instanceGroups/prod-instance-service-blue
maxRatePerInstance: 900.0
maxUtilization: 0.8
Using yq, I would like to change the capacityScaler value based on group value, for example:
If group is equal to https://www.googleapis.com/compute/v1/projects/production/regions/us/instanceGroups/prod-instance-service-green, change the capacityScaler in the same list to 0.5.
So the output should be:
affinityCookieTtlSec: 0
backends:
- balancingMode: UTILIZATION
capacityScaler: 0.5
group: https://www.googleapis.com/compute/v1/projects/production/regions/us/instanceGroups/prod-instance-service-green
maxRatePerInstance: 900.0
maxUtilization: 0.8
- balancingMode: UTILIZATION
capacityScaler: 1.0
group: https://www.googleapis.com/compute/v1/projects/production/regions/us/instanceGroups/prod-instance-service-blue
maxRatePerInstance: 900.0
maxUtilization: 0.8
So far, I figured I can list the lists by yq e '.backends[0] or yq e '.backends[1], but I'm not able to select the correct list by the group value.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
