@@ -2,10 +2,12 @@ package provider
22
33import (
44 "context"
5+ "fmt"
56
67 "github.com/hashicorp/terraform-plugin-go/tfprotov5"
78 "github.com/hashicorp/terraform-plugin-go/tftypes"
89 "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
10+ "k8s.io/apimachinery/pkg/runtime/schema"
911)
1012
1113func (s * RawProviderServer ) GetResourceIdentitySchemas (ctx context.Context , req * tfprotov5.GetResourceIdentitySchemasRequest ) (* tfprotov5.GetResourceIdentitySchemasResponse , error ) {
@@ -18,7 +20,7 @@ func (s *RawProviderServer) GetResourceIdentitySchemas(ctx context.Context, req
1820 {Name : "api_version" , RequiredForImport : true , Type : tftypes .String },
1921 {Name : "kind" , RequiredForImport : true , Type : tftypes .String },
2022 {Name : "name" , RequiredForImport : true , Type : tftypes .String },
21- {Name : "namespace" , RequiredForImport : true , Type : tftypes .String },
23+ {Name : "namespace" , OptionalForImport : true , Type : tftypes .String },
2224 },
2325 },
2426 },
@@ -32,6 +34,28 @@ func (s *RawProviderServer) UpgradeResourceIdentity(ctx context.Context, req *tf
3234 return resp , nil
3335}
3436
37+ func parseResourceIdentityData (rid * tfprotov5.ResourceIdentityData ) (schema.GroupVersionKind , string , string , error ) {
38+ namespace := "default"
39+ var apiVersion , kind , name string
40+
41+ iddata , err := rid .IdentityData .Unmarshal (getIdentityType ())
42+ if err != nil {
43+ return schema.GroupVersionKind {}, "" , "" ,
44+ fmt .Errorf ("could not unmarshal identity data: %v" , err .Error ())
45+ }
46+
47+ var idvals map [string ]tftypes.Value
48+ iddata .As (& idvals )
49+
50+ idvals ["api_version" ].As (& apiVersion )
51+ idvals ["kind" ].As (& kind )
52+ idvals ["namespace" ].As (& namespace )
53+ idvals ["name" ].As (& name )
54+
55+ gvk := schema .FromAPIVersionAndKind (apiVersion , kind )
56+ return gvk , name , namespace , nil
57+ }
58+
3559func getIdentityType () tftypes.Type {
3660 return tftypes.Object {
3761 AttributeTypes : map [string ]tftypes.Type {
0 commit comments