From 464c323311d961eb2e60a338fcab75094d57dff6 Mon Sep 17 00:00:00 2001 From: Heng Lu Date: Fri, 6 Jan 2023 13:22:18 +0800 Subject: [PATCH 1/2] `azurerm_spring_cloud_gateway` - `apm_types`, `environment_variables`, `sensitive_environment_variables` --- .../spring_cloud_gateway_resource.go | 77 +++++++++++++++++++ .../spring_cloud_gateway_resource_test.go | 16 +++- .../docs/r/spring_cloud_gateway.html.markdown | 6 ++ 3 files changed, 96 insertions(+), 3 deletions(-) diff --git a/internal/services/springcloud/spring_cloud_gateway_resource.go b/internal/services/springcloud/spring_cloud_gateway_resource.go index bb73d37974f4..2c1a113b3fad 100644 --- a/internal/services/springcloud/spring_cloud_gateway_resource.go +++ b/internal/services/springcloud/spring_cloud_gateway_resource.go @@ -97,6 +97,21 @@ func resourceSpringCloudGateway() *pluginsdk.Resource { }, }, + "apm_types": { + Type: pluginsdk.TypeList, + Optional: true, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + ValidateFunc: validation.StringInSlice([]string{ + string(appplatform.ApmTypeAppDynamics), + string(appplatform.ApmTypeApplicationInsights), + string(appplatform.ApmTypeDynatrace), + string(appplatform.ApmTypeElasticAPM), + string(appplatform.ApmTypeNewRelic), + }, false), + }, + }, + "cors": { Type: pluginsdk.TypeList, Optional: true, @@ -160,6 +175,25 @@ func resourceSpringCloudGateway() *pluginsdk.Resource { }, }, + "environment_variables": { + Type: pluginsdk.TypeMap, + ForceNew: true, + Optional: true, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + }, + }, + + "sensitive_environment_variables": { + Type: pluginsdk.TypeMap, + Optional: true, + ForceNew: true, + Sensitive: true, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + }, + }, + "https_only": { Type: pluginsdk.TypeBool, Optional: true, @@ -282,7 +316,9 @@ func resourceSpringCloudGatewayCreateUpdate(d *pluginsdk.ResourceData, meta inte gatewayResource := appplatform.GatewayResource{ Properties: &appplatform.GatewayProperties{ APIMetadataProperties: expandGatewayGatewayAPIMetadataProperties(d.Get("api_metadata").([]interface{})), + ApmTypes: expandGatewayGatewayApmTypes(d.Get("apm_types").([]interface{})), CorsProperties: expandGatewayGatewayCorsProperties(d.Get("cors").([]interface{})), + EnvironmentVariables: expandGatewayGatewayEnvironmentVariables(d.Get("environment_variables").(map[string]interface{}), d.Get("sensitive_environment_variables").(map[string]interface{})), HTTPSOnly: utils.Bool(d.Get("https_only").(bool)), Public: utils.Bool(d.Get("public_network_access_enabled").(bool)), ResourceRequests: expandGatewayGatewayResourceRequests(d.Get("quota").([]interface{})), @@ -336,9 +372,17 @@ func resourceSpringCloudGatewayRead(d *pluginsdk.ResourceData, meta interface{}) if err := d.Set("api_metadata", flattenGatewayGatewayAPIMetadataProperties(props.APIMetadataProperties)); err != nil { return fmt.Errorf("setting `api_metadata`: %+v", err) } + if err := d.Set("apm_types", flattenGatewayGatewayApmTypess(props.ApmTypes)); err != nil { + return fmt.Errorf("setting `apm_types`: %+v", err) + } if err := d.Set("cors", flattenGatewayGatewayCorsProperties(props.CorsProperties)); err != nil { return fmt.Errorf("setting `cors`: %+v", err) } + if props.EnvironmentVariables != nil { + if props.EnvironmentVariables.Properties != nil { + d.Set("environment_variables", utils.FlattenMapStringPtrString(props.EnvironmentVariables.Properties)) + } + } d.Set("https_only", props.HTTPSOnly) d.Set("public_network_access_enabled", props.Public) if err := d.Set("quota", flattenGatewayGatewayResourceRequests(props.ResourceRequests)); err != nil { @@ -426,6 +470,28 @@ func expandGatewaySsoProperties(input []interface{}) *appplatform.SsoProperties } } +func expandGatewayGatewayApmTypes(input []interface{}) *[]appplatform.ApmType { + if len(input) == 0 { + return nil + } + out := make([]appplatform.ApmType, 0) + for _, v := range input { + out = append(out, appplatform.ApmType(v.(string))) + } + return &out +} + +func expandGatewayGatewayEnvironmentVariables(env map[string]interface{}, secrets map[string]interface{}) *appplatform.GatewayPropertiesEnvironmentVariables { + if len(env) == 0 && len(secrets) == 0 { + return nil + } + + return &appplatform.GatewayPropertiesEnvironmentVariables{ + Properties: utils.ExpandMapStringPtrString(env), + Secrets: utils.ExpandMapStringPtrString(secrets), + } +} + func flattenGatewayGatewayAPIMetadataProperties(input *appplatform.GatewayAPIMetadataProperties) []interface{} { if input == nil { return make([]interface{}, 0) @@ -544,3 +610,14 @@ func flattenGatewaySsoProperties(input *appplatform.SsoProperties, old []interfa }, } } + +func flattenGatewayGatewayApmTypess(input *[]appplatform.ApmType) []interface{} { + if input == nil { + return nil + } + out := make([]interface{}, 0) + for _, v := range *input { + out = append(out, string(v)) + } + return out +} diff --git a/internal/services/springcloud/spring_cloud_gateway_resource_test.go b/internal/services/springcloud/spring_cloud_gateway_resource_test.go index 505db9a6d296..37046853dc62 100644 --- a/internal/services/springcloud/spring_cloud_gateway_resource_test.go +++ b/internal/services/springcloud/spring_cloud_gateway_resource_test.go @@ -57,7 +57,7 @@ func TestAccSpringCloudGateway_complete(t *testing.T) { check.That(data.ResourceName).ExistsInAzure(r), ), }, - data.ImportStep("sso.0.client_id", "sso.0.client_secret"), + data.ImportStep("sso.0.client_id", "sso.0.client_secret", "sensitive_environment_variables.%", "sensitive_environment_variables.NEW_RELIC_APP_NAME"), }) } @@ -80,7 +80,7 @@ func TestAccSpringCloudGateway_update(t *testing.T) { check.That(data.ResourceName).ExistsInAzure(r), ), }, - data.ImportStep("sso.0.client_id", "sso.0.client_secret"), + data.ImportStep("sso.0.client_id", "sso.0.client_secret", "sensitive_environment_variables.%", "sensitive_environment_variables.NEW_RELIC_APP_NAME"), { Config: r.basic(data), Check: resource.ComposeTestCheckFunc( @@ -162,8 +162,9 @@ resource "azurerm_spring_cloud_gateway" "test" { spring_cloud_service_id = azurerm_spring_cloud_service.test.id https_only = false - public_network_access_enabled = true + public_network_access_enabled = false instance_count = 2 + apm_types = ["ApplicationInsights", "NewRelic"] api_metadata { description = "test description" @@ -181,6 +182,15 @@ resource "azurerm_spring_cloud_gateway" "test" { exposed_headers = ["x-test-header"] max_age_seconds = 86400 } + + environment_variables = { + APPLICATIONINSIGHTS_SAMPLE_RATE = "10" + } + + sensitive_environment_variables = { + NEW_RELIC_APP_NAME = "scg-asa" + } + quota { cpu = "1" memory = "2Gi" diff --git a/website/docs/r/spring_cloud_gateway.html.markdown b/website/docs/r/spring_cloud_gateway.html.markdown index e78aa918370d..8bd8f60eeb78 100644 --- a/website/docs/r/spring_cloud_gateway.html.markdown +++ b/website/docs/r/spring_cloud_gateway.html.markdown @@ -82,8 +82,12 @@ The following arguments are supported: * `api_metadata` - (Optional) A `api_metadata` block as defined below. +* `apm_types` - (Optional) Specifies a list of APM type used in the Spring Cloud Gateway. The allowed values are `AppDynamics`, `ApplicationInsights`, `Dynatrace`, `ElasticAPM` and `NewRelic`. + * `cors` - (Optional) A `cors` block as defined below. +* `environment_variables` - (Optional) Specifies the environment variables of the Spring Cloud Gateway as a map of key-value pairs. + * `https_only` - (Optional) is only https is allowed? * `instance_count` - (Optional) Specifies the required instance count of the Spring Cloud Gateway. Possible Values are between `1` and `500`. Defaults to `1` if not specified. @@ -92,6 +96,8 @@ The following arguments are supported: * `quota` - (Optional) A `quota` block as defined below. +* `sensitive_environment_variables` - (Optional) Specifies the sensitive environment variables of the Spring Cloud Gateway as a map of key-value pairs. + * `sso` - (Optional) A `sso` block as defined below. --- From d8ee0055683491a4f1e981f846d0329546951715 Mon Sep 17 00:00:00 2001 From: Heng Lu Date: Thu, 12 Jan 2023 10:26:01 +0800 Subject: [PATCH 2/2] expand apm_types --- .../services/springcloud/spring_cloud_gateway_resource.go | 8 ++++---- .../springcloud/spring_cloud_gateway_resource_test.go | 8 ++++---- website/docs/r/spring_cloud_gateway.html.markdown | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/internal/services/springcloud/spring_cloud_gateway_resource.go b/internal/services/springcloud/spring_cloud_gateway_resource.go index 2c1a113b3fad..2955d606d4df 100644 --- a/internal/services/springcloud/spring_cloud_gateway_resource.go +++ b/internal/services/springcloud/spring_cloud_gateway_resource.go @@ -97,7 +97,7 @@ func resourceSpringCloudGateway() *pluginsdk.Resource { }, }, - "apm_types": { + "application_performance_monitoring_types": { Type: pluginsdk.TypeList, Optional: true, Elem: &pluginsdk.Schema{ @@ -316,7 +316,7 @@ func resourceSpringCloudGatewayCreateUpdate(d *pluginsdk.ResourceData, meta inte gatewayResource := appplatform.GatewayResource{ Properties: &appplatform.GatewayProperties{ APIMetadataProperties: expandGatewayGatewayAPIMetadataProperties(d.Get("api_metadata").([]interface{})), - ApmTypes: expandGatewayGatewayApmTypes(d.Get("apm_types").([]interface{})), + ApmTypes: expandGatewayGatewayApmTypes(d.Get("application_performance_monitoring_types").([]interface{})), CorsProperties: expandGatewayGatewayCorsProperties(d.Get("cors").([]interface{})), EnvironmentVariables: expandGatewayGatewayEnvironmentVariables(d.Get("environment_variables").(map[string]interface{}), d.Get("sensitive_environment_variables").(map[string]interface{})), HTTPSOnly: utils.Bool(d.Get("https_only").(bool)), @@ -372,8 +372,8 @@ func resourceSpringCloudGatewayRead(d *pluginsdk.ResourceData, meta interface{}) if err := d.Set("api_metadata", flattenGatewayGatewayAPIMetadataProperties(props.APIMetadataProperties)); err != nil { return fmt.Errorf("setting `api_metadata`: %+v", err) } - if err := d.Set("apm_types", flattenGatewayGatewayApmTypess(props.ApmTypes)); err != nil { - return fmt.Errorf("setting `apm_types`: %+v", err) + if err := d.Set("application_performance_monitoring_types", flattenGatewayGatewayApmTypess(props.ApmTypes)); err != nil { + return fmt.Errorf("setting `application_performance_monitoring_types`: %+v", err) } if err := d.Set("cors", flattenGatewayGatewayCorsProperties(props.CorsProperties)); err != nil { return fmt.Errorf("setting `cors`: %+v", err) diff --git a/internal/services/springcloud/spring_cloud_gateway_resource_test.go b/internal/services/springcloud/spring_cloud_gateway_resource_test.go index 37046853dc62..3a2b6429c77b 100644 --- a/internal/services/springcloud/spring_cloud_gateway_resource_test.go +++ b/internal/services/springcloud/spring_cloud_gateway_resource_test.go @@ -161,10 +161,10 @@ resource "azurerm_spring_cloud_gateway" "test" { name = "default" spring_cloud_service_id = azurerm_spring_cloud_service.test.id - https_only = false - public_network_access_enabled = false - instance_count = 2 - apm_types = ["ApplicationInsights", "NewRelic"] + https_only = false + public_network_access_enabled = false + instance_count = 2 + application_performance_monitoring_types = ["ApplicationInsights", "NewRelic"] api_metadata { description = "test description" diff --git a/website/docs/r/spring_cloud_gateway.html.markdown b/website/docs/r/spring_cloud_gateway.html.markdown index 8bd8f60eeb78..8d6196d98472 100644 --- a/website/docs/r/spring_cloud_gateway.html.markdown +++ b/website/docs/r/spring_cloud_gateway.html.markdown @@ -82,7 +82,7 @@ The following arguments are supported: * `api_metadata` - (Optional) A `api_metadata` block as defined below. -* `apm_types` - (Optional) Specifies a list of APM type used in the Spring Cloud Gateway. The allowed values are `AppDynamics`, `ApplicationInsights`, `Dynatrace`, `ElasticAPM` and `NewRelic`. +* `application_performance_monitoring_types` - (Optional) Specifies a list of application performance monitoring types used in the Spring Cloud Gateway. The allowed values are `AppDynamics`, `ApplicationInsights`, `Dynatrace`, `ElasticAPM` and `NewRelic`. * `cors` - (Optional) A `cors` block as defined below.