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_container_app - Correct commands issue with multiple containers (#22984) #23338

Merged
merged 6 commits into from
Sep 21, 2023
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
158 changes: 158 additions & 0 deletions internal/services/containerapps/container_app_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,27 @@ func TestAccContainerAppResource_completeWithSidecar(t *testing.T) {
})
}

func TestAccContainerAppResource_completeWithMultipleContainers(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_container_app", "test")
r := ContainerAppResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.completeWithMultipleContainers(data, "rev1"),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("template.0.container.0.command.0").HasValue("sh"),
check.That(data.ResourceName).Key("template.0.container.0.command.1").HasValue("-c"),
check.That(data.ResourceName).Key("template.0.container.0.command.2").HasValue("CONTAINER=one python3 -m flask run --host=0.0.0.0"),
check.That(data.ResourceName).Key("template.0.container.1.command.0").HasValue("sh"),
check.That(data.ResourceName).Key("template.0.container.1.command.1").HasValue("-c"),
check.That(data.ResourceName).Key("template.0.container.1.command.2").HasValue("CONTAINER=two python3 -m flask run --host=0.0.0.0"),
),
},
data.ImportStep(),
})
}

func TestAccContainerAppResource_completeUpdate(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_container_app", "test")
r := ContainerAppResource{}
Expand Down Expand Up @@ -1059,6 +1080,143 @@ resource "azurerm_container_app" "test" {
`, r.templatePlusExtras(data), data.RandomInteger, revisionSuffix)
}

func (r ContainerAppResource) completeWithMultipleContainers(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-cont1-%[2]d"
image = "jackofallops/azure-containerapps-python-acctest:v0.0.1"
cpu = 0.25
memory = "0.5Gi"
command = ["sh", "-c", "CONTAINER=one python3 -m flask run --host=0.0.0.0"]

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"
}
}

container {
name = "acctest-cont2-%[2]d"
image = "jackofallops/azure-containerapps-python-acctest:v0.0.1"
cpu = 0.25
memory = "0.5Gi"
command = ["sh", "-c", "CONTAINER=two python3 -m flask run --host=0.0.0.0"]

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"
app_port = 5000
app_protocol = "http"
}

tags = {
foo = "Bar"
accTest = "1"
}
}
`, r.templatePlusExtras(data), data.RandomInteger, revisionSuffix)
}

func (r ContainerAppResource) completeChangedSecret(data acceptance.TestData, revisionSuffix string) string {
return fmt.Sprintf(`
%s
Expand Down
4 changes: 2 additions & 2 deletions internal/services/containerapps/helpers/container_apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -1011,10 +1011,10 @@ func expandContainerAppContainers(input []Container) *[]containerapps.Container
VolumeMounts: expandContainerVolumeMounts(v.VolumeMounts),
}
if len(v.Args) != 0 {
container.Args = &v.Args
container.Args = pointer.To(v.Args)
}
if len(v.Command) != 0 {
container.Command = &v.Command
container.Command = pointer.To(v.Command)
}

result = append(result, container)
Expand Down