diff --git a/internal/services/springcloud/spring_cloud_build_deployment_resource.go b/internal/services/springcloud/spring_cloud_build_deployment_resource.go index 2d12bd68340c..14b49b274926 100644 --- a/internal/services/springcloud/spring_cloud_build_deployment_resource.go +++ b/internal/services/springcloud/spring_cloud_build_deployment_resource.go @@ -8,6 +8,7 @@ import ( "log" "time" + appplatform2 "github.com/hashicorp/go-azure-sdk/resource-manager/appplatform/2023-09-01-preview/appplatform" "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/migration" @@ -65,6 +66,16 @@ func resourceSpringCloudBuildDeployment() *pluginsdk.Resource { ValidateFunc: validation.StringIsNotEmpty, }, + "application_performance_monitoring_ids": { + Type: pluginsdk.TypeList, + Optional: true, + MinItems: 1, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + ValidateFunc: appplatform2.ValidateApmID, + }, + }, + "addon_json": { Type: pluginsdk.TypeString, Optional: true, @@ -169,6 +180,7 @@ func resourceSpringCloudBuildDeploymentCreateUpdate(d *pluginsdk.ResourceData, m }, DeploymentSettings: &appplatform.DeploymentSettings{ AddonConfigs: addonConfig, + Apms: expandSpringCloudDeploymentApms(d.Get("application_performance_monitoring_ids").([]interface{})), EnvironmentVariables: expandSpringCloudDeploymentEnvironmentVariables(d.Get("environment_variables").(map[string]interface{})), ResourceRequests: expandSpringCloudBuildDeploymentResourceRequests(d.Get("quota").([]interface{})), }, @@ -223,6 +235,11 @@ func resourceSpringCloudBuildDeploymentRead(d *pluginsdk.ResourceData, meta inte if err := d.Set("addon_json", flattenSpringCloudAppAddon(settings.AddonConfigs)); err != nil { return fmt.Errorf("setting `addon_json`: %s", err) } + apmIds, err := flattenSpringCloudDeploymentApms(settings.Apms) + if err != nil { + return fmt.Errorf("setting `application_performance_monitoring_ids`: %+v", err) + } + d.Set("application_performance_monitoring_ids", apmIds) } if source, ok := resp.Properties.Source.AsBuildResultUserSourceInfo(); ok && source != nil { d.Set("build_result_id", source.BuildResultID) diff --git a/internal/services/springcloud/spring_cloud_build_deployment_resource_test.go b/internal/services/springcloud/spring_cloud_build_deployment_resource_test.go index b2c32881fc00..18649f66e751 100644 --- a/internal/services/springcloud/spring_cloud_build_deployment_resource_test.go +++ b/internal/services/springcloud/spring_cloud_build_deployment_resource_test.go @@ -157,10 +157,11 @@ func (r SpringCloudBuildDeploymentResource) complete(data acceptance.TestData) s %s resource "azurerm_spring_cloud_build_deployment" "test" { - name = "acctest-scjd%s" - spring_cloud_app_id = azurerm_spring_cloud_app.test.id - build_result_id = "" - instance_count = 2 + name = "acctest-scjd%s" + spring_cloud_app_id = azurerm_spring_cloud_app.test.id + build_result_id = "" + instance_count = 2 + application_performance_monitoring_ids = [azurerm_spring_cloud_application_insights_application_performance_monitoring.test.id] environment_variables = { "Foo" : "Bar" @@ -204,25 +205,43 @@ resource "azurerm_spring_cloud_build_deployment" "test" { func (SpringCloudBuildDeploymentResource) template(data acceptance.TestData) string { return fmt.Sprintf(` provider "azurerm" { - features {} + features { + application_insights { + disable_generated_rule = true + } + } } resource "azurerm_resource_group" "test" { - name = "acctestRG-spring-%d" - location = "%s" + name = "acctestRG-spring-%[2]d" + location = "%[1]s" } resource "azurerm_spring_cloud_service" "test" { - name = "acctest-sc-%d" + name = "acctest-sc-%[2]d" location = azurerm_resource_group.test.location resource_group_name = azurerm_resource_group.test.name sku_name = "E0" } resource "azurerm_spring_cloud_app" "test" { - name = "acctest-sca-%d" + name = "acctest-sca-%[2]d" resource_group_name = azurerm_spring_cloud_service.test.resource_group_name service_name = azurerm_spring_cloud_service.test.name } -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) + + +resource "azurerm_application_insights" "test" { + name = "acctest-ai-%[2]d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + application_type = "web" +} + +resource "azurerm_spring_cloud_application_insights_application_performance_monitoring" "test" { + name = "acctest-apm-%[2]d" + spring_cloud_service_id = azurerm_spring_cloud_service.test.id + connection_string = azurerm_application_insights.test.instrumentation_key +} +`, data.Locations.Primary, data.RandomInteger) } diff --git a/internal/services/springcloud/spring_cloud_java_deployment_resource.go b/internal/services/springcloud/spring_cloud_java_deployment_resource.go index 8295de302a28..d38644f2eb46 100644 --- a/internal/services/springcloud/spring_cloud_java_deployment_resource.go +++ b/internal/services/springcloud/spring_cloud_java_deployment_resource.go @@ -9,6 +9,7 @@ import ( "strconv" "time" + appplatform2 "github.com/hashicorp/go-azure-sdk/resource-manager/appplatform/2023-09-01-preview/appplatform" "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/migration" @@ -94,6 +95,7 @@ func resourceSpringCloudJavaDeploymentCreate(d *pluginsdk.ResourceData, meta int Type: appplatform.TypeBasicUserSourceInfoTypeJar, }, DeploymentSettings: &appplatform.DeploymentSettings{ + Apms: expandSpringCloudDeploymentApms(d.Get("application_performance_monitoring_ids").([]interface{})), EnvironmentVariables: expandSpringCloudDeploymentEnvironmentVariables(d.Get("environment_variables").(map[string]interface{})), ResourceRequests: expandSpringCloudDeploymentResourceRequests(d.Get("quota").([]interface{})), }, @@ -174,6 +176,10 @@ func resourceSpringCloudJavaDeploymentUpdate(d *pluginsdk.ResourceData, meta int } } + if d.HasChange("application_performance_monitoring_ids") { + existing.Properties.DeploymentSettings.Apms = expandSpringCloudDeploymentApms(d.Get("application_performance_monitoring_ids").([]interface{})) + } + future, err := client.CreateOrUpdate(ctx, id.ResourceGroup, id.SpringName, id.AppName, id.DeploymentName, existing) if err != nil { return fmt.Errorf("updating %s: %+v", id, err) @@ -217,6 +223,11 @@ func resourceSpringCloudJavaDeploymentRead(d *pluginsdk.ResourceData, meta inter if err := d.Set("quota", flattenSpringCloudDeploymentResourceRequests(settings.ResourceRequests)); err != nil { return fmt.Errorf("setting `quota`: %+v", err) } + apmIds, err := flattenSpringCloudDeploymentApms(settings.Apms) + if err != nil { + return fmt.Errorf("setting `application_performance_monitoring_ids`: %+v", err) + } + d.Set("application_performance_monitoring_ids", apmIds) } if source, ok := resp.Properties.Source.AsJarUploadedUserSourceInfo(); ok && source != nil { d.Set("jvm_options", source.JvmOptions) @@ -333,6 +344,16 @@ func resourceSprintCloudJavaDeploymentSchema() map[string]*pluginsdk.Schema { ValidateFunc: validate.SpringCloudAppID, }, + "application_performance_monitoring_ids": { + Type: pluginsdk.TypeList, + Optional: true, + MinItems: 1, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + ValidateFunc: appplatform2.ValidateApmID, + }, + }, + "environment_variables": { Type: pluginsdk.TypeMap, Optional: true, diff --git a/internal/services/springcloud/spring_cloud_java_deployment_resource_test.go b/internal/services/springcloud/spring_cloud_java_deployment_resource_test.go index ae74efed4a13..3d059155eeb2 100644 --- a/internal/services/springcloud/spring_cloud_java_deployment_resource_test.go +++ b/internal/services/springcloud/spring_cloud_java_deployment_resource_test.go @@ -162,11 +162,12 @@ func (r SpringCloudJavaDeploymentResource) complete(data acceptance.TestData) st %s resource "azurerm_spring_cloud_java_deployment" "test" { - name = "acctest-scjd%s" - spring_cloud_app_id = azurerm_spring_cloud_app.test.id - instance_count = 2 - jvm_options = "-XX:+PrintGC" - runtime_version = "Java_11" + name = "acctest-scjd%s" + spring_cloud_app_id = azurerm_spring_cloud_app.test.id + instance_count = 2 + jvm_options = "-XX:+PrintGC" + runtime_version = "Java_11" + application_performance_monitoring_ids = [azurerm_spring_cloud_application_insights_application_performance_monitoring.test.id] quota { cpu = "2" memory = "2Gi" @@ -212,24 +213,43 @@ resource "azurerm_spring_cloud_java_deployment" "test" { func (SpringCloudJavaDeploymentResource) template(data acceptance.TestData) string { return fmt.Sprintf(` provider "azurerm" { - features {} + features { + application_insights { + disable_generated_rule = true + } + } } resource "azurerm_resource_group" "test" { - name = "acctestRG-spring-%d" - location = "%s" + name = "acctestRG-spring-%[2]d" + location = "%[1]s" } resource "azurerm_spring_cloud_service" "test" { - name = "acctest-sc-%d" + name = "acctest-sc-%[2]d" location = azurerm_resource_group.test.location resource_group_name = azurerm_resource_group.test.name + sku_name = "E0" } resource "azurerm_spring_cloud_app" "test" { - name = "acctest-sca-%d" + name = "acctest-sca-%[2]d" resource_group_name = azurerm_spring_cloud_service.test.resource_group_name service_name = azurerm_spring_cloud_service.test.name } -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) + + +resource "azurerm_application_insights" "test" { + name = "acctest-ai-%[2]d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + application_type = "web" +} + +resource "azurerm_spring_cloud_application_insights_application_performance_monitoring" "test" { + name = "acctest-apm-%[2]d" + spring_cloud_service_id = azurerm_spring_cloud_service.test.id + connection_string = azurerm_application_insights.test.instrumentation_key +} +`, data.Locations.Primary, data.RandomInteger) } diff --git a/website/docs/r/spring_cloud_build_deployment.html.markdown b/website/docs/r/spring_cloud_build_deployment.html.markdown index 106972311b37..7bc7f46a262a 100644 --- a/website/docs/r/spring_cloud_build_deployment.html.markdown +++ b/website/docs/r/spring_cloud_build_deployment.html.markdown @@ -68,6 +68,8 @@ The following arguments are supported: * `addon_json` - (Optional) A JSON object that contains the addon configurations of the Spring Cloud Build Deployment. +* `application_performance_monitoring_ids` - (Optional) Specifies a list of Spring Cloud Application Performance Monitoring IDs. + * `environment_variables` - (Optional) Specifies the environment variables of the Spring Cloud Deployment as a map of key-value pairs. * `instance_count` - (Optional) Specifies the required instance count of the Spring Cloud Deployment. Possible Values are between `1` and `500`. Defaults to `1` if not specified. diff --git a/website/docs/r/spring_cloud_java_deployment.html.markdown b/website/docs/r/spring_cloud_java_deployment.html.markdown index af19a260b79d..e95a7a00505e 100644 --- a/website/docs/r/spring_cloud_java_deployment.html.markdown +++ b/website/docs/r/spring_cloud_java_deployment.html.markdown @@ -68,6 +68,8 @@ The following arguments are supported: * `spring_cloud_app_id` - (Required) Specifies the id of the Spring Cloud Application in which to create the Deployment. Changing this forces a new resource to be created. +* `application_performance_monitoring_ids` - (Optional) Specifies a list of Spring Cloud Application Performance Monitoring IDs. + * `environment_variables` - (Optional) Specifies the environment variables of the Spring Cloud Deployment as a map of key-value pairs. * `instance_count` - (Optional) Specifies the required instance count of the Spring Cloud Deployment. Possible Values are between `1` and `500`. Defaults to `1` if not specified.