Skip to content

Commit

Permalink
fix(GROW-2819): split azuread/azurerm gen args
Browse files Browse the repository at this point in the history
  • Loading branch information
ipcrm committed May 31, 2024
1 parent 67c7bbc commit 328709c
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 10 deletions.
25 changes: 18 additions & 7 deletions lwgenerate/azure/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}

Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}

Expand Down
13 changes: 11 additions & 2 deletions lwgenerate/azure/azure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ terraform {
}

provider "azuread" {
foo = "bar"
}

provider "azurerm" {
Expand Down

0 comments on commit 328709c

Please sign in to comment.