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

fix(blocks): always replace Block data on update #217

Closed parkedwards closed 2 weeks ago

parkedwards commented 2 weeks ago

resolves https://github.com/PrefectHQ/terraform-provider-prefect/issues/215

Also, I'm adding a questionably-useful make dev-new command, which creates a test file in a new gitignored directly, which scaffolds some of the commonly copy-pasta'ed TF configuration blocks.

➜ make help
Usage: /Library/Developer/CommandLineTools/usr/bin/make [target]

This project defines the following build targets:
...
  dev-new    - creates a new dev testfile (args: resource=<resource> name=<name>)
  dev-clean  - cleans up dev directory

Testing

docker-compose up -d

Before:

terraform {
  required_providers {
    prefect = {
      source = "prefecthq/prefect"
    }
  }
}

provider "prefect" {
  endpoint = "http://localhost:4200"
}

resource "prefect_block" "json" {
  name = "json"
  type_slug = "json"
  data = jsonencode({
    "value" = "foo"
    "value2" = "bar"
  })
}
➜ terraform apply --auto-approve
╷
│ Warning: Provider development overrides are in effect
│
│ The following provider development overrides are set in the CLI configuration:
│  - prefecthq/prefect in /Users/edwardpark/CODE/prefect/terraform-provider-prefect/build
│
│ 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:

  # prefect_block.json will be created
  + resource "prefect_block" "json" {
      + created   = (known after apply)
      + data      = (sensitive value)
      + id        = (known after apply)
      + name      = "json"
      + type_slug = "json"
      + updated   = (known after apply)
    }

Plan: 1 to add, 0 to change, 0 to destroy.
prefect_block.json: Creating...
prefect_block.json: Creation complete after 0s [id=75c59269-f1e5-46b5-aebb-3f089163283f]

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

You should see the resource being created. Now remove value2 and apply again and see the error

resource "prefect_block" "json" {
  name = "json"
  type_slug = "json"
  data = jsonencode({
    "value" = "foo"
  })
}
➜ terraform apply --auto-approve
╷
│ Warning: Provider development overrides are in effect
│
│ The following provider development overrides are set in the CLI configuration:
│  - prefecthq/prefect in /Users/edwardpark/CODE/prefect/terraform-provider-prefect/build
│
│ 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.
╵
prefect_block.json: Refreshing state... [id=75c59269-f1e5-46b5-aebb-3f089163283f]

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.json will be updated in-place
  ~ resource "prefect_block" "json" {
      ~ data      = (sensitive value)
        id        = "75c59269-f1e5-46b5-aebb-3f089163283f"
        name      = "json"
      ~ updated   = "2024-06-14T19:31:09Z" -> (known after apply)
        # (2 unchanged attributes hidden)
    }

Plan: 0 to add, 1 to change, 0 to destroy.
prefect_block.json: Modifying... [id=75c59269-f1e5-46b5-aebb-3f089163283f]
╷
│ Error: Provider produced inconsistent result after apply
│
│ When applying changes to prefect_block.json, provider "provider[\"registry.terraform.io/prefecthq/prefect\"]"
│ produced an unexpected new value: .data: inconsistent values for sensitive attribute.
│
│ This is a bug in the provider, which should be reported in the provider's own issue tracker.

After (same steps):

➜ terraform apply --auto-approve
╷
│ Warning: Provider development overrides are in effect
│
│ The following provider development overrides are set in the CLI configuration:
│  - prefecthq/prefect in /Users/edwardpark/CODE/prefect/terraform-provider-prefect/build
│
│ 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:

  # prefect_block.json will be created
  + resource "prefect_block" "json" {
      + created   = (known after apply)
      + data      = (sensitive value)
      + id        = (known after apply)
      + name      = "json"
      + type_slug = "json"
      + updated   = (known after apply)
    }

Plan: 1 to add, 0 to change, 0 to destroy.
prefect_block.json: Creating...
prefect_block.json: Creation complete after 0s [id=8cb569cf-a8c3-4bbd-ba47-d419e045f79c]

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

Remove the value2 key

➜ terraform apply --auto-approve
╷
│ Warning: Provider development overrides are in effect
│
│ The following provider development overrides are set in the CLI configuration:
│  - prefecthq/prefect in /Users/edwardpark/CODE/prefect/terraform-provider-prefect/build
│
│ 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.
╵
prefect_block.json: Refreshing state... [id=8cb569cf-a8c3-4bbd-ba47-d419e045f79c]

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.json will be updated in-place
  ~ resource "prefect_block" "json" {
      ~ data      = (sensitive value)
        id        = "8cb569cf-a8c3-4bbd-ba47-d419e045f79c"
        name      = "json"
      ~ updated   = "2024-06-14T19:32:23Z" -> (known after apply)
        # (2 unchanged attributes hidden)
    }

Plan: 0 to add, 1 to change, 0 to destroy.
prefect_block.json: Modifying... [id=8cb569cf-a8c3-4bbd-ba47-d419e045f79c]
prefect_block.json: Modifications complete after 1s [id=8cb569cf-a8c3-4bbd-ba47-d419e045f79c]

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