Skip to content

Commit

Permalink
Adds warnings that stage_description and canary_settings have no …
Browse files Browse the repository at this point in the history
…effect when `stage_name` isn't set
  • Loading branch information
gdavison committed Nov 8, 2024
1 parent 12753f8 commit 3d968af
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
27 changes: 27 additions & 0 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 @@ -124,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 @@ -330,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),
),
)
}
2 changes: 2 additions & 0 deletions website/docs/r/api_gateway_deployment.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,11 @@ This resource supports the following arguments:

* `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, **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.
Expand Down

0 comments on commit 3d968af

Please sign in to comment.