Skip to content

Commit

Permalink
azurerm_spring_cloud_build_deployment, `azurerm_spring_cloud_java_d…
Browse files Browse the repository at this point in the history
…eployment` - support for the `application_performance_monitoring_ids` property
  • Loading branch information
ms-henglu committed Nov 21, 2023
1 parent 6a0f20e commit f9b867e
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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{})),
},
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<default>"
instance_count = 2
name = "acctest-scjd%s"
spring_cloud_app_id = azurerm_spring_cloud_app.test.id
build_result_id = "<default>"
instance_count = 2
application_performance_monitoring_ids = [azurerm_spring_cloud_application_insights_application_performance_monitoring.test.id]
environment_variables = {
"Foo" : "Bar"
Expand Down Expand Up @@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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{})),
},
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
2 changes: 2 additions & 0 deletions website/docs/r/spring_cloud_build_deployment.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/spring_cloud_java_deployment.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit f9b867e

Please sign in to comment.