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

tftypes: Allow DynamicPseudoType with known values #136

Merged
merged 3 commits into from Jan 13, 2022

Conversation

bflad
Copy link
Member

@bflad bflad commented Jan 7, 2022

Reference: #94
Reference: #99
Reference: #100
Reference: #128
Closes #133

Reverts incorrect logic for handling DynamicPseudoType values in tftypes. This type information must be preserved when traversing the protocol, as Terraform CLI decodes values based on the schema information. If a concrete value type is used where DynamicPseudoType is expected, Terraform CLI will return errors such as (given an object of 4 attributes, when DynamicPseudoType is expected):

│ Error: ["manifest"]: msgpack: invalid code=84 decoding array length

Reference: #94
Reference: #99
Reference: #100
Reference: #128
Reference: #133

Reverts incorrect logic for handling DynamicPseudoType values in `tftypes`. This type information must be preserved when traversing the protocol, as Terraform CLI decodes values based on the schema information. If a concrete value type is used where DynamicPseudoType is expected, Terraform CLI will return errors such as (given an object of 4 attributes, when DynamicPseudoType is expected):

```
│ Error: ["manifest"]: msgpack: invalid code=84 decoding array length
```
@bflad bflad added the bug Something isn't working label Jan 7, 2022
@bflad bflad added this to the v0.6.0 milestone Jan 7, 2022
@bflad bflad requested review from alexsomesan and a team January 7, 2022 19:01
@bflad
Copy link
Member Author

bflad commented Jan 7, 2022

@alexsomesan it seems to work as expected on the terraform-provider-kubernetes update-sdk branch after also including this branch via:

go get github.com/hashicorp/terraform-plugin-go@bflad-tftypes-DynamicPseudoType-values
go mod tidy
go mod vendor

But please reach out if it doesn't.

$ terraform apply

│ Warning: Provider development overrides are in effect

│ The following provider development overrides are set in the CLI configuration:
│  - bflad/framework in /Users/bflad/go/bin
│  - hashicorp/awscc in /Users/bflad/go/bin
│  - hashicorp/corner in /Users/bflad/go/bin
│  - hashicorp/hashicups in /Users/bflad/go/bin
│  - hashicorp/kubernetes in /Users/bflad/go/bin
│  - hashicorp.com/edu/hashicups in /Users/bflad/go/bin

│ The behavior may therefore not match any released version of the provider and applying changes may cause the state to become incompatible with published releases.


Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # kubernetes_manifest.test-configmap will be created
  + resource "kubernetes_manifest" "test-configmap" {
      + manifest = {
          + apiVersion = "v1"
          + data       = {
              + foo = "bar"
            }
          + kind       = "ConfigMap"
          + metadata   = {
              + labels    = {
                  + app         = "test-app"
                  + environment = "production"
                }
              + name      = "test-config"
              + namespace = "default"
            }
        }
      + object   = {
          + apiVersion = "v1"
          + binaryData = (known after apply)
          + data       = {
              + "foo" = "bar"
            }
          + immutable  = (known after apply)
          + kind       = "ConfigMap"
          + metadata   = {
              + annotations                = (known after apply)
              + clusterName                = (known after apply)
              + creationTimestamp          = (known after apply)
              + deletionGracePeriodSeconds = (known after apply)
              + deletionTimestamp          = (known after apply)
              + finalizers                 = (known after apply)
              + generateName               = (known after apply)
              + generation                 = (known after apply)
              + labels                     = (known after apply)
              + managedFields              = (known after apply)
              + name                       = "test-config"
              + namespace                  = "default"
              + ownerReferences            = (known after apply)
              + resourceVersion            = (known after apply)
              + selfLink                   = (known after apply)
              + uid                        = (known after apply)
            }
        }
    }

Plan: 1 to add, 0 to change, 0 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

kubernetes_manifest.test-configmap: Creating...
kubernetes_manifest.test-configmap: Creation complete after 0s

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

@alexsomesan
Copy link
Member

It works!

I've tested this with kubernetes_manifest resources following the scenario reported in issue #133 and can confirm this change resolves the reported issue.

➜  configmap git:(update-sdk) ✗ terraform apply -auto-approve
╷
│ Warning: Provider development overrides are in effect
│
│ The following provider development overrides are set in the CLI configuration:
│  - hashicorp/kubernetes in /Users/alex/work/terraform-provider-kubernetes
│
│ The behavior may therefore not match any released version of the provider and applying changes may cause the state to become incompatible with published releases.
╵

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # kubernetes_manifest.test-configmap will be created
  + resource "kubernetes_manifest" "test-configmap" {
      + manifest = {
          + apiVersion = "v1"
          + data       = {
              + foo = "bar"
            }
          + kind       = "ConfigMap"
          + metadata   = {
              + labels    = {
                  + app         = "test-app"
                  + environment = "production"
                }
              + name      = "test-config"
              + namespace = "default"
            }
        }
      + object   = {
          + apiVersion = "v1"
          + binaryData = (known after apply)
          + data       = {
              + "foo" = "bar"
            }
          + immutable  = (known after apply)
          + kind       = "ConfigMap"
          + metadata   = {
              + annotations                = (known after apply)
              + clusterName                = (known after apply)
              + creationTimestamp          = (known after apply)
              + deletionGracePeriodSeconds = (known after apply)
              + deletionTimestamp          = (known after apply)
              + finalizers                 = (known after apply)
              + generateName               = (known after apply)
              + generation                 = (known after apply)
              + labels                     = (known after apply)
              + managedFields              = (known after apply)
              + name                       = "test-config"
              + namespace                  = "default"
              + ownerReferences            = (known after apply)
              + resourceVersion            = (known after apply)
              + selfLink                   = (known after apply)
              + uid                        = (known after apply)
            }
        }
    }

Plan: 1 to add, 0 to change, 0 to destroy.
kubernetes_manifest.test-configmap: Creating...
kubernetes_manifest.test-configmap: Creation complete after 0s

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
➜  configmap git:(update-sdk)

@bflad
Copy link
Member Author

bflad commented Jan 13, 2022

Excellent! Going to pull this in today and hopefully we can release v0.6.0 with this 🔜

@bflad bflad merged commit 5ad95e8 into main Jan 13, 2022
@bflad bflad deleted the bflad-tftypes-DynamicPseudoType-values branch January 13, 2022 16:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MsgPack encoding issue after upgrading to v0.5.0
2 participants