Skip to content

Commit

Permalink
generate terraform type before making API call
Browse files Browse the repository at this point in the history
  • Loading branch information
jrhouston committed Feb 1, 2022
1 parent 885967d commit 95cba7e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
20 changes: 10 additions & 10 deletions manifest/provider/datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,16 @@ func (s *RawProviderServer) ReadDataSource(ctx context.Context, req *tfprotov5.R
}
rcl := client.Resource(gvr)

objectType, err := s.TFTypeFromOpenAPI(ctx, gvk, false)
if err != nil {
resp.Diagnostics = append(resp.Diagnostics, &tfprotov5.Diagnostic{
Severity: tfprotov5.DiagnosticSeverityError,
Summary: "Failed to save resource state",
Detail: err.Error(),
})
return resp, nil
}

var metadataBlock []tftypes.Value
dsConfig["metadata"].As(&metadataBlock)

Expand Down Expand Up @@ -138,16 +148,6 @@ func (s *RawProviderServer) ReadDataSource(ctx context.Context, req *tfprotov5.R
return resp, nil
}

objectType, err := s.TFTypeFromOpenAPI(ctx, gvk, false)
if err != nil {
resp.Diagnostics = append(resp.Diagnostics, &tfprotov5.Diagnostic{
Severity: tfprotov5.DiagnosticSeverityError,
Summary: "Failed to save resource state",
Detail: err.Error(),
})
return resp, nil
}

fo := RemoveServerSideFields(res.Object)
nobj, err := payload.ToTFValue(fo, objectType, tftypes.NewAttributePath())
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion manifest/test/acceptance/datasource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func TestDataSourceKubernetesResource_ConfigMap(t *testing.T) {

tfstate := tfstatehelper.NewHelper(step2.RequireState(t))

// check the data source
// check the data source
tfstate.AssertAttributeValues(t, tfstatehelper.AttributeValues{
"data.kubernetes_resource.test_config.object.data.TEST": "hello world",
})
Expand Down

0 comments on commit 95cba7e

Please sign in to comment.