@@ -13,6 +13,7 @@ import (
13
13
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
14
14
"github.com/hashicorp/terraform-plugin-framework/attr"
15
15
"github.com/hashicorp/terraform-plugin-framework/diag"
16
+ "github.com/hashicorp/terraform-plugin-framework/path"
16
17
"github.com/hashicorp/terraform-plugin-framework/resource"
17
18
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
18
19
"github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault"
@@ -29,9 +30,10 @@ import (
29
30
)
30
31
31
32
var (
32
- _ resource.Resource = & ClickPipeResource {}
33
- _ resource.ResourceWithModifyPlan = & ClickPipeResource {}
34
- _ resource.ResourceWithConfigure = & ClickPipeResource {}
33
+ _ resource.Resource = & ClickPipeResource {}
34
+ _ resource.ResourceWithModifyPlan = & ClickPipeResource {}
35
+ _ resource.ResourceWithConfigure = & ClickPipeResource {}
36
+ _ resource.ResourceWithImportState = & ClickPipeResource {}
35
37
)
36
38
37
39
const clickPipeResourceDescription = `
@@ -884,15 +886,19 @@ func (c *ClickPipeResource) syncClickPipeState(ctx context.Context, state *model
884
886
}
885
887
886
888
stateSourceModel := models.ClickPipeSourceModel {}
887
- if diags := state .Source .As (ctx , & stateSourceModel , basetypes.ObjectAsOptions {}); diags .HasError () {
888
- return fmt .Errorf ("error reading ClickPipe source: %v" , diags )
889
+ if ! state .Source .IsNull () {
890
+ if diags := state .Source .As (ctx , & stateSourceModel , basetypes.ObjectAsOptions {}); diags .HasError () {
891
+ return fmt .Errorf ("error reading ClickPipe source: %v" , diags )
892
+ }
889
893
}
890
894
891
895
sourceModel := models.ClickPipeSourceModel {}
892
896
if clickPipe .Source .Kafka != nil {
893
897
stateKafkaModel := models.ClickPipeKafkaSourceModel {}
894
- if diags := stateSourceModel .Kafka .As (ctx , & stateKafkaModel , basetypes.ObjectAsOptions {}); diags .HasError () {
895
- return fmt .Errorf ("error reading ClickPipe Kafka source: %v" , diags )
898
+ if ! stateSourceModel .Kafka .IsNull () {
899
+ if diags := stateSourceModel .Kafka .As (ctx , & stateKafkaModel , basetypes.ObjectAsOptions {}); diags .HasError () {
900
+ return fmt .Errorf ("error reading ClickPipe Kafka source: %v" , diags )
901
+ }
896
902
}
897
903
898
904
var consumerGroup string
@@ -923,8 +929,10 @@ func (c *ClickPipeResource) syncClickPipeState(ctx context.Context, state *model
923
929
924
930
if clickPipe .Source .Kafka .SchemaRegistry != nil {
925
931
var stateSchemaRegistryModel models.ClickPipeKafkaSchemaRegistryModel
926
- if diags := stateKafkaModel .SchemaRegistry .As (ctx , & stateSchemaRegistryModel , basetypes.ObjectAsOptions {}); diags .HasError () {
927
- return fmt .Errorf ("error reading ClickPipe Kafka source schema registry: %v" , diags )
932
+ if ! stateKafkaModel .SchemaRegistry .IsNull () {
933
+ if diags := stateKafkaModel .SchemaRegistry .As (ctx , & stateSchemaRegistryModel , basetypes.ObjectAsOptions {}); diags .HasError () {
934
+ return fmt .Errorf ("error reading ClickPipe Kafka source schema registry: %v" , diags )
935
+ }
928
936
}
929
937
930
938
schemaRegistryModel := models.ClickPipeKafkaSchemaRegistryModel {
@@ -966,8 +974,11 @@ func (c *ClickPipeResource) syncClickPipeState(ctx context.Context, state *model
966
974
967
975
if clickPipe .Source .ObjectStorage != nil {
968
976
stateObjectStorageModel := models.ClickPipeObjectStorageSourceModel {}
969
- if diags := stateSourceModel .ObjectStorage .As (ctx , & stateObjectStorageModel , basetypes.ObjectAsOptions {}); diags .HasError () {
970
- return fmt .Errorf ("error reading ClickPipe object storage source: %v" , diags )
977
+
978
+ if ! stateSourceModel .ObjectStorage .IsNull () {
979
+ if diags := stateSourceModel .ObjectStorage .As (ctx , & stateObjectStorageModel , basetypes.ObjectAsOptions {}); diags .HasError () {
980
+ return fmt .Errorf ("error reading ClickPipe object storage source: %v" , diags )
981
+ }
971
982
}
972
983
973
984
objectStorageModel := models.ClickPipeObjectStorageSourceModel {
@@ -1009,12 +1020,19 @@ func (c *ClickPipeResource) syncClickPipeState(ctx context.Context, state *model
1009
1020
}
1010
1021
1011
1022
stateDestinationModel := models.ClickPipeDestinationModel {}
1012
- if diags := state .Destination .As (ctx , & stateDestinationModel , basetypes.ObjectAsOptions {}); diags .HasError () {
1013
- return fmt .Errorf ("error reading ClickPipe destination: %v" , diags )
1023
+
1024
+ if ! state .Destination .IsNull () {
1025
+ if diags := state .Destination .As (ctx , & stateDestinationModel , basetypes.ObjectAsOptions {}); diags .HasError () {
1026
+ return fmt .Errorf ("error reading ClickPipe destination: %v" , diags )
1027
+ }
1014
1028
}
1015
1029
1016
1030
// Destination roles are not persisted on ClickPipes side. Used only during pipe creation.
1017
- destinationModel .Roles = stateDestinationModel .Roles
1031
+ if ! stateDestinationModel .Roles .IsNull () {
1032
+ destinationModel .Roles = stateDestinationModel .Roles
1033
+ } else {
1034
+ destinationModel .Roles = types .ListNull (types .StringType )
1035
+ }
1018
1036
1019
1037
columnList := make ([]attr.Value , len (clickPipe .Destination .Columns ))
1020
1038
for i , column := range clickPipe .Destination .Columns {
@@ -1259,3 +1277,32 @@ func (c *ClickPipeResource) Delete(ctx context.Context, request resource.DeleteR
1259
1277
)
1260
1278
}
1261
1279
}
1280
+
1281
+ // ImportState imports a ClickPipe reverse private endpoint into the state.
1282
+ // We don't have access to configuration/plan, so service id is required
1283
+ // to be provided as a part of the import id.
1284
+ func (r * ClickPipeResource ) ImportState (ctx context.Context , req resource.ImportStateRequest , resp * resource.ImportStateResponse ) {
1285
+ idParts := strings .Split (req .ID , ":" )
1286
+
1287
+ if len (idParts ) != 2 {
1288
+ resp .Diagnostics .AddError (
1289
+ "Invalid Import ID" ,
1290
+ fmt .Sprintf ("Expected import identifier with format: service_id:id. Got: %q" , req .ID ),
1291
+ )
1292
+ return
1293
+ }
1294
+
1295
+ id := idParts [0 ]
1296
+ endpointID := idParts [1 ]
1297
+
1298
+ resp .Diagnostics .Append (resp .State .SetAttribute (ctx , path .Root ("service_id" ), id )... )
1299
+ resp .Diagnostics .Append (resp .State .SetAttribute (ctx , path .Root ("id" ), endpointID )... )
1300
+
1301
+ resp .Diagnostics .AddWarning (
1302
+ "Credentials state diverge" ,
1303
+ "Importing a ClickPipe will not persist credentials into your state.\n " +
1304
+ "Sensitive values are only stored in your state and provider is not able to import them.\n " +
1305
+ "Run a `terraform apply` to ensure sensitive values state is up to date with a ClickPipe.\n " +
1306
+ "Important: your configuration (in *.tf files) has to provide valid credentials." ,
1307
+ )
1308
+ }
0 commit comments