Skip to content

Commit

Permalink
Block "data" argument: Clarify expected data format (#257)
Browse files Browse the repository at this point in the history
* Block "data" argument: Clarify expected data format

Clarifies the expected data format for the "data" argument in the Block
resource.

The specific type is `schema.stringAttribute`, but we also set a
CustomType of `jsontypes.NormalizedType`, which is an RFC 7159 JSON
string.

The Terraform Documentation tooling does not consider the CustomType
field, so in the generated markdown it only say `String, Sensitive`.
This can be confusing for users who expect to just pass any string here.

So this change:
- Clarifies the format expectations in the `data` argument description
- Updates the examples to ensure we use `jsonencode` consistently

Related to #255

* Fix Marvin account email
  • Loading branch information
mitchnielsen authored Sep 20, 2024
1 parent d6cafda commit f1ab693
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions docs/resources/block.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ resource "prefect_block" "aws_credentials_from_file" {
type_slug = "aws-credentials"
# prefect block type inspect aws-credentials
data = file("./aws-credentials.json")
data = jsonencode(file("./aws-credentials.json"))
}
# example:
Expand Down Expand Up @@ -111,7 +111,7 @@ For more information on the `$ref` syntax definition, see the

### Required

- `data` (String, Sensitive) The user-inputted Block payload, as a JSON string. The value's schema will depend on the selected `type` slug. Use `prefect block type inspect <slug>` to view the data schema for a given Block type.
- `data` (String, Sensitive) The user-inputted Block payload, as a JSON string. Use `jsonencode` on the provided value to satisfy the underlying JSON type. The value's schema will depend on the selected `type` slug. Use `prefect block type inspect <slug>` to view the data schema for a given Block type.
- `name` (String) Unique name of the Block
- `type_slug` (String) Block Type slug, which determines the schema of the `data` JSON attribute. Use `prefect block type ls` to view all available Block type slugs.

Expand Down
2 changes: 1 addition & 1 deletion examples/resources/prefect_block/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ resource "prefect_block" "aws_credentials_from_file" {
type_slug = "aws-credentials"

# prefect block type inspect aws-credentials
data = file("./aws-credentials.json")
data = jsonencode(file("./aws-credentials.json"))
}

# example:
Expand Down
4 changes: 2 additions & 2 deletions internal/provider/datasources/account_member_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ func TestAccDatasource_account_member(t *testing.T) {
PreCheck: func() { testutils.AccTestPreCheck(t) },
Steps: []resource.TestStep{
{
Config: fixtureAccAccountMember("marvin+tf-acceptance-tester@prefect.io"),
Config: fixtureAccAccountMember("[email protected]"),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(dataSourceName, "email", "marvin+tf-acceptance-tester@prefect.io"),
resource.TestCheckResourceAttr(dataSourceName, "email", "[email protected]"),
resource.TestCheckResourceAttrSet(dataSourceName, "id"),
resource.TestCheckResourceAttrSet(dataSourceName, "account_role_id"),
resource.TestCheckResourceAttrSet(dataSourceName, "account_role_name"),
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/resources/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (r *BlockResource) Schema(_ context.Context, _ resource.SchemaRequest, resp
Required: true,
Sensitive: true,
CustomType: jsontypes.NormalizedType{},
Description: "The user-inputted Block payload, as a JSON string. The value's schema will depend on the selected `type` slug. Use `prefect block type inspect <slug>` to view the data schema for a given Block type.",
Description: "The user-inputted Block payload, as a JSON string. Use `jsonencode` on the provided value to satisfy the underlying JSON type. The value's schema will depend on the selected `type` slug. Use `prefect block type inspect <slug>` to view the data schema for a given Block type.",
},
"account_id": schema.StringAttribute{
Optional: true,
Expand Down

0 comments on commit f1ab693

Please sign in to comment.