44 "context"
55
66 "github.com/elastic/terraform-provider-elasticstack/internal/clients/kibana_oapi"
7+ "github.com/hashicorp/terraform-plugin-framework/diag"
78 "github.com/hashicorp/terraform-plugin-framework/resource"
89 "github.com/hashicorp/terraform-plugin-framework/types"
910)
@@ -22,19 +23,28 @@ func (r *DefaultDataViewResource) Read(ctx context.Context, req resource.ReadReq
2223 return
2324 }
2425
25- spaceID := state .SpaceID .ValueString ()
26- defaultDataViewID , diags := kibana_oapi .GetDefaultDataView (ctx , client , spaceID )
26+ state , diags = r .read (ctx , client , state )
2727 resp .Diagnostics .Append (diags ... )
2828 if resp .Diagnostics .HasError () {
2929 return
3030 }
3131
32+ diags = resp .State .Set (ctx , state )
33+ resp .Diagnostics .Append (diags ... )
34+ }
35+
36+ func (r * DefaultDataViewResource ) read (ctx context.Context , client * kibana_oapi.Client , state defaultDataViewModel ) (defaultDataViewModel , diag.Diagnostics ) {
37+ spaceID := state .SpaceID .ValueString ()
38+ defaultDataViewID , diags := kibana_oapi .GetDefaultDataView (ctx , client , spaceID )
39+ if diags .HasError () {
40+ return state , diags
41+ }
42+
3243 // Update state with current default data view
3344 state .DataViewID = types .StringPointerValue (defaultDataViewID )
3445
3546 // Use the space_id as the resource ID
3647 state .ID = types .StringValue (spaceID )
3748
38- diags = resp .State .Set (ctx , state )
39- resp .Diagnostics .Append (diags ... )
49+ return state , nil
4050}
0 commit comments