Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix scraping Refs from attributes containing lists #441

Merged
merged 3 commits into from
Oct 7, 2024

Conversation

rickard-von-essen
Copy link
Contributor

@rickard-von-essen rickard-von-essen commented Oct 5, 2024

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:

  • Read and followed Upjet's [contribution process].
  • Run make reviewable to ensure this PR is ready for review.
  • Added backport release-x.y labels to auto-backport this PR if necessary.

How has this code been tested

By updating the unit test in meta_test.go and rebuilding provider-upjet-gcp (rickard-von-essen/provider-upjet-gcp@f162f83)

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

Example 1):

```hcl
    require_attestations_by = [google_binary_authorization_attestor.attestor.name]
```

Does not add:

```
cluster_admission_rules.require_attestations_by: google_binary_authorization_attestor.attestor.name
```

As it should since the reference is contained in a _list_.

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

Signed-off-by: Rickard von Essen <rickard.von.essen@gmail.com>
This correctly parses references contained in lists and adds them to the map of
references.

Example 1):

```hcl
    require_attestations_by = [google_binary_authorization_attestor.attestor.name]
```

Correctly generates a ref and 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

Signed-off-by: Rickard von Essen <rickard.von.essen@gmail.com>
rickard-von-essen added a commit to rickard-von-essen/provider-upjet-gcp that referenced this pull request Oct 5, 2024
Signed-off-by: Rickard von Essen <rickard.von.essen@gmail.com>
Copy link
Member

@sergenyalcin sergenyalcin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @rickard-von-essen for this valuable fix. I also tested the change against provider-upjet-aws and did not observe any issue or unwanted changes. LGTM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

examples-generated contain terraform variables in the yaml that are not meaningfully consumable
3 participants