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_gateway - support for the application_performance_monitoring_ids property #24919

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
49 changes: 49 additions & 0 deletions internal/services/springcloud/spring_cloud_gateway_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -907,3 +941,18 @@ func flattenGatewayLocalResponseCachePerInstanceProperties(input appplatform.Gat
}
return make([]ResponseCacheModel, 0)
}

func flattenGatewayApms(input *[]appplatform.ApmReference) ([]string, error) {
if input == nil {
return nil, nil
}
out := make([]string, 0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if input == nil {
return nil, nil
}
out := make([]string, 0)
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
}
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,48 @@ 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.apms(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.apms(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
{
Config: r.basic(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we include a step where we update the value of application_performance_monitoring_ids here too?

}

func (r SpringCloudGatewayResource) Exists(ctx context.Context, client *clients.Client, state *pluginsdk.InstanceState) (*bool, error) {
id, err := appplatform.ParseGatewayID(state.ID)
if err != nil {
Expand Down Expand Up @@ -166,6 +208,14 @@ resource "azurerm_spring_cloud_service" "test" {
resource_group_name = azurerm_resource_group.test.name
sku_name = "E0"
}

resource "azurerm_spring_cloud_dynatrace_application_performance_monitoring" "test" {
name = "acctest-apm-%[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"
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we move this to apms rather than have it in template if it isn't applicable to the other tests?

`, data.Locations.Primary, data.RandomInteger)
}

Expand Down Expand Up @@ -250,6 +300,19 @@ resource "azurerm_spring_cloud_gateway" "test" {
`, template, clientId, clientSecret)
}

func (r SpringCloudGatewayResource) apms(data acceptance.TestData) string {
template := r.template(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, data.RandomInteger)
}

func (r SpringCloudGatewayResource) clientAuth(data acceptance.TestData) string {
template := r.template(data)
return fmt.Sprintf(`
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/spring_cloud_gateway.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading