Skip to content

Commit

Permalink
azurerm_spring_cloud_container_deployment - support for the `applic…
Browse files Browse the repository at this point in the history
…ation_performance_monitoring_resource_ids` property (hashicorp#23862)

* `azurerm_spring_cloud_container_deployment` - support for the `application_performance_monitoring_resource_ids` property

* update

* update

* update
  • Loading branch information
ms-henglu authored Nov 20, 2023
1 parent 53fef37 commit 3870f0a
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"log"
"time"

"github.com/hashicorp/go-azure-helpers/lang/pointer"
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 @@ -79,6 +81,16 @@ func resourceSpringCloudContainerDeployment() *pluginsdk.Resource {
DiffSuppressFunc: pluginsdk.SuppressJsonDiff,
},

"application_performance_monitoring_ids": {
Type: pluginsdk.TypeList,
Optional: true,
MinItems: 1,
Elem: &pluginsdk.Schema{
Type: pluginsdk.TypeString,
ValidateFunc: appplatform2.ValidateApmID,
},
},

"arguments": {
Type: pluginsdk.TypeList,
Optional: true,
Expand Down Expand Up @@ -207,6 +219,7 @@ func resourceSpringCloudContainerDeploymentCreateUpdate(d *pluginsdk.ResourceDat
},
DeploymentSettings: &appplatform.DeploymentSettings{
AddonConfigs: addonConfig,
Apms: expandSpringCloudDeploymentApms(d.Get("application_performance_monitoring_ids").([]interface{})),
EnvironmentVariables: expandSpringCloudDeploymentEnvironmentVariables(d.Get("environment_variables").(map[string]interface{})),
ResourceRequests: expandSpringCloudContainerDeploymentResourceRequests(d.Get("quota").([]interface{})),
},
Expand Down Expand Up @@ -261,6 +274,11 @@ func resourceSpringCloudContainerDeploymentRead(d *pluginsdk.ResourceData, meta
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.AsCustomContainerUserSourceInfo(); ok && source != nil {
if container := source.CustomContainer; container != nil {
Expand Down Expand Up @@ -320,3 +338,31 @@ func expandSpringCloudContainerDeploymentResourceRequests(input []interface{}) *

return &result
}

func expandSpringCloudDeploymentApms(input []interface{}) *[]appplatform.ApmReference {
if len(input) == 0 {
return nil
}
result := make([]appplatform.ApmReference, 0)
for _, v := range input {
result = append(result, appplatform.ApmReference{
ResourceID: pointer.To(v.(string)),
})
}
return pointer.To(result)
}

func flattenSpringCloudDeploymentApms(input *[]appplatform.ApmReference) ([]interface{}, error) {
if input == nil {
return nil, nil
}
result := make([]interface{}, 0)
for _, v := range *input {
id, err := appplatform2.ParseApmIDInsensitively(*v.ResourceID)
if err != nil {
return nil, err
}
result = append(result, id.ID())
}
return result, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,15 @@ resource "azurerm_spring_cloud_container_deployment" "import" {

func (r SpringCloudContainerDeploymentResource) complete(data acceptance.TestData) string {
return fmt.Sprintf(`
%s
%[1]s
resource "azurerm_spring_cloud_container_deployment" "test" {
name = "acctest-scjd%s"
spring_cloud_app_id = azurerm_spring_cloud_app.test.id
instance_count = 2
arguments = ["-cp", "/app/resources:/app/classes:/app/libs/*", "hello.Application"]
commands = ["java"]
name = "acctest-scjd%[2]s"
spring_cloud_app_id = azurerm_spring_cloud_app.test.id
instance_count = 2
arguments = ["-cp", "/app/resources:/app/classes:/app/libs/*", "hello.Application"]
application_performance_monitoring_ids = [azurerm_spring_cloud_application_insights_application_performance_monitoring.test.id]
commands = ["java"]
environment_variables = {
"Foo" : "Bar"
"Env" : "Staging"
Expand Down Expand Up @@ -204,25 +205,43 @@ resource "azurerm_spring_cloud_container_deployment" "test" {
func (SpringCloudContainerDeploymentResource) 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 @@ -67,6 +67,8 @@ The following arguments are supported:

* `addon_json` - (Optional) A JSON object that contains the addon configurations of the Spring Cloud Container Deployment.

* `application_performance_monitoring_ids` - (Optional) Specifies a list of Spring Cloud Application Performance Monitoring IDs.

* `arguments` - (Optional) Specifies the arguments to the entrypoint. The docker image's `CMD` is used if not specified.

* `commands` - (Optional) Specifies the entrypoint array. It will not be executed within a shell. The docker image's `ENTRYPOINT` is used if not specified.
Expand Down

0 comments on commit 3870f0a

Please sign in to comment.