Shubham Jain
Shubham Jain

Reputation: 17553

How to add list having map in YAML using yq

How to add list having map in YAML using yq , I also need to use properties file for input

I have below yaml:

apiVersion: core.oci.upbound.io/v1alpha1
kind: Instance
metadata:
  name: crossplane-inst-flat
spec:
  forProvider:
    compartmentIdRef:
      name: compartment-oke-shu
    createVnicDetails:
      - subnetIdRef:
          name: crossplane-srg-subnet
    availabilityDomain: "yyy:PHX-AD-1"
    shape: "VM.Standard2.1"
    sourceDetails:
      - sourceId: ocid1.image.oc1.phx.7ytytytytytyt
        sourceType: "image"
    displayName: crossplane-inst-flat

I want to change below name value:

createVnicDetails:
  - subnetIdRef:
      name: crossplane-srg-subnet

And source id in below section also the other map should persist as well

    sourceDetails:
      - sourceId: ocid1.image.oc1.phx.7ytytytytytyt

Using below config.properties syntax:

spec.forProvider.createVnicDetails.subnetIdRef.name=test
spec.forProvider.sourceDetails.sourceId=ocid1.image.oc1.phx.hhhh
spec.forProvider.sourceDetails.sourceType=image

sh file expression:

 '. *= load_props("/compute.properties")' config.yaml

but they are not working as expected, the list -(dash) is missing. how to do this without sed

Upvotes: 0

Views: 252

Answers (1)

flyx
flyx

Reputation: 39638

Your paths are missing the sequence indexes.

These expressions do what you want:

.spec.forProvider.createVnicDetails[].subnetIdRef.name = "test"
.spec.forProvider.sourceDetails[].sourceId = "ocid1.image.oc1.phx.hhhh"
.spec.forProvider.sourceDetails[].sourceType = "image"

You may want to use [0] instead of [] if you explicitly want to only update the first sequence item.

You can specify these in property syntax:

spec.forProvider.createVnicDetails.0.subnetIdRef.name=test
spec.forProvider.sourceDetails.0.sourceId=ocid1.image.oc1.phx.hhhh
spec.forProvider.sourceDetails.0.sourceType=image

Upvotes: 1

Related Questions