Skip to content

Commit

Permalink
Merge pull request #40067 from hashicorp/b-apigateway-stage-canary
Browse files Browse the repository at this point in the history
resource/aws_api_gateway_deployment: Reverts validation errors
  • Loading branch information
YakDriver authored Nov 11, 2024
2 parents a6411de + ad31b4d commit 41d2db2
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 15 deletions.
3 changes: 3 additions & 0 deletions .changelog/40067.txt
Original file line number Diff line number Diff line change
@@ -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.
```
52 changes: 40 additions & 12 deletions internal/service/apigateway/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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": {
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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),
),
)
}
11 changes: 8 additions & 3 deletions website/docs/r/api_gateway_deployment.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down

0 comments on commit 41d2db2

Please sign in to comment.