From 4232ecec8b8731588f916092086189839b028a0c Mon Sep 17 00:00:00 2001 From: jackofallops Date: Fri, 16 Jun 2023 17:16:13 +0200 Subject: [PATCH 1/3] only send storagename if it's defined in config --- internal/services/containerapps/helpers/container_apps.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/internal/services/containerapps/helpers/container_apps.go b/internal/services/containerapps/helpers/container_apps.go index 8d27e7d7746f..fab7d86100e3 100644 --- a/internal/services/containerapps/helpers/container_apps.go +++ b/internal/services/containerapps/helpers/container_apps.go @@ -1109,8 +1109,10 @@ func expandContainerAppVolumes(input []ContainerVolume) *[]containerapps.Volume for _, v := range input { volume := containerapps.Volume{ - Name: pointer.To(v.Name), - StorageName: pointer.To(v.StorageName), + Name: pointer.To(v.Name), + } + if v.StorageName != "" { + volume.StorageName = pointer.To(v.StorageName) } if v.StorageType != "" { storageType := containerapps.StorageType(v.StorageType) From 199da2bc636066673dc4281a1ce66a492cc5456c Mon Sep 17 00:00:00 2001 From: jackofallops Date: Fri, 16 Jun 2023 18:35:02 +0200 Subject: [PATCH 2/3] add test coverage for EmptyDir --- .../container_app_resource_test.go | 111 ++++++++++++++++++ 1 file changed, 111 insertions(+) diff --git a/internal/services/containerapps/container_app_resource_test.go b/internal/services/containerapps/container_app_resource_test.go index de3e64c93a86..81f151faf4d7 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_completeVolumeEmptyDir(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_container_app", "test") + r := ContainerAppResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.completeEmptyDir(data, "rev1"), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + func TestAccContainerAppResource_completeWithNoDaprAppPort(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_container_app", "test") r := ContainerAppResource{} @@ -509,6 +524,102 @@ resource "azurerm_container_app" "test" { `, r.templatePlusExtras(data), data.RandomInteger, revisionSuffix) } +func (r ContainerAppResource) completeEmptyDir(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 = "EmptyDir" + } + + 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" + app_port = 5000 + app_protocol = "http" + } + + tags = { + foo = "Bar" + accTest = "1" + } +} +`, r.templatePlusExtras(data), data.RandomInteger, revisionSuffix) +} + func (r ContainerAppResource) completeWithNoDaprAppPort(data acceptance.TestData, revisionSuffix string) string { return fmt.Sprintf(` %s From 0f98b1599443067135bfe506ed1be0752e9714d9 Mon Sep 17 00:00:00 2001 From: jackofallops Date: Fri, 16 Jun 2023 18:36:24 +0200 Subject: [PATCH 3/3] remove dead code and fixup enums while passing through --- .../containerapps/helpers/container_apps.go | 35 ++----------------- 1 file changed, 3 insertions(+), 32 deletions(-) diff --git a/internal/services/containerapps/helpers/container_apps.go b/internal/services/containerapps/helpers/container_apps.go index fab7d86100e3..8b1e0489bb95 100644 --- a/internal/services/containerapps/helpers/container_apps.go +++ b/internal/services/containerapps/helpers/container_apps.go @@ -665,34 +665,6 @@ func ContainerAppEnvironmentDaprMetadataSchema() *pluginsdk.Schema { } } -func ContainerAppEnvironmentDaprMetadataDataSourceSchema() *pluginsdk.Schema { - return &pluginsdk.Schema{ - Type: pluginsdk.TypeList, - Computed: true, - Elem: &pluginsdk.Resource{ - Schema: map[string]*pluginsdk.Schema{ - "name": { - Type: pluginsdk.TypeString, - Computed: true, - Description: "The name of the Metadata configuration item.", - }, - - "value": { - Type: pluginsdk.TypeString, - Computed: true, - Description: "The value for this metadata configuration item.", - }, - - "secret_name": { - Type: pluginsdk.TypeString, - Computed: true, - Description: "The name of a secret specified in the `secrets` block that contains the value for this metadata configuration item.", - }, - }, - }, - } -} - type ContainerTemplate struct { Containers []Container `tfschema:"container"` Suffix string `tfschema:"revision_suffix"` @@ -1082,10 +1054,9 @@ func ContainerVolumeSchema() *pluginsdk.Schema { Type: pluginsdk.TypeString, Optional: true, Default: "EmptyDir", - ValidateFunc: validation.StringInSlice([]string{ - "EmptyDir", - "AzureFile", - }, false), + ValidateFunc: validation.StringInSlice( + containerapps.PossibleValuesForStorageType(), + false), Description: "The type of storage volume. Possible values include `AzureFile` and `EmptyDir`. Defaults to `EmptyDir`.", },