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

Support for TCP type & ExposedPort on azurerm_container_app #23752

Merged
merged 7 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
112 changes: 112 additions & 0 deletions internal/services/containerapps/container_app_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,21 @@ func TestAccContainerAppResource_completeUpdate(t *testing.T) {
})
}

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

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.completeTcpExposedPort(data, "rev1"),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

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

func (r ContainerAppResource) completeTcpExposedPort(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 {
external_enabled = true
target_port = 5000
exposed_port = 5555
transport = "tcp"
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) scaleRules(data acceptance.TestData) string {
return fmt.Sprintf(`
%s
Expand Down
20 changes: 18 additions & 2 deletions internal/services/containerapps/helpers/container_apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ type Ingress struct {
IsExternal bool `tfschema:"external_enabled"`
FQDN string `tfschema:"fqdn"`
TargetPort int `tfschema:"target_port"`
ExposedPort int `tfschema:"exposed_port"`
TrafficWeights []TrafficWeight `tfschema:"traffic_weight"`
Transport string `tfschema:"transport"`
}
Expand Down Expand Up @@ -192,14 +193,21 @@ func ContainerAppIngressSchema() *pluginsdk.Schema {
Description: "The target port on the container for the Ingress traffic.",
},

"exposed_port": {
Type: pluginsdk.TypeInt,
Optional: true,
ValidateFunc: validation.IntBetween(1, 65535),
Description: "The exposed port on the container for the Ingress traffic.",
},

"traffic_weight": ContainerAppIngressTrafficWeight(),

"transport": {
Type: pluginsdk.TypeString,
Optional: true,
Default: string(containerapps.IngressTransportMethodAuto),
ValidateFunc: validation.StringInSlice(containerapps.PossibleValuesForIngressTransportMethod(), false),
Description: "The transport method for the Ingress. Possible values include `auto`, `http`, and `http2`. Defaults to `auto`",
Description: "The transport method for the Ingress. Possible values include `auto`, `http`, and `http2`, `tcp`. Defaults to `auto`",
},
},
},
Expand Down Expand Up @@ -238,12 +246,18 @@ func ContainerAppIngressSchemaComputed() *pluginsdk.Schema {
Description: "The target port on the container for the Ingress traffic.",
},

"exposed_port": {
Type: pluginsdk.TypeInt,
Computed: true,
Description: "The exposed port on the container for the Ingress traffic.",
},

"traffic_weight": ContainerAppIngressTrafficWeightComputed(),

"transport": {
Type: pluginsdk.TypeString,
Computed: true,
Description: "The transport method for the Ingress. Possible values include `auto`, `http`, and `http2`. Defaults to `auto`",
Description: "The transport method for the Ingress. Possible values include `auto`, `http`, and `http2`, `tcp`. Defaults to `auto`",
},
},
},
Expand All @@ -262,6 +276,7 @@ func ExpandContainerAppIngress(input []Ingress, appName string) *containerapps.I
External: pointer.To(ingress.IsExternal),
Fqdn: pointer.To(ingress.FQDN),
TargetPort: pointer.To(int64(ingress.TargetPort)),
ExposedPort: pointer.To(int64(ingress.ExposedPort)),
Traffic: expandContainerAppIngressTraffic(ingress.TrafficWeights, appName),
}
transport := containerapps.IngressTransportMethod(ingress.Transport)
Expand All @@ -282,6 +297,7 @@ func FlattenContainerAppIngress(input *containerapps.Ingress, appName string) []
IsExternal: pointer.From(ingress.External),
FQDN: pointer.From(ingress.Fqdn),
TargetPort: int(pointer.From(ingress.TargetPort)),
ExposedPort: int(pointer.From(ingress.ExposedPort)),
TrafficWeights: flattenContainerAppIngressTraffic(ingress.Traffic, appName),
}

Expand Down
6 changes: 5 additions & 1 deletion website/docs/r/container_app.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -338,12 +338,16 @@ An `ingress` block supports the following:
* `external_enabled` - (Optional) Are connections to this Ingress from outside the Container App Environment enabled? Defaults to `false`.

* `target_port` - (Required) The target port on the container for the Ingress traffic.

* `exposed_port` - (Required) The exposed port on the container for the Ingress traffic.

~> **Note:** `exposed_port` can only be specified when `transport` is set to `tcp`.

* `traffic_weight` - (Required) A `traffic_weight` block as detailed below.

~> **Note:** `traffic_weight` can only be specified when `revision_mode` is set to `Multiple`.

* `transport` - (Optional) The transport method for the Ingress. Possible values include `auto`, `http`, and `http2`. Defaults to `auto`
* `transport` - (Optional) The transport method for the Ingress. Possible values include `auto`, `http`, `http2` and `tcp`. Defaults to `auto`

---

Expand Down