Skip to content

Commit

Permalink
Support for TCP type & ExposedPort on azurerm_container_app (#23752)
Browse files Browse the repository at this point in the history
* Support for TCP type & ExposedPort on azurerm_container_app

* fix ingress

* fix test

* remove allow_insecure_connections from tcp test

* documentation

* vnet fix

* fix spacing
  • Loading branch information
SpartakusMd authored Nov 2, 2023
1 parent 5440ab3 commit 233c40d
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 3 deletions.
49 changes: 49 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,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
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

0 comments on commit 233c40d

Please sign in to comment.