crossplane / upjet

A code generation framework and runtime for Crossplane providers
Apache License 2.0
319 stars 89 forks source link

Fix scraping Refs from attributes containing lists #441

Closed rickard-von-essen closed 1 month ago

rickard-von-essen commented 1 month ago

Description of your changes

Scraping does not handle TupleConsExpr when parsing example HCL code from Terraform documentation.

Example 1):

    require_attestations_by = [google_binary_authorization_attestor.attestor.name]

Does not add:

cluster_admission_rules.require_attestations_by: google_binary_authorization_attestor.attestor.name

To metadata as it should since the reference is contained in a list.

With this patch it's correctly scraped and adds a ref. Building provider-upjet-gcp with this change produces the expected examples-generated/binaryauthorization/v1beta2/policy.yaml with this diff compared to without this change.

@@ -14,8 +14,8 @@ spec:
     - cluster: us-central1-a.prod-cluster
       enforcementMode: ENFORCED_BLOCK_AND_AUDIT_LOG
       evaluationMode: REQUIRE_ATTESTATION
-      requireAttestationsBy:
-      - ${google_binary_authorization_attestor.attestor.name}
+      requireAttestationsByRefs:
+      - name: attestor
     defaultAdmissionRule:
     - enforcementMode: ENFORCED_BLOCK_AND_AUDIT_LOG
        evaluationMode: ALWAYS_ALLOW

1) https://github.com/hashicorp/terraform-provider-google/blob/v5.39.0/website/docs/r/binary_authorization_policy.html.markdown?plain=1#L49

Fixes #349

I have:

How has this code been tested

By updating the unit test in meta_test.go and rebuilding provider-upjet-gcp (https://github.com/rickard-von-essen/provider-upjet-gcp/commit/f162f8325cd51b769658fc9f021af36c02eea017)