@@ -81,9 +81,9 @@ func ResourceDatastreamPrivateConnection() *schema.Resource {
81
81
},
82
82
83
83
Timeouts : & schema.ResourceTimeout {
84
- Create : schema .DefaultTimeout (20 * time .Minute ),
85
- Update : schema .DefaultTimeout (20 * time .Minute ),
86
- Delete : schema .DefaultTimeout (20 * time .Minute ),
84
+ Create : schema .DefaultTimeout (30 * time .Minute ),
85
+ Update : schema .DefaultTimeout (30 * time .Minute ),
86
+ Delete : schema .DefaultTimeout (30 * time .Minute ),
87
87
},
88
88
89
89
SchemaVersion : 1 ,
@@ -119,9 +119,50 @@ func ResourceDatastreamPrivateConnection() *schema.Resource {
119
119
ForceNew : true ,
120
120
Description : `The private connectivity identifier.` ,
121
121
},
122
+ "create_without_validation" : {
123
+ Type : schema .TypeBool ,
124
+ Optional : true ,
125
+ ForceNew : true ,
126
+ Description : `If set to true, will skip validations.` ,
127
+ Default : false ,
128
+ },
129
+ "labels" : {
130
+ Type : schema .TypeMap ,
131
+ Optional : true ,
132
+ Description : `Labels.
133
+
134
+ **Note**: This field is non-authoritative, and will only manage the labels present in your configuration.
135
+ Please refer to the field 'effective_labels' for all of the labels present on the resource.` ,
136
+ Elem : & schema.Schema {Type : schema .TypeString },
137
+ },
138
+ "psc_interface_config" : {
139
+ Type : schema .TypeList ,
140
+ Optional : true ,
141
+ ForceNew : true ,
142
+ Description : `The PSC Interface configuration is used to create PSC Interface
143
+ between Datastream and the consumer's PSC.` ,
144
+ MaxItems : 1 ,
145
+ Elem : & schema.Resource {
146
+ Schema : map [string ]* schema.Schema {
147
+ "network_attachment" : {
148
+ Type : schema .TypeString ,
149
+ Required : true ,
150
+ ForceNew : true ,
151
+ Description : `Fully qualified name of the network attachment that Datastream will connect to.
152
+ Format: projects/{project}/regions/{region}/networkAttachments/{name}
153
+
154
+ To get Datastream project for the accepted list:
155
+ 'gcloud datastream private-connections create [PC ID] --location=[LOCATION] --network-attachment=[NA URI] --validate-only --display-name=[ANY STRING]'
156
+ Add Datastream project to the attachment accepted list:
157
+ 'gcloud compute network-attachments update [NA URI] --region=[NA region] --producer-accept-list=[TP from prev command]'` ,
158
+ },
159
+ },
160
+ },
161
+ ExactlyOneOf : []string {"vpc_peering_config" , "psc_interface_config" },
162
+ },
122
163
"vpc_peering_config" : {
123
164
Type : schema .TypeList ,
124
- Required : true ,
165
+ Optional : true ,
125
166
ForceNew : true ,
126
167
Description : `The VPC Peering configuration is used to create VPC peering
127
168
between Datastream and the consumer's VPC.` ,
@@ -143,22 +184,7 @@ Format: projects/{project}/global/{networks}/{name}`,
143
184
},
144
185
},
145
186
},
146
- },
147
- "create_without_validation" : {
148
- Type : schema .TypeBool ,
149
- Optional : true ,
150
- ForceNew : true ,
151
- Description : `If set to true, will skip validations.` ,
152
- Default : false ,
153
- },
154
- "labels" : {
155
- Type : schema .TypeMap ,
156
- Optional : true ,
157
- Description : `Labels.
158
-
159
- **Note**: This field is non-authoritative, and will only manage the labels present in your configuration.
160
- Please refer to the field 'effective_labels' for all of the labels present on the resource.` ,
161
- Elem : & schema.Schema {Type : schema .TypeString },
187
+ ExactlyOneOf : []string {"vpc_peering_config" , "psc_interface_config" },
162
188
},
163
189
"effective_labels" : {
164
190
Type : schema .TypeMap ,
@@ -235,6 +261,12 @@ func resourceDatastreamPrivateConnectionCreate(d *schema.ResourceData, meta inte
235
261
} else if v , ok := d .GetOkExists ("vpc_peering_config" ); ! tpgresource .IsEmptyValue (reflect .ValueOf (vpcPeeringConfigProp )) && (ok || ! reflect .DeepEqual (v , vpcPeeringConfigProp )) {
236
262
obj ["vpcPeeringConfig" ] = vpcPeeringConfigProp
237
263
}
264
+ pscInterfaceConfigProp , err := expandDatastreamPrivateConnectionPscInterfaceConfig (d .Get ("psc_interface_config" ), d , config )
265
+ if err != nil {
266
+ return err
267
+ } else if v , ok := d .GetOkExists ("psc_interface_config" ); ! tpgresource .IsEmptyValue (reflect .ValueOf (pscInterfaceConfigProp )) && (ok || ! reflect .DeepEqual (v , pscInterfaceConfigProp )) {
268
+ obj ["pscInterfaceConfig" ] = pscInterfaceConfigProp
269
+ }
238
270
labelsProp , err := expandDatastreamPrivateConnectionEffectiveLabels (d .Get ("effective_labels" ), d , config )
239
271
if err != nil {
240
272
return err
@@ -362,6 +394,9 @@ func resourceDatastreamPrivateConnectionRead(d *schema.ResourceData, meta interf
362
394
if err := d .Set ("vpc_peering_config" , flattenDatastreamPrivateConnectionVpcPeeringConfig (res ["vpcPeeringConfig" ], d , config )); err != nil {
363
395
return fmt .Errorf ("Error reading PrivateConnection: %s" , err )
364
396
}
397
+ if err := d .Set ("psc_interface_config" , flattenDatastreamPrivateConnectionPscInterfaceConfig (res ["pscInterfaceConfig" ], d , config )); err != nil {
398
+ return fmt .Errorf ("Error reading PrivateConnection: %s" , err )
399
+ }
365
400
if err := d .Set ("terraform_labels" , flattenDatastreamPrivateConnectionTerraformLabels (res ["labels" ], d , config )); err != nil {
366
401
return fmt .Errorf ("Error reading PrivateConnection: %s" , err )
367
402
}
@@ -535,6 +570,23 @@ func flattenDatastreamPrivateConnectionVpcPeeringConfigSubnet(v interface{}, d *
535
570
return v
536
571
}
537
572
573
+ func flattenDatastreamPrivateConnectionPscInterfaceConfig (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
574
+ if v == nil {
575
+ return nil
576
+ }
577
+ original := v .(map [string ]interface {})
578
+ if len (original ) == 0 {
579
+ return nil
580
+ }
581
+ transformed := make (map [string ]interface {})
582
+ transformed ["network_attachment" ] =
583
+ flattenDatastreamPrivateConnectionPscInterfaceConfigNetworkAttachment (original ["networkAttachment" ], d , config )
584
+ return []interface {}{transformed }
585
+ }
586
+ func flattenDatastreamPrivateConnectionPscInterfaceConfigNetworkAttachment (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
587
+ return v
588
+ }
589
+
538
590
func flattenDatastreamPrivateConnectionTerraformLabels (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
539
591
if v == nil {
540
592
return v
@@ -592,6 +644,29 @@ func expandDatastreamPrivateConnectionVpcPeeringConfigSubnet(v interface{}, d tp
592
644
return v , nil
593
645
}
594
646
647
+ func expandDatastreamPrivateConnectionPscInterfaceConfig (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
648
+ l := v .([]interface {})
649
+ if len (l ) == 0 || l [0 ] == nil {
650
+ return nil , nil
651
+ }
652
+ raw := l [0 ]
653
+ original := raw .(map [string ]interface {})
654
+ transformed := make (map [string ]interface {})
655
+
656
+ transformedNetworkAttachment , err := expandDatastreamPrivateConnectionPscInterfaceConfigNetworkAttachment (original ["network_attachment" ], d , config )
657
+ if err != nil {
658
+ return nil , err
659
+ } else if val := reflect .ValueOf (transformedNetworkAttachment ); val .IsValid () && ! tpgresource .IsEmptyValue (val ) {
660
+ transformed ["networkAttachment" ] = transformedNetworkAttachment
661
+ }
662
+
663
+ return transformed , nil
664
+ }
665
+
666
+ func expandDatastreamPrivateConnectionPscInterfaceConfigNetworkAttachment (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
667
+ return v , nil
668
+ }
669
+
595
670
func expandDatastreamPrivateConnectionEffectiveLabels (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (map [string ]string , error ) {
596
671
if v == nil {
597
672
return map [string ]string {}, nil
0 commit comments