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 - Add validations for the ingress.0.traffic_weight #24042

Merged
merged 7 commits into from
Jan 8, 2024
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
46 changes: 45 additions & 1 deletion internal/services/containerapps/container_app_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,51 @@ func (r ContainerAppResource) Update() sdk.ResourceFunc {
func (r ContainerAppResource) CustomizeDiff() sdk.ResourceFunc {
return sdk.ResourceFunc{
Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error {
if metadata.ResourceDiff != nil && metadata.ResourceDiff.HasChange("secret") {
if metadata.ResourceDiff == nil {
return nil
}
var app ContainerAppModel
if err := metadata.DecodeDiff(&app); err != nil {
return err
}
// 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`")
}
}
}

if metadata.ResourceDiff.HasChange("secret") {
stateSecretsRaw, configSecretsRaw := metadata.ResourceDiff.GetChange("secret")
stateSecrets := stateSecretsRaw.(*schema.Set).List()
configSecrets := configSecretsRaw.(*schema.Set).List()
Expand Down
Loading
Loading