diff --git a/internal/services/springcloud/spring_cloud_gateway_resource.go b/internal/services/springcloud/spring_cloud_gateway_resource.go index d8a0add1e0ca6..71107d62255c2 100644 --- a/internal/services/springcloud/spring_cloud_gateway_resource.go +++ b/internal/services/springcloud/spring_cloud_gateway_resource.go @@ -22,6 +22,7 @@ type SpringCloudGatewayModel struct { Name string `tfschema:"name"` SpringCloudServiceId string `tfschema:"spring_cloud_service_id"` ApiMetadata []ApiMetadataModel `tfschema:"api_metadata"` + ApplicationPerformanceMonitoringIds []string `tfschema:"application_performance_monitoring_ids"` ApplicationPerformanceMonitoringTypes []string `tfschema:"application_performance_monitoring_types"` ClientAuthorization []ClientAuthorizationModel `tfschema:"client_authorization"` Cors []CorsModel `tfschema:"cors"` @@ -151,6 +152,16 @@ func (s SpringCloudGatewayResource) Arguments() map[string]*pluginsdk.Schema { }, }, + "application_performance_monitoring_ids": { + Type: pluginsdk.TypeList, + Optional: true, + MinItems: 1, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + ValidateFunc: appplatform.ValidateApmID, + }, + }, + "application_performance_monitoring_types": { Type: pluginsdk.TypeList, Optional: true, @@ -462,6 +473,7 @@ func (s SpringCloudGatewayResource) Create() sdk.ResourceFunc { Properties: &appplatform.GatewayProperties{ ClientAuth: expandGatewayClientAuth(model.ClientAuthorization), ApiMetadataProperties: expandGatewayGatewayAPIMetadataProperties(model.ApiMetadata), + Apms: expandGatewayApms(model.ApplicationPerformanceMonitoringIds), ApmTypes: expandGatewayGatewayApmTypes(model.ApplicationPerformanceMonitoringTypes), CorsProperties: expandGatewayGatewayCorsProperties(model.Cors), EnvironmentVariables: expandGatewayGatewayEnvironmentVariables(model.EnvironmentVariables, model.SensitiveEnvironmentVariables), @@ -530,6 +542,10 @@ func (s SpringCloudGatewayResource) Update() sdk.ResourceFunc { properties.ApiMetadataProperties = expandGatewayGatewayAPIMetadataProperties(model.ApiMetadata) } + if metadata.ResourceData.HasChange("application_performance_monitoring_ids") { + properties.Apms = expandGatewayApms(model.ApplicationPerformanceMonitoringIds) + } + if metadata.ResourceData.HasChange("application_performance_monitoring_types") { properties.ApmTypes = expandGatewayGatewayApmTypes(model.ApplicationPerformanceMonitoringTypes) } @@ -614,6 +630,11 @@ func (s SpringCloudGatewayResource) Read() sdk.ResourceFunc { if resp.Model != nil { if props := resp.Model.Properties; props != nil { state.ApiMetadata = flattenGatewayGatewayAPIMetadataProperties(props.ApiMetadataProperties) + apms, err := flattenGatewayApms(props.Apms) + if err != nil { + return err + } + state.ApplicationPerformanceMonitoringIds = apms state.ApplicationPerformanceMonitoringTypes = flattenGatewayGatewayApmTypes(props.ApmTypes) state.ClientAuthorization = flattenGatewayClientAuth(props.ClientAuth) state.Cors = flattenGatewayGatewayCorsProperties(props.CorsProperties) @@ -766,6 +787,19 @@ func expandGatewayResponseCacheProperties(input SpringCloudGatewayModel) appplat return appplatform.RawGatewayResponseCachePropertiesImpl{} } +func expandGatewayApms(input []string) *[]appplatform.ApmReference { + if len(input) == 0 { + return nil + } + out := make([]appplatform.ApmReference, 0) + for _, v := range input { + out = append(out, appplatform.ApmReference{ + ResourceId: v, + }) + } + return pointer.To(out) +} + func flattenGatewayGatewayAPIMetadataProperties(input *appplatform.GatewayApiMetadataProperties) []ApiMetadataModel { if input == nil { return make([]ApiMetadataModel, 0) @@ -907,3 +941,18 @@ func flattenGatewayLocalResponseCachePerInstanceProperties(input appplatform.Gat } return make([]ResponseCacheModel, 0) } + +func flattenGatewayApms(input *[]appplatform.ApmReference) ([]string, error) { + out := make([]string, 0) + if input == nil { + return out, nil + } + for _, v := range *input { + id, err := appplatform.ParseApmIDInsensitively(v.ResourceId) + if err != nil { + return nil, err + } + out = append(out, id.ID()) + } + return out, nil +} diff --git a/internal/services/springcloud/spring_cloud_gateway_resource_test.go b/internal/services/springcloud/spring_cloud_gateway_resource_test.go index 7570f2796c45c..19695dfd4d645 100644 --- a/internal/services/springcloud/spring_cloud_gateway_resource_test.go +++ b/internal/services/springcloud/spring_cloud_gateway_resource_test.go @@ -129,6 +129,62 @@ func TestAccSpringCloudGateway_responseCache(t *testing.T) { }) } +func TestAccSpringCloudGateway_apms(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_spring_cloud_gateway", "test") + r := SpringCloudGatewayResource{} + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.elasticApm(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + +func TestAccSpringCloudGateway_apmsUpdate(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_spring_cloud_gateway", "test") + r := SpringCloudGatewayResource{} + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.basic(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + { + Config: r.elasticApm(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + { + Config: r.dynatraceApm(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + { + Config: r.multipleApms(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + { + Config: r.noApms(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + func (r SpringCloudGatewayResource) Exists(ctx context.Context, client *clients.Client, state *pluginsdk.InstanceState) (*bool, error) { id, err := appplatform.ParseGatewayID(state.ID) if err != nil { @@ -250,6 +306,80 @@ resource "azurerm_spring_cloud_gateway" "test" { `, template, clientId, clientSecret) } +func (r SpringCloudGatewayResource) apmsTemplate(data acceptance.TestData) string { + template := r.template(data) + return fmt.Sprintf(` +%[1]s + +resource "azurerm_spring_cloud_dynatrace_application_performance_monitoring" "test" { + name = "acctest-dapm-%[2]d" + spring_cloud_service_id = azurerm_spring_cloud_service.test.id + tenant = "test-tenant" + tenant_token = "dt0s01.AAAAAAAAAAAAAAAAAAAAAAAA.BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB" + connection_point = "https://example.live.dynatrace.com:443" +} + +resource "azurerm_spring_cloud_elastic_application_performance_monitoring" "test" { + name = "acctest-eapm-%[2]d" + spring_cloud_service_id = azurerm_spring_cloud_service.test.id + application_packages = ["org.example", "org.another.example"] + service_name = "test-service-name" + server_url = "http://127.0.0.1:8200" +} +`, template, data.RandomInteger) +} + +func (r SpringCloudGatewayResource) dynatraceApm(data acceptance.TestData) string { + template := r.apmsTemplate(data) + return fmt.Sprintf(` +%[1]s + +resource "azurerm_spring_cloud_gateway" "test" { + name = "default" + spring_cloud_service_id = azurerm_spring_cloud_service.test.id + application_performance_monitoring_ids = [azurerm_spring_cloud_dynatrace_application_performance_monitoring.test.id] +} +`, template) +} + +func (r SpringCloudGatewayResource) elasticApm(data acceptance.TestData) string { + template := r.apmsTemplate(data) + return fmt.Sprintf(` +%[1]s + +resource "azurerm_spring_cloud_gateway" "test" { + name = "default" + spring_cloud_service_id = azurerm_spring_cloud_service.test.id + application_performance_monitoring_ids = [azurerm_spring_cloud_elastic_application_performance_monitoring.test.id] +} +`, template) +} + +func (r SpringCloudGatewayResource) multipleApms(data acceptance.TestData) string { + template := r.apmsTemplate(data) + return fmt.Sprintf(` +%[1]s + +resource "azurerm_spring_cloud_gateway" "test" { + name = "default" + spring_cloud_service_id = azurerm_spring_cloud_service.test.id + application_performance_monitoring_ids = [azurerm_spring_cloud_dynatrace_application_performance_monitoring.test.id, azurerm_spring_cloud_elastic_application_performance_monitoring.test.id] +} +`, template) +} + +func (r SpringCloudGatewayResource) noApms(data acceptance.TestData) string { + template := r.apmsTemplate(data) + return fmt.Sprintf(` +%[1]s + +resource "azurerm_spring_cloud_gateway" "test" { + name = "default" + spring_cloud_service_id = azurerm_spring_cloud_service.test.id +} +`, template) +} + func (r SpringCloudGatewayResource) clientAuth(data acceptance.TestData) string { template := r.template(data) return fmt.Sprintf(` diff --git a/website/docs/r/spring_cloud_gateway.html.markdown b/website/docs/r/spring_cloud_gateway.html.markdown index de6f442fe0076..1b5e83d08fe0f 100644 --- a/website/docs/r/spring_cloud_gateway.html.markdown +++ b/website/docs/r/spring_cloud_gateway.html.markdown @@ -87,6 +87,8 @@ The following arguments are supported: * `api_metadata` - (Optional) A `api_metadata` block as defined below. +* `application_performance_monitoring_ids` - (Optional) Specifies a list of Spring Cloud Application Performance Monitoring IDs. + * `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`. * `client_authorization` - (Optional) A `client_authorization` block as defined below.