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

Add provider defined functions for encoding and decoding Kubernetes manifests #2428

Merged
merged 42 commits into from
Apr 5, 2024

Conversation

jrhouston
Copy link
Collaborator

@jrhouston jrhouston commented Feb 20, 2024

Description

This PR introduces the following provider defined functions:

  • manifest_encode to encode a Terraform object representation of a Kubernetes manifest as a YAML string.
  • manifest_decode to decode a string containing a Kubernetes manifest in YAML format and return it as a Terraform object.
  • manifest_decode_multi To do the above but for YAML manifests containing multiple resources.

Solves hashicorp/terraform#29729

TODO

Output from acceptance testing:

$ make testacc TESTARGS='-run=TestAccXXX'

...

Release Note

Release note for CHANGELOG:

...

References

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

@jrhouston jrhouston requested a review from a team as a code owner February 20, 2024 14:41
@jrhouston jrhouston marked this pull request as draft February 20, 2024 14:42
Copy link
Member

@SarahFrench SarahFrench left a comment

Choose a reason for hiding this comment

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

I'm assuming it's too early to review for real, but something that could be added in internal/framework/provider/provider.go is

// Ensure KubernetesProvider satisfies various provider interfaces.
var _ provider.Provider = &KubernetesProvider{}
+ var _ provider.ProviderWithFunctions  = &KubernetesProvider{}

Copy link
Member

@austinvalle austinvalle left a comment

Choose a reason for hiding this comment

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

Looks awesome!

return types.TupleValue(tl, vl)
}

func decodeScalar(m any) (value attr.Value, diags diag.Diagnostics) {
Copy link
Member

Choose a reason for hiding this comment

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

As you probably found out, we punted on defining any reflection rules for converting native Go types into a types.Dynamic. We started down that route and then decided we'd rather return to the problem later.

Perhaps when your team (or other developers) start looking at potentially using types.Dynamic with managed resources/data source schemas we could revisit that problem.

@jrhouston jrhouston changed the title Add manifest_decode() function Add provider defined functions for encoding and decoding Kubernetes manifests Mar 4, 2024
@jrhouston jrhouston force-pushed the add-manifest-decode-function branch from 8d6534c to 217b4bf Compare March 26, 2024 20:06
@jrhouston jrhouston marked this pull request as ready for review March 27, 2024 21:26
{
Config: testManifestDecodeMultiConfig("testdata/decode_single.yaml"),
ConfigStateChecks: []statecheck.StateCheck{
statecheck.ExpectKnownOutputValue(outputName, knownvalue.ListExact([]knownvalue.Check{
Copy link
Member

@austinvalle austinvalle Mar 27, 2024

Choose a reason for hiding this comment

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

Not released yet, but in terraform-plugin-testing v1.8.0 you can use the essentially equivalent TupleExact for a little better readability 👍🏻

Ref: hashicorp/terraform-plugin-testing#312

@jrhouston jrhouston force-pushed the add-manifest-decode-function branch from 9a6aeec to 4915eaa Compare April 5, 2024 19:56
@jrhouston jrhouston merged commit 75fa00f into main Apr 5, 2024
16 checks passed
@jrhouston jrhouston deleted the add-manifest-decode-function branch April 5, 2024 20:35
dduportal referenced this pull request in jenkins-infra/azure Apr 9, 2024
<Actions>
<action
id="bcd9b70d7c1eb1e07eb5ad8a958f18dc1bbd81461ee1a2604adeea46e3148a47">
        <h3>Bump Terraform `kubernetes` provider version</h3>
<details
id="1d9343c012f5434ac9fe8a98135bae3667b399259be16d9b14302ea3bd424a24">
            <summary>Update Terraform lock file</summary>
<p>changes detected:&#xA;&#x9;&#34;hashicorp/kubernetes&#34; updated
from &#34;2.27.0&#34; to &#34;2.28.0&#34; in file
&#34;.terraform.lock.hcl&#34;</p>
            <details>
                <summary>2.28.0</summary>
<pre>Changelog retrieved
from:&#xA;&#x9;https://github.com/hashicorp/terraform-provider-kubernetes/releases/tag/v2.28.0&#xA;ENHANCEMENTS:&#xA;&#xA;**NOTE:
Using [Provider Defined
Functions](https://developer.hashicorp.com/terraform/plugin/framework/functions/concepts)
requires Terraform version 1.8.0.**&#xA;&#xA;* Add provider defined
functions: `manifest_encode`, `manifest_decode`, `manifest_decode_multi`
[[GH-2428](https://github.com/hashicorp/terraform-provider-kubernetes/issues/2428)]&#xA;&#xA;&#xA;</pre>
            </details>
        </details>
<a
href="https://infra.ci.jenkins.io/job/updatecli/job/azure/job/main/96/">Jenkins
pipeline link</a>
    </action>
</Actions>

---

<table>
  <tr>
    <td width="77">
<img src="https://www.updatecli.io/images/updatecli.png" alt="Updatecli
logo" width="50" height="50">
    </td>
    <td>
      <p>
Created automatically by <a
href="https://www.updatecli.io/">Updatecli</a>
      </p>
      <details><summary>Options:</summary>
        <br />
<p>Most of Updatecli configuration is done via <a
href="https://www.updatecli.io/docs/prologue/quick-start/">its
manifest(s)</a>.</p>
        <ul>
<li>If you close this pull request, Updatecli will automatically reopen
it, the next time it runs.</li>
<li>If you close this pull request and delete the base branch, Updatecli
will automatically recreate it, erasing all previous commits made.</li>
        </ul>
        <p>
Feel free to report any issues at <a
href="https://github.com/updatecli/updatecli/issues">github.com/updatecli/updatecli</a>.<br
/>
If you find this tool useful, do not hesitate to star <a
href="https://github.com/updatecli/updatecli/stargazers">our GitHub
repository</a> as a sign of appreciation, and/or to tell us directly on
our <a
href="https://matrix.to/#/#Updatecli_community:gitter.im">chat</a>!
        </p>
      </details>
    </td>
  </tr>
</table>

Co-authored-by: Jenkins Infra Bot (updatecli) <60776566+jenkins-infra-bot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants