diff --git a/.changelog/40067.txt b/.changelog/40067.txt new file mode 100644 index 00000000000..15f335d7df4 --- /dev/null +++ b/.changelog/40067.txt @@ -0,0 +1,3 @@ +```release-note:bug +resource/aws_api_gateway_deployment: Rolls back validation of `canary_settings` and `stage_description` when `stage_name` not set. +``` diff --git a/internal/service/apigateway/deployment.go b/internal/service/apigateway/deployment.go index 086d37a8fa2..1a101fba8fe 100644 --- a/internal/service/apigateway/deployment.go +++ b/internal/service/apigateway/deployment.go @@ -14,6 +14,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/arn" "github.com/aws/aws-sdk-go-v2/service/apigateway" "github.com/aws/aws-sdk-go-v2/service/apigateway/types" + "github.com/hashicorp/go-cty/cty" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -47,11 +48,10 @@ func resourceDeployment() *schema.Resource { Optional: true, }, "canary_settings": { - Type: schema.TypeList, - Optional: true, - ForceNew: true, - MaxItems: 1, - RequiredWith: []string{"stage_name"}, + Type: schema.TypeList, + Optional: true, + ForceNew: true, + MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "percent_traffic": { @@ -70,6 +70,7 @@ func resourceDeployment() *schema.Resource { }, }, }, + Deprecated: `The attribute "canary_settings" will be removed in a future major version. Use an explicit "aws_api_gateway_stage" instead.`, }, "execution_arn": { Type: schema.TypeString, @@ -85,15 +86,16 @@ func resourceDeployment() *schema.Resource { ForceNew: true, }, "stage_description": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, - RequiredWith: []string{"stage_name"}, + Type: schema.TypeString, + Optional: true, + ForceNew: true, + Deprecated: `The attribute "stage_description" will be removed in a future major version. Use an explicit "aws_api_gateway_stage" instead.`, }, "stage_name": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, + Type: schema.TypeString, + Optional: true, + ForceNew: true, + Deprecated: `The attribute "stage_name" will be removed in a future major version. Use an explicit "aws_api_gateway_stage" instead.`, }, names.AttrTriggers: { Type: schema.TypeMap, @@ -123,8 +125,23 @@ func resourceDeploymentCreate(ctx context.Context, d *schema.ResourceData, meta Variables: flex.ExpandStringValueMap(d.Get("variables").(map[string]interface{})), } + _, hasStageName := d.GetOk("stage_name") + + if _, ok := d.GetOk("stage_description"); !hasStageName && ok { + diags = append(diags, noEffectWithoutWarningDiag( + cty.GetAttrPath("stage_description"), + cty.GetAttrPath("stage_name"), + )) + } + if v, ok := d.GetOk("canary_settings"); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil { input.CanarySettings = expandDeploymentCanarySettings(v.([]interface{})[0].(map[string]interface{})) + if !hasStageName { + diags = append(diags, noEffectWithoutWarningDiag( + cty.GetAttrPath("canary_settings"), + cty.GetAttrPath("stage_name"), + )) + } } deployment, err := conn.CreateDeployment(ctx, input) @@ -329,3 +346,14 @@ func expandDeploymentCanarySettings(tfMap map[string]interface{}) *types.Deploym return apiObject } + +func noEffectWithoutWarningDiag(path, otherPath cty.Path) diag.Diagnostic { + return errs.NewAttributeWarningDiagnostic( + path, + "Invalid Attribute Combination", + fmt.Sprintf("Attribute %q has no effect when %q is not set.", + errs.PathString(path), + errs.PathString(otherPath), + ), + ) +} diff --git a/website/docs/r/api_gateway_deployment.html.markdown b/website/docs/r/api_gateway_deployment.html.markdown index 069fa3bca85..e75e98fee02 100644 --- a/website/docs/r/api_gateway_deployment.html.markdown +++ b/website/docs/r/api_gateway_deployment.html.markdown @@ -130,11 +130,16 @@ resource "aws_api_gateway_stage" "example" { This resource supports the following arguments: -* `canary_settings` - (Optional) Input configuration for the canary deployment when the deployment is a canary release deployment. See [`canary_settings](#canary_settings-argument-reference) below. +* `canary_settings` - (Optional, **Deprecated** Use an explicit [`aws_api_gateway_stage` resource](api_gateway_stage.html) instead) Input configuration for the canary deployment when the deployment is a canary release deployment. + See [`canary_settings](#canary_settings-argument-reference) below. + Has no effect when `stage_name` is not set. * `description` - (Optional) Description of the deployment * `rest_api_id` - (Required) REST API identifier. -* `stage_description` - (Optional) Description to set on the stage managed by the `stage_name` argument. -* `stage_name` - (Optional) Name of the stage to create with this deployment. If the specified stage already exists, it will be updated to point to the new deployment. We recommend using the [`aws_api_gateway_stage` resource](api_gateway_stage.html) instead to manage stages. +* `stage_description` - (Optional, **Deprecated** Use an explicit [`aws_api_gateway_stage` resource](api_gateway_stage.html) instead) Description to set on the stage managed by the `stage_name` argument. + Has no effect when `stage_name` is not set. +* `stage_name` - (Optional, **Deprecated** Use an explicit [`aws_api_gateway_stage` resource](api_gateway_stage.html) instead) Name of the stage to create with this deployment. + If the specified stage already exists, it will be updated to point to the new deployment. + We recommend using the [`aws_api_gateway_stage` resource](api_gateway_stage.html) instead to manage stages. * `triggers` - (Optional) Map of arbitrary keys and values that, when changed, will trigger a redeployment. To force a redeployment without changing these keys/values, use the [`-replace` option](https://developer.hashicorp.com/terraform/cli/commands/plan#replace-address) with `terraform plan` or `terraform apply`. * `variables` - (Optional) Map to set on the stage managed by the `stage_name` argument.