Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azurerm_spring_cloud_gateway - support for the application_performance_monitoring_types , environment_variables sensitive_environment_variables properties #19884

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions internal/services/springcloud/spring_cloud_gateway_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,21 @@ func resourceSpringCloudGateway() *pluginsdk.Resource {
},
},

"application_performance_monitoring_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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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("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)),
Public: utils.Bool(d.Get("public_network_access_enabled").(bool)),
ResourceRequests: expandGatewayGatewayResourceRequests(d.Get("quota").([]interface{})),
Expand Down Expand Up @@ -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("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)
}
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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
})
}

Expand All @@ -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(
Expand Down Expand Up @@ -161,9 +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 = true
instance_count = 2
https_only = false
public_network_access_enabled = false
instance_count = 2
application_performance_monitoring_types = ["ApplicationInsights", "NewRelic"]

api_metadata {
description = "test description"
Expand All @@ -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"
Expand Down
6 changes: 6 additions & 0 deletions website/docs/r/spring_cloud_gateway.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,12 @@ The following arguments are supported:

* `api_metadata` - (Optional) A `api_metadata` block as defined below.

* `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.

* `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.
Expand All @@ -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.

---
Expand Down