hashicorp / hashicorp/terraform-plugin-framework
`path.PathStepElementKeyValue` with `Unknown` attribute cannot be used to get attribute from `Config`
- Dominant language
- Go
- Stars
- 384
- Forks
- 107
- Avg merge
- 3m
- Merged PRs (30d)
- 1
Description
### Module version
```
github.com/hashicorp/terraform-plugin-framework v1.14.1
github.com/hashicorp/terraform-plugin-go v0.26.0
```
### Relevant provider source code
Schema snippet
```go
"transition": schema.SetNestedBlock{
// TODO: one of `date` or `days``
CustomType: fwtypes.NewSetNestedObjectTypeOf[transitionModel](ctx),
NestedObject: schema.NestedBlockObject{
Attributes: map[string]schema.Attribute{
"date": schema.StringAttribute{
CustomType: timetypes.RFC3339Type{},
Optional: true,
},
"days": schema.Int32Attribute{
Optional: true,
Computed: true, // Because of Legacy value handling
PlanModifiers: []planmodifier.Int32{
ruleTransitionDaysForUnknown(),
int32planmodifier.UseStateForUnknown(),
},
Validators: []validator.Int32{
int32validator.AtLeast(0),
},
},
names.AttrStorageClass: schema.StringAttribute{
CustomType: fwtypes.StringEnumType[awstypes.TransitionStorageClass](),
Required: true,
},
},
},
},
```
```go
func (m ruleTransitionDaysForUnknownModifier) PlanModifyInt32(ctx context.Context, req planmodifier.Int32Request, resp *planmodifier.Int32Response) {
// Nothing to do if a value is configured
if !req.ConfigValue.IsNull() {
return
}
// Do nothing if there is a known planned value.
if !req.PlanValue.IsUnknown() {
return
}
// Do nothing if there is an unknown configuration value, otherwise interpolation gets messed up.
if req.ConfigValue.IsUnknown() {
return
}
var parentConfig transitionModel
parentPath := req.Path.ParentPath()
diags := req.Config.GetAttribute(ctx, parentPath, &parentConfig)
resp.Diagnostics.Append(diags...)
if diags.HasError() {
return
}
if parentConfig.Date.IsNull() {
resp.PlanValue = types.Int32Value(0)
} else {
resp.PlanValue = types.Int32Null()
}
}
```
### Debug Output
### Expected Behavior
`req.Config.GetAttribute(ctx, parentPath, &parentConfig)` should succeed
### Actual Behavior
Returns the following error
Error: Value Conversion Error
with aws_s3_bucket_lifecycle_configuration.test,
on terraform_plugin_test.tf line 35, in resource "aws_s3_bucket_lifecycle_configuration" "test":
35: transition {
An unexpected error was encountered trying to build a value. This is always
an error in the provider. Please report the following to the provider
developer:
Received null value, however the target type cannot handle null values. Use
the corresponding `types` package type, a pointer type or a custom type that
handles null values.
Path:
rule[0].transition[Value({"date":"2025-04-27T00:00:00Z","days":,"storage_class":"STANDARD_IA"})]
Target Type: s3.transitionModel
Suggested `types` Type: basetypes.ObjectValue
Suggested Pointer Type: *s3.transitionModel
During the plan modification, `days` is `Unknown` in the `Plan` and `PathStepElementKeyValue`, but `Null` in `Config`. Thus, `req.Path` cannot be used to walk the path.
Contributor guide
Assessment
This issue has not been assessed yet.