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_container_deployment - support for the application_performance_monitoring_resource_ids property #23862

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
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
Loading