diff --git a/internal/services/containerapps/container_app_resource_test.go b/internal/services/containerapps/container_app_resource_test.go index a43b5544617c..03ba2e6ee6d6 100644 --- a/internal/services/containerapps/container_app_resource_test.go +++ b/internal/services/containerapps/container_app_resource_test.go @@ -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{} @@ -1561,6 +1576,40 @@ 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" + } + } + + ingress { + external_enabled = true + target_port = 5000 + exposed_port = 5555 + transport = "tcp" + + traffic_weight { + latest_revision = true + percentage = 100 + } + } +} +`, r.templateWithVnet(data), data.RandomInteger, revisionSuffix) +} + func (r ContainerAppResource) scaleRules(data acceptance.TestData) string { return fmt.Sprintf(` %s diff --git a/internal/services/containerapps/helpers/container_apps.go b/internal/services/containerapps/helpers/container_apps.go index 61ee769355a1..50a1e8745b90 100644 --- a/internal/services/containerapps/helpers/container_apps.go +++ b/internal/services/containerapps/helpers/container_apps.go @@ -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"` } @@ -192,6 +193,13 @@ 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": { @@ -199,7 +207,7 @@ func ContainerAppIngressSchema() *pluginsdk.Schema { 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`", }, }, }, @@ -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`", }, }, }, @@ -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) @@ -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), } diff --git a/website/docs/r/container_app.html.markdown b/website/docs/r/container_app.html.markdown index 3065081947be..1b3a3f643765 100644 --- a/website/docs/r/container_app.html.markdown +++ b/website/docs/r/container_app.html.markdown @@ -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` ---