PrefectHQ / terraform-provider-prefect

Terraform Provider for Prefect Cloud
https://registry.terraform.io/providers/PrefectHQ/prefect/latest/docs
Apache License 2.0
29 stars 13 forks source link

hygiene: audit all computed resource schema attributes + set planmodifier for relatively static values #200

Closed parkedwards closed 3 weeks ago

parkedwards commented 3 weeks ago

it should actually be for computed values that are immutable - id and created

since they aren't set by us, they are computed (and come from the API). however, when we run terraform plan, the framework doesn't know whether or not those values WILL change, so we'll often find plan outputs that look like this:

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:

  # prefect_block.foo will be updated in-place
  ~ resource "prefect_block" "foo" {
      ~ created   = "2024-06-06T23:19:59Z" -> (known after apply)
      ~ data      = (sensitive value)
        id        = "626d4f5b-58e8-4604-adcf-d3415c40c1dd"
        name      = "foo"
      ~ updated   = "2024-06-06T23:20:17Z" -> (known after apply)
        # (1 unchanged attribute hidden)
    }

Plan: 0 to add, 1 to change, 0 to destroy.
prefect_block.foo: Modifying... [id=626d4f5b-58e8-4604-adcf-d3415c40c1dd]
prefect_block.foo: Modifications complete after 0s [id=626d4f5b-58e8-4604-adcf-d3415c40c1dd]

however, created will never change after the resource is created. similar to id, these are immutable values that ARENT set by us, and so we can use a planmodifier here to tell the framework to use the existing state as the baseline when running a plan

https://developer.hashicorp.com/terraform/plugin/framework/resources/plan-modification#usestateforunknown

UseStateForUnknown(): Copies the prior state value, if not null. This is useful for reducing (known after apply) plan outputs for computed attributes which are known to not change over time.