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

Add path object to rewrite on gateway route #32449

Merged
merged 5 commits into from
Jul 19, 2023
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
7 changes: 7 additions & 0 deletions .changelog/32449.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:enhancement
resource/aws_gateway_route: Add `path` to the `spec.http_route.action.rewrite` and `spec.http2_route.action.rewrite` configuration blocks
```

```release-note:enhancement
data-source/aws_gateway_route: Add `path` to the `spec.http_route.action.rewrite` and `spec.http2_route.action.rewrite` configuration blocks
```
94 changes: 66 additions & 28 deletions internal/service/appmesh/gateway_route.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,60 +107,51 @@ func resourceGatewayRouteSpecSchema() *schema.Schema {
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"target": {
"rewrite": {
Type: schema.TypeList,
Required: true,
Optional: true,
MinItems: 1,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"port": {
Type: schema.TypeInt,
Optional: true,
ValidateFunc: validation.IsPortNumber,
},
"virtual_service": {
"hostname": {
Type: schema.TypeList,
Required: true,
Optional: true,
MinItems: 1,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"virtual_service_name": {
"default_target_hostname": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringLenBetween(1, 255),
ValidateFunc: validation.StringInSlice([]string{"ENABLED", "DISABLED"}, false),
},
},
},
AtLeastOneOf: []string{
fmt.Sprintf("spec.0.%s.0.action.0.rewrite.0.hostname", attrName),
fmt.Sprintf("spec.0.%s.0.action.0.rewrite.0.path", attrName),
fmt.Sprintf("spec.0.%s.0.action.0.rewrite.0.prefix", attrName),
},
},
},
},
},
"rewrite": {
Type: schema.TypeList,
Optional: true,
MinItems: 1,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"hostname": {
"path": {
Type: schema.TypeList,
Optional: true,
MinItems: 1,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"default_target_hostname": {
"exact": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{"ENABLED", "DISABLED"}, false),
ValidateFunc: validation.StringLenBetween(1, 255),
},
},
},
AtLeastOneOf: []string{
fmt.Sprintf("spec.0.%s.0.action.0.rewrite.0.prefix", attrName),
fmt.Sprintf("spec.0.%s.0.action.0.rewrite.0.hostname", attrName),
fmt.Sprintf("spec.0.%s.0.action.0.rewrite.0.path", attrName),
fmt.Sprintf("spec.0.%s.0.action.0.rewrite.0.prefix", attrName),
},
},
"prefix": {
Expand Down Expand Up @@ -191,8 +182,39 @@ func resourceGatewayRouteSpecSchema() *schema.Schema {
},
},
AtLeastOneOf: []string{
fmt.Sprintf("spec.0.%s.0.action.0.rewrite.0.prefix", attrName),
fmt.Sprintf("spec.0.%s.0.action.0.rewrite.0.hostname", attrName),
fmt.Sprintf("spec.0.%s.0.action.0.rewrite.0.path", attrName),
fmt.Sprintf("spec.0.%s.0.action.0.rewrite.0.prefix", attrName),
},
},
},
},
},
"target": {
Type: schema.TypeList,
Required: true,
MinItems: 1,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"port": {
Type: schema.TypeInt,
Optional: true,
ValidateFunc: validation.IsPortNumber,
},
"virtual_service": {
Type: schema.TypeList,
Required: true,
MinItems: 1,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"virtual_service_name": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringLenBetween(1, 255),
},
},
},
},
},
Expand Down Expand Up @@ -327,8 +349,8 @@ func resourceGatewayRouteSpecSchema() *schema.Schema {
},
},
AtLeastOneOf: []string{
fmt.Sprintf("spec.0.%s.0.match.0.path", attrName),
fmt.Sprintf("spec.0.%s.0.match.0.hostname", attrName),
fmt.Sprintf("spec.0.%s.0.match.0.path", attrName),
fmt.Sprintf("spec.0.%s.0.match.0.prefix", attrName),
},
},
Expand All @@ -342,9 +364,9 @@ func resourceGatewayRouteSpecSchema() *schema.Schema {
Optional: true,
ValidateFunc: validation.StringMatch(regexp.MustCompile(`^/`), "must start with /"),
AtLeastOneOf: []string{
fmt.Sprintf("spec.0.%s.0.match.0.prefix", attrName),
fmt.Sprintf("spec.0.%s.0.match.0.hostname", attrName),
fmt.Sprintf("spec.0.%s.0.match.0.path", attrName),
fmt.Sprintf("spec.0.%s.0.match.0.prefix", attrName),
},
},
"query_parameter": {
Expand Down Expand Up @@ -783,6 +805,15 @@ func expandHTTPGatewayRouteRewrite(vHttpRouteRewrite []interface{}) *appmesh.Htt
routeRewrite.Hostname = routeHostnameRewrite
}

if vRoutePathRewrite, ok := mRouteRewrite["path"].([]interface{}); ok && len(vRoutePathRewrite) > 0 && vRoutePathRewrite[0] != nil {
mRoutePathRewrite := vRoutePathRewrite[0].(map[string]interface{})
routePathRewrite := &appmesh.HttpGatewayRoutePathRewrite{}
if vExact, ok := mRoutePathRewrite["exact"].(string); ok && vExact != "" {
routePathRewrite.Exact = aws.String(vExact)
}
routeRewrite.Path = routePathRewrite
}

if vRoutePrefixRewrite, ok := mRouteRewrite["prefix"].([]interface{}); ok && len(vRoutePrefixRewrite) > 0 && vRoutePrefixRewrite[0] != nil {
mRoutePrefixRewrite := vRoutePrefixRewrite[0].(map[string]interface{})
routePrefixRewrite := &appmesh.HttpGatewayRoutePrefixRewrite{}
Expand Down Expand Up @@ -1136,6 +1167,13 @@ func flattenHTTPGatewayRouteRewrite(routeRewrite *appmesh.HttpGatewayRouteRewrit
mRouteRewrite["hostname"] = []interface{}{mRewriteHostname}
}

if rewritePath := routeRewrite.Path; rewritePath != nil {
mRewritePath := map[string]interface{}{
"exact": aws.StringValue(rewritePath.Exact),
}
mRouteRewrite["path"] = []interface{}{mRewritePath}
}

if rewritePrefix := routeRewrite.Prefix; rewritePrefix != nil {
mRewritePrefix := map[string]interface{}{
"default_prefix": aws.StringValue(rewritePrefix.DefaultPrefix),
Expand Down
Loading