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

Remove marking of entire object as unknown when child attribute is unknown #63

Merged
merged 2 commits into from
Oct 10, 2023

Conversation

austinvalle
Copy link
Member

This PR:

  • Removes the logic that marks an entire object as unknown when one of the child attributes is unknown
  • Adds a final diag check before returning to avoid any weird object states (i.e. an object is known, but has a bunch of nil values because it had diags 😆 )

@austinvalle austinvalle requested a review from a team as a code owner October 10, 2023 20:07
@austinvalle austinvalle changed the title Remove marking of entire attribute as unknown when nested attribute is unknown Remove marking of entire object as unknown when child attribute is unknown Oct 10, 2023
@austinvalle
Copy link
Member Author

austinvalle commented Oct 10, 2023

I did some testing with the petstore workflow example (where I originally ran into invalid plan errors due to a nested attribute being marked as unknown):

resource "petstore_pet" "clifford" {
  id   = 12345
  name = "Clifford the Big Red Dog"
  photo_urls = [
    "https://example.com/pet.jpg"
  ]
  category = {
    id = 1
   # name is a computed/optional field! 
  }
}

Now the terraform apply works 🚀 (the provider update code just sets unknown stuff to null)

 $ terraform apply -auto-approve
╷
│ Warning: Provider development overrides are in effect
│ 
│ The following provider development overrides are set in the CLI configuration:
│  - hashicorp.com/edu/petstore in /Users/austin.valle/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.
╵
petstore_pet.clifford: Refreshing state... [name=Clifford the Big Red Dog]

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  # petstore_pet.clifford will be updated in-place
  ~ resource "petstore_pet" "clifford" {
      + category   = {
          + id   = 1
          + name = (known after apply)
        }
        id         = 12345
        name       = "Clifford the Big Red Dog"
      + status     = (known after apply)
      + tags       = (known after apply)
        # (1 unchanged attribute hidden)
    }

Plan: 0 to add, 1 to change, 0 to destroy.
petstore_pet.clifford: Modifying... [name=Clifford the Big Red Dog]
petstore_pet.clifford: Modifications complete after 0s [name=Clifford the Big Red Dog]

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

Copy link
Contributor

@bflad bflad left a comment

Choose a reason for hiding this comment

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

This seems like better behavior for this functionality 👍

@austinvalle austinvalle merged commit b488bac into main Oct 10, 2023
@austinvalle austinvalle deleted the av/update-unknown-marking branch October 10, 2023 20:41
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants