-
Notifications
You must be signed in to change notification settings - Fork 91
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
ListAttribute does not allows in Blocks? #885
Comments
Hey there @duytiennguyen-okta 👋🏻! It's definitely valid to put a
I didn't see in your example the setting of the value, but here is a full example that gives you an idea of what I mean (I'm using the package provider
import (
"context"
"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/types"
)
var _ datasource.DataSource = (*thingDataSource)(nil)
func NewThingDataSource() datasource.DataSource {
return &thingDataSource{}
}
type thingDataSource struct{}
type thingDataSourceModel struct {
BlockObj types.Object `tfsdk:"block_obj"` // BlockObject
}
type BlockObject struct {
NestedList types.List `tfsdk:"nested_list"`
}
func (d *thingDataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_thing"
}
func (d *thingDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
Blocks: map[string]schema.Block{
"block_obj": schema.SingleNestedBlock{
Attributes: map[string]schema.Attribute{
"nested_list": schema.ListAttribute{
Computed: true,
ElementType: types.StringType,
},
},
},
},
}
}
func (d *thingDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
var data thingDataSourceModel
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)
if resp.Diagnostics.HasError() {
return
}
data.BlockObj = types.ObjectValueMust(map[string]attr.Type{
"nested_list": types.ListType{
// This needs to be set, otherwise you might see a "MISSING TYPE" in your diagnostic
ElemType: types.StringType,
},
}, map[string]attr.Value{
"nested_list": types.ListValueMust(types.StringType, []attr.Value{types.StringValue("hey")}),
})
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
} data "examplecloud_thing" "this" {}
output "d" {
value = data.examplecloud_thing.this.block_obj.nested_list
} $ terraform plan
data.examplecloud_thing.this: Reading...
data.examplecloud_thing.this: Read complete after 8s
Changes to Outputs:
+ d = [
+ "hey",
]
You can apply this plan to save these new output values to the Terraform state, without changing any real infrastructure. Let me know if this helps! |
Hi @duytiennguyen-okta 👋 Since we have not heard back from you in awhile, I'm going to close this issue. There is a time period before this issue will be automatically locked so please let us know about the above if you get a chance and we can reopen/revisit. |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. |
Module version
Relevant provider source code
Terraform Configuration Files
This issue is not related to terraform, only the terraform plugin framework
...
Debug Output
Expected Behavior
There should not be an error when running
Actual Behavior
I received the following error
Steps to Reproduce
References
Note
I should note that I do not have issue when I was using ListAttribute inside Attributes instead of Blocks
I just want to know if this behaviour is expected or because I am using it wrong
The text was updated successfully, but these errors were encountered: