@@ -9,19 +9,21 @@ import (
99)
1010
1111type GenerateGkeTfConfigurationArgs struct {
12- ExistingServiceAccount * ServiceAccount
13- ExistingSinkName string
14- IntegrationName string
15- Labels map [string ]string
16- LaceworkProfile string
17- OrganizationId string
18- OrganizationIntegration bool
19- Prefix string
20- ProjectId string
21- PubSubSubscriptionLabels map [string ]string
22- PubSubTopicLabels map [string ]string
23- ServiceAccountCredentials string
24- WaitTime string
12+ UseExistingRequiredProviders bool
13+ GcpProviderAlias string
14+ ExistingServiceAccount * ServiceAccount
15+ ExistingSinkName string
16+ IntegrationName string
17+ Labels map [string ]string
18+ LaceworkProfile string
19+ OrganizationId string
20+ OrganizationIntegration bool
21+ Prefix string
22+ ProjectId string
23+ PubSubSubscriptionLabels map [string ]string
24+ PubSubTopicLabels map [string ]string
25+ ServiceAccountCredentials string
26+ WaitTime string
2527}
2628
2729type Modifier func (c * GenerateGkeTfConfigurationArgs )
@@ -31,12 +33,17 @@ func (args *GenerateGkeTfConfigurationArgs) Generate() (string, error) {
3133 return "" , errors .Wrap (err , "invalid inputs" )
3234 }
3335
34- requiredProviders , err := createRequiredProviders ()
36+ requiredProviders , err := createRequiredProviders (args . UseExistingRequiredProviders )
3537 if err != nil {
3638 return "" , errors .Wrap (err , "failed to generate required providers" )
3739 }
3840
39- gcpProvider , err := createGcpProvider (args .ServiceAccountCredentials , args .ProjectId , []string {})
41+ gcpProvider , err := createGcpProvider (
42+ args .ServiceAccountCredentials ,
43+ args .ProjectId ,
44+ []string {},
45+ args .GcpProviderAlias ,
46+ )
4047 if err != nil {
4148 return "" , errors .Wrap (err , "failed to generate gcp provider" )
4249 }
@@ -93,6 +100,18 @@ func NewGkeTerraform(mods ...Modifier) *GenerateGkeTfConfigurationArgs {
93100 return config
94101}
95102
103+ func WithGkeExistingRequiredProviders () Modifier {
104+ return func (c * GenerateGkeTfConfigurationArgs ) {
105+ c .UseExistingRequiredProviders = true
106+ }
107+ }
108+
109+ func WithGkeGcpProviderAlias (alias string ) Modifier {
110+ return func (c * GenerateGkeTfConfigurationArgs ) {
111+ c .GcpProviderAlias = alias
112+ }
113+ }
114+
96115func WithGkeExistingServiceAccount (serviceAccount * ServiceAccount ) Modifier {
97116 return func (c * GenerateGkeTfConfigurationArgs ) {
98117 c .ExistingServiceAccount = serviceAccount
@@ -207,10 +226,23 @@ func createGKEAuditLog(args *GenerateGkeTfConfigurationArgs) (*hclwrite.Block, e
207226 attributes ["wait_time" ] = args .WaitTime
208227 }
209228
229+ moduleDetails := []lwgenerate.HclModuleModifier {
230+ lwgenerate .HclModuleWithAttributes (attributes ),
231+ lwgenerate .HclModuleWithVersion (lwgenerate .GcpGKEAuditLogVersion ),
232+ }
233+
234+ if args .GcpProviderAlias != "" {
235+ moduleDetails = append (
236+ moduleDetails ,
237+ lwgenerate .HclModuleWithProviderDetails (
238+ map [string ]string {"google" : fmt .Sprintf ("google.%s" , args .GcpProviderAlias )},
239+ ),
240+ )
241+ }
242+
210243 return lwgenerate .NewModule (
211244 fmt .Sprintf ("gcp_%s_level_gke_audit_log" , level ),
212245 lwgenerate .GcpGKEAuditLogSource ,
213- lwgenerate .HclModuleWithAttributes (attributes ),
214- lwgenerate .HclModuleWithVersion (lwgenerate .GcpGKEAuditLogVersion ),
246+ moduleDetails ... ,
215247 ).ToBlock ()
216248}
0 commit comments