From 0471d5abd4f6f3a2e9cde3363612f369595638c0 Mon Sep 17 00:00:00 2001 From: Paolo Salvatori Date: Mon, 20 Feb 2023 09:09:45 +0100 Subject: [PATCH 1/9] Made app_port property optional --- internal/services/containerapps/helpers/container_apps.go | 2 +- website/docs/r/container_app.html.markdown | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/services/containerapps/helpers/container_apps.go b/internal/services/containerapps/helpers/container_apps.go index b103c43a6c38..15089b192376 100644 --- a/internal/services/containerapps/helpers/container_apps.go +++ b/internal/services/containerapps/helpers/container_apps.go @@ -404,7 +404,7 @@ func ContainerDaprSchema() *pluginsdk.Schema { "app_port": { Type: pluginsdk.TypeInt, - Required: true, + Required: false, Description: "The port which the application is listening on. This is the same as the `ingress` port.", }, diff --git a/website/docs/r/container_app.html.markdown b/website/docs/r/container_app.html.markdown index 763b57778247..6a83b01ee17a 100644 --- a/website/docs/r/container_app.html.markdown +++ b/website/docs/r/container_app.html.markdown @@ -307,7 +307,7 @@ A `dapr` block supports the following: * `app_id` - (Required) The Dapr Application Identifier. -* `app_port` - (Required) The port which the application is listening on. This is the same as the `ingress` port. +* `app_port` - (Optional) The port which the application is listening on. This is the same as the `ingress` port. * `app_protocol` - (Optional) The protocol for the app. Possible values include `http` and `grpc`. Defaults to `http`. From c67a180a62d05ec12e87d9507beb187fb015dea4 Mon Sep 17 00:00:00 2001 From: Paolo Salvatori Date: Mon, 20 Feb 2023 11:49:29 +0100 Subject: [PATCH 2/9] Replaced Required: false with Optional: true --- internal/services/containerapps/helpers/container_apps.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/services/containerapps/helpers/container_apps.go b/internal/services/containerapps/helpers/container_apps.go index 15089b192376..a7a5963e0506 100644 --- a/internal/services/containerapps/helpers/container_apps.go +++ b/internal/services/containerapps/helpers/container_apps.go @@ -404,7 +404,7 @@ func ContainerDaprSchema() *pluginsdk.Schema { "app_port": { Type: pluginsdk.TypeInt, - Required: false, + Optional: true, Description: "The port which the application is listening on. This is the same as the `ingress` port.", }, From 5fbd8bec6838a7c77a07f90cb369ae96a1a15b91 Mon Sep 17 00:00:00 2001 From: Paolo Salvatori Date: Tue, 21 Feb 2023 09:51:25 +0100 Subject: [PATCH 3/9] Added completeWithNoAppPort test function --- .../container_app_resource_test.go | 95 +++++++++++++++++++ 1 file changed, 95 insertions(+) diff --git a/internal/services/containerapps/container_app_resource_test.go b/internal/services/containerapps/container_app_resource_test.go index 546cdd3e3bc8..d58a241a1b04 100644 --- a/internal/services/containerapps/container_app_resource_test.go +++ b/internal/services/containerapps/container_app_resource_test.go @@ -472,6 +472,101 @@ resource "azurerm_container_app" "test" { `, r.templatePlusExtras(data), data.RandomInteger, revisionSuffix) } +func (r ContainerAppResource) completeWithNoAppPort(data acceptance.TestData, revisionSuffix string) string { + return fmt.Sprintf(` +%s + +resource "azurerm_container_app" "test" { + name = "acctest-capp-%[2]d" + resource_group_name = azurerm_resource_group.test.name + container_app_environment_id = azurerm_container_app_environment.test.id + revision_mode = "Single" + + template { + container { + name = "acctest-cont-%[2]d" + image = "jackofallops/azure-containerapps-python-acctest:v0.0.1" + cpu = 0.25 + memory = "0.5Gi" + + readiness_probe { + transport = "HTTP" + port = 5000 + } + + liveness_probe { + transport = "HTTP" + port = 5000 + path = "/health" + + header { + name = "Cache-Control" + value = "no-cache" + } + + initial_delay = 5 + interval_seconds = 20 + timeout = 2 + failure_count_threshold = 1 + } + + startup_probe { + transport = "TCP" + port = 5000 + } + + volume_mounts { + name = azurerm_container_app_environment_storage.test.name + path = "/tmp/testdata" + } + } + + volume { + name = azurerm_container_app_environment_storage.test.name + storage_type = "AzureFile" + storage_name = azurerm_container_app_environment_storage.test.name + } + + min_replicas = 2 + max_replicas = 3 + + revision_suffix = "%[3]s" + } + + ingress { + allow_insecure_connections = true + external_enabled = true + target_port = 5000 + transport = "http" + traffic_weight { + latest_revision = true + percentage = 100 + } + } + + registry { + server = azurerm_container_registry.test.login_server + username = azurerm_container_registry.test.admin_username + password_secret_name = "registry-password" + } + + secret { + name = "registry-password" + value = azurerm_container_registry.test.admin_password + } + + dapr { + app_id = "acctest-cont-%[2]d" + } + + tags = { + foo = "Bar" + accTest = "1" + } +} +`, r.templatePlusExtras(data), data.RandomInteger, revisionSuffix) +} + func (r ContainerAppResource) completeWithVnet(data acceptance.TestData, revisionSuffix string) string { return fmt.Sprintf(` %s From a232053d580ff644d59fa911b89c5d6e178ab4a1 Mon Sep 17 00:00:00 2001 From: Paolo Salvatori Date: Tue, 21 Feb 2023 10:32:18 +0100 Subject: [PATCH 4/9] Small fix --- internal/services/containerapps/helpers/container_apps.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/services/containerapps/helpers/container_apps.go b/internal/services/containerapps/helpers/container_apps.go index a7a5963e0506..fddd7a1e2f34 100644 --- a/internal/services/containerapps/helpers/container_apps.go +++ b/internal/services/containerapps/helpers/container_apps.go @@ -404,7 +404,7 @@ func ContainerDaprSchema() *pluginsdk.Schema { "app_port": { Type: pluginsdk.TypeInt, - Optional: true, + Optional: true, Description: "The port which the application is listening on. This is the same as the `ingress` port.", }, From b9a6e086fb2ac307aca090ab42be02d2c1709f27 Mon Sep 17 00:00:00 2001 From: Paolo Salvatori Date: Fri, 24 Feb 2023 09:16:33 +0100 Subject: [PATCH 5/9] Added test function --- .../containerapps/container_app_resource_test.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/internal/services/containerapps/container_app_resource_test.go b/internal/services/containerapps/container_app_resource_test.go index d58a241a1b04..2d2a95b1bb15 100644 --- a/internal/services/containerapps/container_app_resource_test.go +++ b/internal/services/containerapps/container_app_resource_test.go @@ -143,6 +143,21 @@ func TestAccContainerAppResource_complete(t *testing.T) { }) } +func TestAccContainerAppResource_completeWithNoAppPort(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_container_app", "test") + r := ContainerAppResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.completeWithNoAppPort(data, "rev1"), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + func TestAccContainerAppResource_completeWithVNet(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_container_app", "test") r := ContainerAppResource{} From efc592217877e2839d4b51dbcf95a709834c86ec Mon Sep 17 00:00:00 2001 From: Paolo Salvatori Date: Wed, 1 Mar 2023 15:09:13 +0100 Subject: [PATCH 6/9] Added TestAccContainerAppResource_removeDaprAppPort --- .../container_app_resource_test.go | 145 +++++++++++++++++- 1 file changed, 142 insertions(+), 3 deletions(-) diff --git a/internal/services/containerapps/container_app_resource_test.go b/internal/services/containerapps/container_app_resource_test.go index 2d2a95b1bb15..e40dc03420a5 100644 --- a/internal/services/containerapps/container_app_resource_test.go +++ b/internal/services/containerapps/container_app_resource_test.go @@ -143,13 +143,13 @@ func TestAccContainerAppResource_complete(t *testing.T) { }) } -func TestAccContainerAppResource_completeWithNoAppPort(t *testing.T) { +func TestAccContainerAppResource_completeWithNoDaprAppPort(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_container_app", "test") r := ContainerAppResource{} data.ResourceTest(t, r, []acceptance.TestStep{ { - Config: r.completeWithNoAppPort(data, "rev1"), + Config: r.completeWithNoDaprAppPort(data, "rev1"), Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), @@ -210,6 +210,28 @@ func TestAccContainerAppResource_completeUpdate(t *testing.T) { }) } +func TestAccContainerAppResource_removeDaprAppPort(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_container_app", "test") + r := ContainerAppResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.complete(data, "rev1"), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + { + Config: r.completeUpdate_withNoDaprAppPort(data, "rev2"), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).Key("dapr.app_port").IsEmpty(), + ), + }, + data.ImportStep(), + }) +} + func TestAccContainerAppResource_secretRemoveShouldFail(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_container_app", "test") r := ContainerAppResource{} @@ -487,7 +509,7 @@ resource "azurerm_container_app" "test" { `, r.templatePlusExtras(data), data.RandomInteger, revisionSuffix) } -func (r ContainerAppResource) completeWithNoAppPort(data acceptance.TestData, revisionSuffix string) string { +func (r ContainerAppResource) completeWithNoDaprAppPort(data acceptance.TestData, revisionSuffix string) string { return fmt.Sprintf(` %s @@ -1024,6 +1046,123 @@ resource "azurerm_container_app" "test" { `, r.templatePlusExtras(data), data.RandomInteger, revisionSuffix) } +func (r ContainerAppResource) completeUpdate_withNoDaprAppPort(data acceptance.TestData, revisionSuffix string) string { + return fmt.Sprintf(` +%s + +resource "azurerm_container_app" "test" { + name = "acctest-capp-%[2]d" + resource_group_name = azurerm_resource_group.test.name + container_app_environment_id = azurerm_container_app_environment.test.id + revision_mode = "Multiple" + + template { + container { + name = "acctest-cont-%[2]d" + image = "jackofallops/azure-containerapps-python-acctest:v0.0.1" + + cpu = 0.5 + memory = "1Gi" + + readiness_probe { + transport = "HTTP" + port = 5000 + path = "/uptime" + timeout = 2 + failure_count_threshold = 1 + success_count_threshold = 1 + + header { + name = "Cache-Control" + value = "no-cache" + } + } + + liveness_probe { + transport = "HTTP" + port = 5000 + path = "/health" + + header { + name = "Cache-Control" + value = "no-cache" + } + + initial_delay = 5 + timeout = 2 + failure_count_threshold = 3 + } + + startup_probe { + transport = "TCP" + port = 5000 + timeout = 5 + failure_count_threshold = 1 + } + + volume_mounts { + name = azurerm_container_app_environment_storage.test.name + path = "/tmp/testdata" + } + } + + volume { + name = azurerm_container_app_environment_storage.test.name + storage_type = "AzureFile" + storage_name = azurerm_container_app_environment_storage.test.name + } + + min_replicas = 1 + max_replicas = 4 + + revision_suffix = "%[3]s" + } + + ingress { + allow_insecure_connections = true + external_enabled = true + target_port = 5000 + transport = "auto" + + traffic_weight { + latest_revision = true + percentage = 20 + } + + traffic_weight { + revision_suffix = "rev1" + percentage = 80 + } + } + + registry { + server = azurerm_container_registry.test.login_server + username = azurerm_container_registry.test.admin_username + password_secret_name = "registry-password" + } + + secret { + name = "registry-password" + value = azurerm_container_registry.test.admin_password + } + + secret { + name = "rick" + value = "morty" + } + + dapr { + app_id = "acctest-cont-%[2]d" + } + + tags = { + foo = "Bar" + accTest = "1" + } +} +`, r.templatePlusExtras(data), data.RandomInteger, revisionSuffix) +} + func (ContainerAppResource) template(data acceptance.TestData) string { return ContainerAppEnvironmentResource{}.basic(data) } From b42542b2d390df652b00abf842b6e3d519bf33b7 Mon Sep 17 00:00:00 2001 From: Paolo Salvatori Date: Fri, 10 Mar 2023 10:30:35 +0100 Subject: [PATCH 7/9] Update internal/services/containerapps/container_app_resource_test.go Co-authored-by: jackofallops <11830746+jackofallops@users.noreply.github.com> --- internal/services/containerapps/container_app_resource_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/services/containerapps/container_app_resource_test.go b/internal/services/containerapps/container_app_resource_test.go index e40dc03420a5..62c294a654ee 100644 --- a/internal/services/containerapps/container_app_resource_test.go +++ b/internal/services/containerapps/container_app_resource_test.go @@ -225,7 +225,7 @@ func TestAccContainerAppResource_removeDaprAppPort(t *testing.T) { { Config: r.completeUpdate_withNoDaprAppPort(data, "rev2"), Check: acceptance.ComposeTestCheckFunc( - check.That(data.ResourceName).Key("dapr.app_port").IsEmpty(), + check.That(data.ResourceName).Key("dapr.0.app_port").IsEmpty(), ), }, data.ImportStep(), From 115dd50d7116c131a97eb403c3af4b10fa20a7a6 Mon Sep 17 00:00:00 2001 From: Paolo Salvatori Date: Mon, 27 Mar 2023 10:19:37 +0200 Subject: [PATCH 8/9] Changed TestAccContainerAppResource_removeDaprAppPort --- internal/services/containerapps/container_app_resource_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/services/containerapps/container_app_resource_test.go b/internal/services/containerapps/container_app_resource_test.go index 62c294a654ee..e40dc03420a5 100644 --- a/internal/services/containerapps/container_app_resource_test.go +++ b/internal/services/containerapps/container_app_resource_test.go @@ -225,7 +225,7 @@ func TestAccContainerAppResource_removeDaprAppPort(t *testing.T) { { Config: r.completeUpdate_withNoDaprAppPort(data, "rev2"), Check: acceptance.ComposeTestCheckFunc( - check.That(data.ResourceName).Key("dapr.0.app_port").IsEmpty(), + check.That(data.ResourceName).Key("dapr.app_port").IsEmpty(), ), }, data.ImportStep(), From 4e099c3332875fdbe555f38dbae490cec0aae9d0 Mon Sep 17 00:00:00 2001 From: Paolo Salvatori Date: Tue, 28 Mar 2023 15:32:09 +0200 Subject: [PATCH 9/9] Changed line 228 as suggested by @jackofallops --- internal/services/containerapps/container_app_resource_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/services/containerapps/container_app_resource_test.go b/internal/services/containerapps/container_app_resource_test.go index e40dc03420a5..9111530ae3cf 100644 --- a/internal/services/containerapps/container_app_resource_test.go +++ b/internal/services/containerapps/container_app_resource_test.go @@ -225,7 +225,7 @@ func TestAccContainerAppResource_removeDaprAppPort(t *testing.T) { { Config: r.completeUpdate_withNoDaprAppPort(data, "rev2"), Check: acceptance.ComposeTestCheckFunc( - check.That(data.ResourceName).Key("dapr.app_port").IsEmpty(), + check.That(data.ResourceName).Key("dapr.0.app_port").HasValue("0"), ), }, data.ImportStep(),