Skip to content

Commit

Permalink
azurerm_container_app - fix bug in Container Volume for EmptyDir (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jackofallops authored Jun 17, 2023
1 parent 8bc0e56 commit 53ef2b2
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 34 deletions.
111 changes: 111 additions & 0 deletions internal/services/containerapps/container_app_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down Expand Up @@ -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
Expand Down
41 changes: 7 additions & 34 deletions internal/services/containerapps/helpers/container_apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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`.",
},

Expand All @@ -1109,8 +1080,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)
Expand Down

0 comments on commit 53ef2b2

Please sign in to comment.