@@ -23,6 +23,7 @@ package provider
2323import (
2424 "context"
2525 "fmt"
26+
2627 "github.com/hashicorp/terraform-plugin-sdk/v2/diag"
2728 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
2829
@@ -47,6 +48,10 @@ const (
4748 privateEndpointAWSPrincipalAccountIdFieldName = "account_id"
4849 privateEndpointAWSPrincipalUserNamesFieldName = "user_names"
4950 privateEndpointAWSPrincipalRoleNamesFieldName = "role_names"
51+
52+ // GCP field names
53+ privateEndpointGCPFieldName = "gcp"
54+ privateEndpointGCPProjectsFieldName = "projects"
5055)
5156
5257// resourcePrivateEndpoint defines a Private Endpoint Oasis resource.
@@ -143,6 +148,26 @@ func resourcePrivateEndpoint() *schema.Resource {
143148 },
144149 },
145150 },
151+ privateEndpointGCPFieldName : {
152+ Type : schema .TypeList ,
153+ Description : "Private Endpoint Resource Private Endpoint GCP field" ,
154+ Optional : true ,
155+ MaxItems : 1 ,
156+ DiffSuppressFunc : func (k , old , new string , d * schema.ResourceData ) bool {
157+ return old == "1" && new == "0"
158+ },
159+ Elem : & schema.Resource {
160+ Schema : map [string ]* schema.Schema {
161+ privateEndpointGCPProjectsFieldName : {
162+ Type : schema .TypeList ,
163+ Description : "Private Endpoint Resource Private Endpoint GCP Projects field (list of project ids)" ,
164+ Required : true ,
165+ MaxItems : 1 ,
166+ Elem : & schema.Schema {Type : schema .TypeString },
167+ },
168+ },
169+ },
170+ },
146171 },
147172 }
148173}
@@ -181,6 +206,7 @@ func flattenPrivateEndpointResource(privateEndpoint *network.PrivateEndpointServ
181206 privateEndpointDNSNamesFieldName : privateEndpoint .GetAlternateDnsNames (),
182207 privateEndpointAKSFieldName : flattenAKSResource (privateEndpoint .GetAks ()),
183208 privateEndpointAWSFieldName : flattenAWSResource (privateEndpoint .GetAws ()),
209+ privateEndpointGCPFieldName : flattenGCPResource (privateEndpoint .GetGcp ()),
184210 }
185211}
186212
@@ -202,6 +228,15 @@ func flattenAWSResource(privateEndpointAWS *network.PrivateEndpointService_Aws)
202228 }
203229}
204230
231+ // flattenGCPResource will take an GCP Resource part of a Private Endpoint and create a sub map for terraform schema.
232+ func flattenGCPResource (privateEndpointGCP * network.PrivateEndpointService_Gcp ) []interface {} {
233+ return []interface {}{
234+ map [string ]interface {}{
235+ privateEndpointGCPProjectsFieldName : privateEndpointGCP .GetProjects (),
236+ },
237+ }
238+ }
239+
205240// flattenAWSPrincipals will take an AWS Principal Resource part of a Private Endpoint and create a sub map for terraform schema.
206241func flattenAWSPrincipals (privateEndpointAWSPrincipals []* network.PrivateEndpointService_AwsPrincipals ) []interface {} {
207242 var principals = make (map [string ]interface {})
@@ -281,11 +316,11 @@ func expandPrivateEndpointResource(d *schema.ResourceData) (*network.PrivateEndp
281316 ret .AlternateDnsNames = dnsNames
282317 }
283318 if v , ok := d .GetOk (privateEndpointAKSFieldName ); ok {
284- subscriptionIds , err := expandAKSResource (v .([]interface {}))
319+ aksResource , err := expandAKSResource (v .([]interface {}))
285320 if err != nil {
286321 return nil , err
287322 }
288- ret .Aks = subscriptionIds
323+ ret .Aks = aksResource
289324 }
290325 if v , ok := d .GetOk (privateEndpointAWSFieldName ); ok {
291326 awsResource , err := expandAWSResource (v .([]interface {}))
@@ -294,6 +329,13 @@ func expandPrivateEndpointResource(d *schema.ResourceData) (*network.PrivateEndp
294329 }
295330 ret .Aws = awsResource
296331 }
332+ if v , ok := d .GetOk (privateEndpointGCPFieldName ); ok {
333+ gcpResource , err := expandGCPResource (v .([]interface {}))
334+ if err != nil {
335+ return nil , err
336+ }
337+ ret .Gcp = gcpResource
338+ }
297339 return ret , nil
298340}
299341
@@ -365,6 +407,26 @@ func expandAWSPrincipal(s []interface{}) ([]*network.PrivateEndpointService_AwsP
365407 return principals , nil
366408}
367409
410+ // expandGCPResource gathers GCP Resource data from the terraform store
411+ func expandGCPResource (s []interface {}) (gcpResource * network.PrivateEndpointService_Gcp , err error ) {
412+ for _ , v := range s {
413+ item := v .(map [string ]interface {})
414+ if projects , ok := item [privateEndpointGCPProjectsFieldName ]; ok {
415+ projects , ok := projects .([]interface {})
416+ if ! ok {
417+ return nil , fmt .Errorf ("failed to parse field %s" , privateEndpointGCPProjectsFieldName )
418+ }
419+ if gcpResource == nil {
420+ gcpResource = & network.PrivateEndpointService_Gcp {}
421+ }
422+ for _ , addr := range projects {
423+ gcpResource .Projects = append (gcpResource .Projects , addr .(string ))
424+ }
425+ }
426+ }
427+ return
428+ }
429+
368430// resourcePrivateEndpointDelete will delete the Terraform PrivateEndpoint resource
369431func resourcePrivateEndpointDelete (ctx context.Context , d * schema.ResourceData , m interface {}) diag.Diagnostics {
370432 d .SetId ("" )
@@ -414,6 +476,13 @@ func resourcePrivateEndpointUpdate(ctx context.Context, d *schema.ResourceData,
414476 }
415477 privateEndpoint .Aws = awsResource
416478 }
479+ if d .HasChange (privateEndpointGCPFieldName ) {
480+ gcpResource , err := expandGCPResource (d .Get (privateEndpointGCPFieldName ).([]interface {}))
481+ if err != nil {
482+ diag .FromErr (err )
483+ }
484+ privateEndpoint .Gcp = gcpResource
485+ }
417486
418487 _ , err = nwc .UpdatePrivateEndpointService (client .ctxWithToken , privateEndpoint )
419488 if err != nil {
0 commit comments