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

Dynamic write-only attribute can't be assigned by ephemeral values internally #36518

Closed
magodo opened this issue Feb 15, 2025 · 0 comments · Fixed by #36520
Closed

Dynamic write-only attribute can't be assigned by ephemeral values internally #36518

magodo opened this issue Feb 15, 2025 · 0 comments · Fixed by #36520
Assignees

Comments

@magodo
Copy link
Contributor

magodo commented Feb 15, 2025

Terraform Version

v1.12.0-dev (8865218ccb584267a558b4d0c6f0c14a2d1aefd0)

Terraform Configuration Files

terraform {
  required_providers {
    restful = {
      source = "magodo/restful"
    }
  }
}

provider "restful" {
  base_url = "http://local:3000"
}

ephemeral "restful_resource" "test" {
  path = "/ephemerals"
  method = "POST"

  renew_path = "/ephemerals/$(body.id)"
  renew_method = "PATCH"
  renew_body = {
      renew = 1
  }

  expiry_type = "duration"
  expiry_locator = "exact.1s"

  close_path = "/ephemerals/$(body.id)"
  close_method = "DELETE"
}

resource "restful_resource" "test" {
  path = "/resources"
  read_path = "/resources/$(body.id)"
  body = {
      foo = "bar"
  }
  ephemeral_body = {
    secret = ephemeral.restful_resource.test.output.id
  }
}

Debug Output

╷
│ Error: Invalid use of ephemeral value
│
│   with restful_resource.test,
│   on main.tf line 30, in resource "restful_resource" "test":
│   30: resource "restful_resource" "test" {
│
│ Ephemeral values are not valid for "ephemeral_body.secret", because it is not an assignable
│ attribute.
╵

Expected Behavior

Terraform should accept this config as ephemeral_body is marked as WriteOnly: true, albeit it is of dynamic type.

Actual Behavior

terraform validate failed with error:

╷
│ Error: Invalid use of ephemeral value
│
│   with restful_resource.test,
│   on main.tf line 30, in resource "restful_resource" "test":
│   30: resource "restful_resource" "test" {
│
│ Ephemeral values are not valid for "ephemeral_body.secret", because it is not an assignable
│ attribute.
╵

Steps to Reproduce

  1. Checkout and build the magodo/terraform-provider-restful at branch: https://github.com/magodo/terraform-provider-restful/tree/ephemeral_body
  2. Instruct terraform to use the locally built provider via modifying the .terraformrc
  3. terraform validate with the config above

Additional Context

Since the write-only attribute support PR is merged in FW recently, I'm trying to support that in my restful provider.

The provider offers a general resource restful_resource, whose body is defined as a dynamic value. For the same reason, I've introduced a new optional attribute ephemeral_body which has the WriteOnly: true, and is also a dynamic value. I expect as long the ephemeral_body is marked as write-only, then it can reference a ephemeral value.

However, it turns out I can only directly assign an ephemeral value to ephemeral_body, but can't assign it to a nested field. I find the error is raised from Terraform, therefore submitting the issue here.

References

No response

Generative AI / LLM assisted development?

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants