diff --git a/internal/services/containerapps/container_app_resource.go b/internal/services/containerapps/container_app_resource.go index 2bfc598948f3..d83027d24eea 100644 --- a/internal/services/containerapps/container_app_resource.go +++ b/internal/services/containerapps/container_app_resource.go @@ -440,36 +440,10 @@ func (r ContainerAppResource) CustomizeDiff() sdk.ResourceFunc { // Ingress traffic weight validations if len(app.Ingress) != 0 { ingress := app.Ingress[0] - if metadata.ResourceDiff.HasChange("name") { - // Validation for create time - // (Above is a trick to tell whether this is for a new create apply, as the "name" is a force new property) - if len(ingress.TrafficWeights) != 0 { - if len(ingress.TrafficWeights) > 1 { - return fmt.Errorf("at most one `ingress.0.traffic_weight` can be specified during creation") - } - tw := ingress.TrafficWeights[0] - if !tw.LatestRevision { - return fmt.Errorf("`ingress.0.traffic_weight.0.latest_revision` must be set to true during creation") - } - if tw.RevisionSuffix != "" { - return fmt.Errorf("`ingress.0.traffic_weight.0.revision_suffix` must not be set during creation") - } - } - } else { - // Validation for update time - var latestRevCount int - for i, tw := range ingress.TrafficWeights { - if tw.LatestRevision { - latestRevCount++ - if tw.RevisionSuffix != "" { - return fmt.Errorf("`ingress.0.traffic_weight.%[1]d.revision_suffix` conflicts with `ingress.0.traffic_weight.%[1]d.latest_revision`", i) - } - } else if tw.RevisionSuffix == "" { - return fmt.Errorf("`ingress.0.traffic_weight.%[1]d.revision_suffix` is not specified", i) - } - } - if latestRevCount > 1 { - return fmt.Errorf("more than one `ingress.0.traffic_weight` has `latest_revision` set to `true`") + + for i, tw := range ingress.TrafficWeights { + if !tw.LatestRevision && tw.RevisionSuffix == "" { + return fmt.Errorf("`either ingress.0.traffic_weight.%[1]d.revision_suffix` or `ingress.0.traffic_weight.%[1]d.latest_revision` should be specified", i) } } } diff --git a/internal/services/containerapps/container_app_resource_test.go b/internal/services/containerapps/container_app_resource_test.go index fbc03d535314..b98919252059 100644 --- a/internal/services/containerapps/container_app_resource_test.go +++ b/internal/services/containerapps/container_app_resource_test.go @@ -570,16 +570,8 @@ func TestAccContainerAppResource_ingressTrafficValidation(t *testing.T) { data.ResourceTest(t, r, []acceptance.TestStep{ { - Config: r.ingressTrafficValidation(data, r.trafficBlockMoreThanOne()), - ExpectError: regexp.MustCompile(fmt.Sprintf(`at most one %s can be specified during creation`, "`ingress.0.traffic_weight`")), - }, - { - Config: r.ingressTrafficValidation(data, r.trafficBlockLatestRevisionNotSet()), - ExpectError: regexp.MustCompile(fmt.Sprintf(`%s must be set to true during creation`, "`ingress.0.traffic_weight.0.latest_revision`")), - }, - { - Config: r.ingressTrafficValidation(data, r.trafficBlockRevisionSuffixSet()), - ExpectError: regexp.MustCompile(fmt.Sprintf(`%s must not be set during creation`, "`ingress.0.traffic_weight.0.revision_suffix`")), + Config: r.ingressTrafficValidation(data, r.latestRevisionFalseRevisionSuffixEmpty()), + ExpectError: regexp.MustCompile("`either ingress.0.traffic_weight.0.revision_suffix` or `ingress.0.traffic_weight.0.latest_revision` should be specified"), }, }) } @@ -2832,31 +2824,11 @@ resource "azurerm_container_app" "test" { `, r.template(data), data.RandomInteger) } -func (r ContainerAppResource) trafficBlockMoreThanOne() string { - return ` -traffic_weight { - percentage = 50 -} -traffic_weight { - percentage = 50 -} -` -} - -func (r ContainerAppResource) trafficBlockLatestRevisionNotSet() string { +func (r ContainerAppResource) latestRevisionFalseRevisionSuffixEmpty() string { return ` traffic_weight { + latest_revision = false percentage = 100 } ` } - -func (r ContainerAppResource) trafficBlockRevisionSuffixSet() string { - return ` -traffic_weight { - percentage = 100 - latest_revision = true - revision_suffix = "foo" -} -` -} diff --git a/website/docs/r/container_app.html.markdown b/website/docs/r/container_app.html.markdown index 6d71cb9be01e..589b63acca2c 100644 --- a/website/docs/r/container_app.html.markdown +++ b/website/docs/r/container_app.html.markdown @@ -415,7 +415,7 @@ A `traffic_weight` block supports the following: * `revision_suffix` - (Optional) The suffix string to which this `traffic_weight` applies. -~> **Note:** `latest_revision` conflicts with `revision_suffix`, which means you shall either set `latest_revision` to `true` or specify `revision_suffix`. Especially for creation, there shall only be one `traffic_weight`, with the `latest_revision` set to `true`, and leave the `revision_suffix` empty. +~> **Note:** If `latest_revision` is `false`, the `revision_suffix` shall be specified. * `percentage` - (Required) The percentage of traffic which should be sent this revision.