From 328709ce39333c1f3244653eb3a16d2efddaf55b Mon Sep 17 00:00:00 2001 From: ipcrm Date: Thu, 30 May 2024 20:36:15 +0000 Subject: [PATCH] fix(GROW-2819): split azuread/azurerm gen args --- lwgenerate/azure/azure.go | 25 +++++++---- lwgenerate/azure/azure_test.go | 13 +++++- ...ty_log_with_config_azureadprovider_args.tf | 41 +++++++++++++++++++ .../activity_log_with_config_provider_args.tf | 1 - 4 files changed, 70 insertions(+), 10 deletions(-) create mode 100644 lwgenerate/azure/test-data/activity_log_with_config_azureadprovider_args.tf diff --git a/lwgenerate/azure/azure.go b/lwgenerate/azure/azure.go index 0f0ae61be..4cb1d23c5 100644 --- a/lwgenerate/azure/azure.go +++ b/lwgenerate/azure/azure.go @@ -64,8 +64,11 @@ type GenerateAzureTfConfigurationArgs struct { // Add custom blocks to the root `terraform{}` block. Can be used for advanced configuration. Things like backend, etc ExtraBlocksRootTerraform []*hclwrite.Block - // ExtraProviderArguments allows adding more arguments to the provider block as needed (custom use cases) - ExtraProviderArguments map[string]interface{} + // ExtraAZRMArguments allows adding more arguments to the provider block as needed (custom use cases) + ExtraAZRMArguments map[string]interface{} + + // ExtraAZReadArguments allows adding more arguments to the provider block as needed (custom use cases) + ExtraAZReadArguments map[string]interface{} // ExtraBlocks allows adding more hclwrite.Block to the root terraform document (advanced use cases) ExtraBlocks []*hclwrite.Block @@ -142,11 +145,19 @@ func WithExtraRootBlocks(blocks []*hclwrite.Block) AzureTerraformModifier { } } -// WithExtraProviderArguments enables adding additional arguments into the `aws` provider block +// WithExtraAZRMArguments enables adding additional arguments into the `azurerm` provider block +// this enables custom use cases +func WithExtraAZRMArguments(arguments map[string]interface{}) AzureTerraformModifier { + return func(c *GenerateAzureTfConfigurationArgs) { + c.ExtraAZRMArguments = arguments + } +} + +// WithExtraAZReadArguments enables adding additional arguments into the `azuread` provider block // this enables custom use cases -func WithExtraProviderArguments(arguments map[string]interface{}) AzureTerraformModifier { +func WithExtraAZReadArguments(arguments map[string]interface{}) AzureTerraformModifier { return func(c *GenerateAzureTfConfigurationArgs) { - c.ExtraProviderArguments = arguments + c.ExtraAZReadArguments = arguments } } @@ -349,7 +360,7 @@ func createAzureADProvider(args *GenerateAzureTfConfigurationArgs) ([]*hclwrite. attrs := map[string]interface{}{} // set custom args before the required ones below to ensure expected behavior (i.e., no overrides) - for k, v := range args.ExtraProviderArguments { + for k, v := range args.ExtraAZReadArguments { attrs[k] = v } @@ -379,7 +390,7 @@ func createAzureRMProvider(args *GenerateAzureTfConfigurationArgs) ([]*hclwrite. featureAttrs := map[string]interface{}{} // set custom args before the required ones below to ensure expected behavior (i.e., no overrides) - for k, v := range args.ExtraProviderArguments { + for k, v := range args.ExtraAZRMArguments { attrs[k] = v } diff --git a/lwgenerate/azure/azure_test.go b/lwgenerate/azure/azure_test.go index 7e84dcf70..ae153ace0 100644 --- a/lwgenerate/azure/azure_test.go +++ b/lwgenerate/azure/azure_test.go @@ -49,10 +49,19 @@ func TestGenerationActivityLogWithConfigAndExtraBlocks(t *testing.T) { assert.Equal(t, ActivityLogWithConfig, hcl) } -func TestGenerationActivityLogWithConfigAndExtraProviderBlocks(t *testing.T) { +func TestGenerationActivityLogWithConfigAndExtraAzureRMProviderBlocks(t *testing.T) { var ActivityLogWithConfig, fileErr = getFileContent("test-data/activity_log_with_config_provider_args.tf") assert.Nil(t, fileErr) - hcl, err := azure.NewTerraform(true, true, true, azure.WithExtraProviderArguments(map[string]interface{}{"foo": "bar"})).Generate() + hcl, err := azure.NewTerraform(true, true, true, azure.WithExtraAZRMArguments(map[string]interface{}{"foo": "bar"})).Generate() + assert.Nil(t, err) + assert.NotNil(t, hcl) + assert.Equal(t, ActivityLogWithConfig, hcl) +} + +func TestGenerationActivityLogWithConfigAndExtraAZUReadProviderBlocks(t *testing.T) { + var ActivityLogWithConfig, fileErr = getFileContent("test-data/activity_log_with_config_azureadprovider_args.tf") + assert.Nil(t, fileErr) + hcl, err := azure.NewTerraform(true, true, true, azure.WithExtraAZReadArguments(map[string]interface{}{"foo": "bar"})).Generate() assert.Nil(t, err) assert.NotNil(t, hcl) assert.Equal(t, ActivityLogWithConfig, hcl) diff --git a/lwgenerate/azure/test-data/activity_log_with_config_azureadprovider_args.tf b/lwgenerate/azure/test-data/activity_log_with_config_azureadprovider_args.tf new file mode 100644 index 000000000..5946ac6a5 --- /dev/null +++ b/lwgenerate/azure/test-data/activity_log_with_config_azureadprovider_args.tf @@ -0,0 +1,41 @@ +terraform { + required_providers { + lacework = { + source = "lacework/lacework" + version = "~> 1.0" + } + } +} + +provider "azuread" { + foo = "bar" +} + +provider "azurerm" { + features { + } +} + +module "az_ad_application" { + source = "lacework/ad-application/azure" + version = "~> 1.0" +} + +module "az_config" { + source = "lacework/config/azure" + version = "~> 2.0" + application_id = module.az_ad_application.application_id + application_password = module.az_ad_application.application_password + service_principal_id = module.az_ad_application.service_principal_id + use_existing_ad_application = true +} + +module "az_activity_log" { + source = "lacework/activity-log/azure" + version = "~> 2.0" + application_id = module.az_ad_application.application_id + application_password = module.az_ad_application.application_password + infrastructure_encryption_enabled = true + service_principal_id = module.az_ad_application.service_principal_id + use_existing_ad_application = true +} diff --git a/lwgenerate/azure/test-data/activity_log_with_config_provider_args.tf b/lwgenerate/azure/test-data/activity_log_with_config_provider_args.tf index b535f9ec7..bc22ff32a 100644 --- a/lwgenerate/azure/test-data/activity_log_with_config_provider_args.tf +++ b/lwgenerate/azure/test-data/activity_log_with_config_provider_args.tf @@ -8,7 +8,6 @@ terraform { } provider "azuread" { - foo = "bar" } provider "azurerm" {