Skip to content

Commit e02a42e

Browse files
authored
Merge pull request #47388 from hashicorp/f-list-apigateway-integration-response
New List Resource: `aws_api_gateway_integration_response`
2 parents 511c95d + 978ad9c commit e02a42e

12 files changed

Lines changed: 572 additions & 2 deletions

File tree

.changelog/47388.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:new-list-resource
2+
aws_api_gateway_integration_response
3+
```

internal/service/apigateway/integration_response.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,15 +145,19 @@ func resourceIntegrationResponseRead(ctx context.Context, d *schema.ResourceData
145145
return sdkdiag.AppendErrorf(diags, "reading API Gateway Integration Response (%s): %s", d.Id(), err)
146146
}
147147

148+
resourceIntegrationResponseFlatten(d, integrationResponse)
149+
150+
return diags
151+
}
152+
153+
func resourceIntegrationResponseFlatten(d *schema.ResourceData, integrationResponse *apigateway.GetIntegrationResponseOutput) {
148154
d.Set("content_handling", integrationResponse.ContentHandling)
149155
d.Set("response_parameters", integrationResponse.ResponseParameters)
150156
// We need to explicitly convert key = nil values into key = "", which aws.StringValueMap() removes.
151157
responseTemplates := make(map[string]string)
152158
maps.Copy(responseTemplates, integrationResponse.ResponseTemplates)
153159
d.Set("response_templates", responseTemplates)
154160
d.Set("selection_pattern", integrationResponse.SelectionPattern)
155-
156-
return diags
157161
}
158162

159163
func resourceIntegrationResponseDelete(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics {
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
// Copyright IBM Corp. 2014, 2026
2+
// SPDX-License-Identifier: MPL-2.0
3+
4+
package apigateway
5+
6+
import (
7+
"context"
8+
"fmt"
9+
10+
"github.com/hashicorp/terraform-plugin-framework/list"
11+
listschema "github.com/hashicorp/terraform-plugin-framework/list/schema"
12+
"github.com/hashicorp/terraform-plugin-framework/types"
13+
"github.com/hashicorp/terraform-plugin-log/tflog"
14+
"github.com/hashicorp/terraform-provider-aws/internal/errs/fwdiag"
15+
"github.com/hashicorp/terraform-provider-aws/internal/framework"
16+
"github.com/hashicorp/terraform-provider-aws/internal/logging"
17+
inttypes "github.com/hashicorp/terraform-provider-aws/internal/types"
18+
"github.com/hashicorp/terraform-provider-aws/names"
19+
)
20+
21+
// Function annotations are used for list resource registration to the Provider. DO NOT EDIT.
22+
// @SDKListResource("aws_api_gateway_integration_response")
23+
func newIntegrationResponseResourceAsListResource() inttypes.ListResourceForSDK {
24+
l := integrationResponseListResource{}
25+
l.SetResourceSchema(resourceIntegrationResponse())
26+
return &l
27+
}
28+
29+
var _ list.ListResource = &integrationResponseListResource{}
30+
var _ list.ListResourceWithRawV5Schemas = &integrationResponseListResource{}
31+
32+
type integrationResponseListResource struct {
33+
framework.ListResourceWithSDKv2Resource
34+
}
35+
36+
func (l *integrationResponseListResource) ListResourceConfigSchema(_ context.Context, _ list.ListResourceSchemaRequest, response *list.ListResourceSchemaResponse) {
37+
response.Schema = listschema.Schema{
38+
Attributes: map[string]listschema.Attribute{
39+
"rest_api_id": listschema.StringAttribute{
40+
Required: true,
41+
Description: "ID of the associated REST API.",
42+
},
43+
names.AttrResourceID: listschema.StringAttribute{
44+
Required: true,
45+
Description: "ID of the API Gateway Resource.",
46+
},
47+
"http_method": listschema.StringAttribute{
48+
Required: true,
49+
Description: "HTTP method of the API Gateway Method.",
50+
},
51+
},
52+
}
53+
}
54+
55+
func (l *integrationResponseListResource) List(ctx context.Context, request list.ListRequest, stream *list.ListResultsStream) {
56+
conn := l.Meta().APIGatewayClient(ctx)
57+
58+
var query listIntegrationResponseModel
59+
if request.Config.Raw.IsKnown() && !request.Config.Raw.IsNull() {
60+
if diags := request.Config.Get(ctx, &query); diags.HasError() {
61+
stream.Results = list.ListResultsStreamDiagnostics(diags)
62+
return
63+
}
64+
}
65+
66+
restAPIID := query.RestAPIID.ValueString()
67+
resourceID := query.ResourceID.ValueString()
68+
httpMethod := query.HTTPMethod.ValueString()
69+
70+
tflog.Info(ctx, "Listing API Gateway Integration Responses", map[string]any{
71+
logging.ResourceAttributeKey("rest_api_id"): restAPIID,
72+
logging.ResourceAttributeKey(names.AttrResourceID): resourceID,
73+
logging.ResourceAttributeKey("http_method"): httpMethod,
74+
})
75+
76+
stream.Results = func(yield func(list.ListResult) bool) {
77+
integration, err := findIntegrationByThreePartKey(ctx, conn, httpMethod, resourceID, restAPIID)
78+
if err != nil {
79+
result := fwdiag.NewListResultErrorDiagnostic(fmt.Errorf("reading API Gateway Integration (%s/%s/%s): %w", restAPIID, resourceID, httpMethod, err))
80+
yield(result)
81+
return
82+
}
83+
84+
for statusCode := range integration.IntegrationResponses {
85+
ctx := tflog.SetField(ctx, logging.ResourceAttributeKey(names.AttrStatusCode), statusCode)
86+
87+
result := request.NewListResult(ctx)
88+
rd := l.ResourceData()
89+
rd.SetId(resourceIntegrationResponseIDAttr(restAPIID, resourceID, httpMethod, statusCode))
90+
rd.Set("rest_api_id", restAPIID)
91+
rd.Set(names.AttrResourceID, resourceID)
92+
rd.Set("http_method", httpMethod)
93+
rd.Set(names.AttrStatusCode, statusCode)
94+
95+
if request.IncludeResource {
96+
integrationResponse, err := findIntegrationResponseByFourPartKey(ctx, conn, httpMethod, resourceID, restAPIID, statusCode)
97+
if err != nil {
98+
tflog.Error(ctx, "Reading API Gateway Integration Response", map[string]any{
99+
"error": err.Error(),
100+
})
101+
continue
102+
}
103+
resourceIntegrationResponseFlatten(rd, integrationResponse)
104+
}
105+
106+
result.DisplayName = fmt.Sprintf("%s %s", httpMethod, statusCode)
107+
108+
l.SetResult(ctx, l.Meta(), request.IncludeResource, rd, &result)
109+
if result.Diagnostics.HasError() {
110+
yield(result)
111+
return
112+
}
113+
114+
if !yield(result) {
115+
return
116+
}
117+
}
118+
}
119+
}
120+
121+
type listIntegrationResponseModel struct {
122+
framework.WithRegionModel
123+
RestAPIID types.String `tfsdk:"rest_api_id"`
124+
ResourceID types.String `tfsdk:"resource_id"`
125+
HTTPMethod types.String `tfsdk:"http_method"`
126+
}
Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
// Copyright IBM Corp. 2014, 2026
2+
// SPDX-License-Identifier: MPL-2.0
3+
4+
package apigateway_test
5+
6+
import (
7+
"testing"
8+
9+
"github.com/YakDriver/regexache"
10+
"github.com/hashicorp/terraform-plugin-testing/config"
11+
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
12+
"github.com/hashicorp/terraform-plugin-testing/knownvalue"
13+
"github.com/hashicorp/terraform-plugin-testing/querycheck"
14+
"github.com/hashicorp/terraform-plugin-testing/statecheck"
15+
"github.com/hashicorp/terraform-plugin-testing/tfjsonpath"
16+
"github.com/hashicorp/terraform-plugin-testing/tfversion"
17+
"github.com/hashicorp/terraform-provider-aws/internal/acctest"
18+
tfquerycheck "github.com/hashicorp/terraform-provider-aws/internal/acctest/querycheck"
19+
tfqueryfilter "github.com/hashicorp/terraform-provider-aws/internal/acctest/queryfilter"
20+
tfstatecheck "github.com/hashicorp/terraform-provider-aws/internal/acctest/statecheck"
21+
"github.com/hashicorp/terraform-provider-aws/names"
22+
)
23+
24+
func TestAccAPIGatewayIntegrationResponse_List_basic(t *testing.T) {
25+
ctx := acctest.Context(t)
26+
27+
resourceName1 := "aws_api_gateway_integration_response.test[0]"
28+
resourceName2 := "aws_api_gateway_integration_response.test[1]"
29+
rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix)
30+
31+
identity1 := tfstatecheck.Identity()
32+
identity2 := tfstatecheck.Identity()
33+
34+
acctest.ParallelTest(ctx, t, resource.TestCase{
35+
TerraformVersionChecks: []tfversion.TerraformVersionCheck{
36+
tfversion.SkipBelow(tfversion.Version1_14_0),
37+
},
38+
PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckAPIGatewayTypeEDGE(t) },
39+
ErrorCheck: acctest.ErrorCheck(t, names.APIGatewayServiceID),
40+
CheckDestroy: testAccCheckIntegrationResponseDestroy(ctx, t),
41+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
42+
Steps: []resource.TestStep{
43+
// Step 1: Setup
44+
{
45+
ConfigDirectory: config.StaticDirectory("testdata/IntegrationResponse/list_basic/"),
46+
ConfigVariables: config.Variables{
47+
acctest.CtRName: config.StringVariable(rName),
48+
"status_codes": config.ListVariable(config.StringVariable("200"), config.StringVariable("400")),
49+
},
50+
ConfigStateChecks: []statecheck.StateCheck{
51+
identity1.GetIdentity(resourceName1),
52+
identity2.GetIdentity(resourceName2),
53+
},
54+
},
55+
// Step 2: Query
56+
{
57+
Query: true,
58+
ConfigDirectory: config.StaticDirectory("testdata/IntegrationResponse/list_basic/"),
59+
ConfigVariables: config.Variables{
60+
acctest.CtRName: config.StringVariable(rName),
61+
"status_codes": config.ListVariable(config.StringVariable("200"), config.StringVariable("400")),
62+
},
63+
QueryResultChecks: []querycheck.QueryResultCheck{
64+
tfquerycheck.ExpectIdentityFunc("aws_api_gateway_integration_response.test", identity1.Checks()),
65+
querycheck.ExpectResourceDisplayName("aws_api_gateway_integration_response.test", tfqueryfilter.ByResourceIdentityFunc(identity1.Checks()), knownvalue.StringRegexp(regexache.MustCompile(`^GET (200|400)$`))),
66+
tfquerycheck.ExpectNoResourceObject("aws_api_gateway_integration_response.test", tfqueryfilter.ByResourceIdentityFunc(identity1.Checks())),
67+
68+
tfquerycheck.ExpectIdentityFunc("aws_api_gateway_integration_response.test", identity2.Checks()),
69+
querycheck.ExpectResourceDisplayName("aws_api_gateway_integration_response.test", tfqueryfilter.ByResourceIdentityFunc(identity2.Checks()), knownvalue.StringRegexp(regexache.MustCompile(`^GET (200|400)$`))),
70+
tfquerycheck.ExpectNoResourceObject("aws_api_gateway_integration_response.test", tfqueryfilter.ByResourceIdentityFunc(identity2.Checks())),
71+
},
72+
},
73+
},
74+
})
75+
}
76+
77+
func TestAccAPIGatewayIntegrationResponse_List_includeResource(t *testing.T) {
78+
ctx := acctest.Context(t)
79+
80+
resourceName1 := "aws_api_gateway_integration_response.test[0]"
81+
rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix)
82+
83+
identity1 := tfstatecheck.Identity()
84+
85+
acctest.ParallelTest(ctx, t, resource.TestCase{
86+
TerraformVersionChecks: []tfversion.TerraformVersionCheck{
87+
tfversion.SkipBelow(tfversion.Version1_14_0),
88+
},
89+
PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckAPIGatewayTypeEDGE(t) },
90+
ErrorCheck: acctest.ErrorCheck(t, names.APIGatewayServiceID),
91+
CheckDestroy: testAccCheckIntegrationResponseDestroy(ctx, t),
92+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
93+
Steps: []resource.TestStep{
94+
// Step 1: Setup
95+
{
96+
ConfigDirectory: config.StaticDirectory("testdata/IntegrationResponse/list_include_resource/"),
97+
ConfigVariables: config.Variables{
98+
acctest.CtRName: config.StringVariable(rName),
99+
"status_codes": config.ListVariable(config.StringVariable("200")),
100+
},
101+
ConfigStateChecks: []statecheck.StateCheck{
102+
identity1.GetIdentity(resourceName1),
103+
},
104+
},
105+
// Step 2: Query
106+
{
107+
Query: true,
108+
ConfigDirectory: config.StaticDirectory("testdata/IntegrationResponse/list_include_resource/"),
109+
ConfigVariables: config.Variables{
110+
acctest.CtRName: config.StringVariable(rName),
111+
"status_codes": config.ListVariable(config.StringVariable("200")),
112+
},
113+
QueryResultChecks: []querycheck.QueryResultCheck{
114+
tfquerycheck.ExpectIdentityFunc("aws_api_gateway_integration_response.test", identity1.Checks()),
115+
querycheck.ExpectResourceDisplayName("aws_api_gateway_integration_response.test", tfqueryfilter.ByResourceIdentityFunc(identity1.Checks()), knownvalue.StringExact("GET 200")),
116+
querycheck.ExpectResourceKnownValues("aws_api_gateway_integration_response.test", tfqueryfilter.ByResourceIdentityFunc(identity1.Checks()), []querycheck.KnownValueCheck{
117+
tfquerycheck.KnownValueCheck(tfjsonpath.New(names.AttrID), knownvalue.NotNull()),
118+
tfquerycheck.KnownValueCheck(tfjsonpath.New("content_handling"), knownvalue.StringExact("")),
119+
tfquerycheck.KnownValueCheck(tfjsonpath.New("http_method"), knownvalue.StringExact("GET")),
120+
tfquerycheck.KnownValueCheck(tfjsonpath.New(names.AttrResourceID), knownvalue.NotNull()),
121+
tfquerycheck.KnownValueCheck(tfjsonpath.New("response_parameters"), knownvalue.MapExact(map[string]knownvalue.Check{})),
122+
tfquerycheck.KnownValueCheck(tfjsonpath.New("response_templates"), knownvalue.MapExact(map[string]knownvalue.Check{})),
123+
tfquerycheck.KnownValueCheck(tfjsonpath.New("rest_api_id"), knownvalue.NotNull()),
124+
tfquerycheck.KnownValueCheck(tfjsonpath.New("selection_pattern"), knownvalue.StringExact("")),
125+
tfquerycheck.KnownValueCheck(tfjsonpath.New(names.AttrStatusCode), knownvalue.StringExact("200")),
126+
}),
127+
},
128+
},
129+
},
130+
})
131+
}
132+
133+
func TestAccAPIGatewayIntegrationResponse_List_regionOverride(t *testing.T) {
134+
ctx := acctest.Context(t)
135+
136+
resourceName1 := "aws_api_gateway_integration_response.test[0]"
137+
resourceName2 := "aws_api_gateway_integration_response.test[1]"
138+
rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix)
139+
140+
identity1 := tfstatecheck.Identity()
141+
identity2 := tfstatecheck.Identity()
142+
143+
acctest.ParallelTest(ctx, t, resource.TestCase{
144+
TerraformVersionChecks: []tfversion.TerraformVersionCheck{
145+
tfversion.SkipBelow(tfversion.Version1_14_0),
146+
},
147+
PreCheck: func() {
148+
acctest.PreCheck(ctx, t)
149+
acctest.PreCheckMultipleRegion(t, 2)
150+
acctest.PreCheckAPIGatewayTypeEDGE(t)
151+
},
152+
ErrorCheck: acctest.ErrorCheck(t, names.APIGatewayServiceID),
153+
CheckDestroy: testAccCheckIntegrationResponseDestroy(ctx, t),
154+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
155+
Steps: []resource.TestStep{
156+
// Step 1: Setup
157+
{
158+
ConfigDirectory: config.StaticDirectory("testdata/IntegrationResponse/list_region_override/"),
159+
ConfigVariables: config.Variables{
160+
acctest.CtRName: config.StringVariable(rName),
161+
"status_codes": config.ListVariable(config.StringVariable("200"), config.StringVariable("400")),
162+
"region": config.StringVariable(acctest.AlternateRegion()),
163+
},
164+
ConfigStateChecks: []statecheck.StateCheck{
165+
identity1.GetIdentity(resourceName1),
166+
identity2.GetIdentity(resourceName2),
167+
},
168+
},
169+
// Step 2: Query
170+
{
171+
Query: true,
172+
ConfigDirectory: config.StaticDirectory("testdata/IntegrationResponse/list_region_override/"),
173+
ConfigVariables: config.Variables{
174+
acctest.CtRName: config.StringVariable(rName),
175+
"status_codes": config.ListVariable(config.StringVariable("200"), config.StringVariable("400")),
176+
"region": config.StringVariable(acctest.AlternateRegion()),
177+
},
178+
QueryResultChecks: []querycheck.QueryResultCheck{
179+
tfquerycheck.ExpectIdentityFunc("aws_api_gateway_integration_response.test", identity1.Checks()),
180+
tfquerycheck.ExpectIdentityFunc("aws_api_gateway_integration_response.test", identity2.Checks()),
181+
},
182+
},
183+
},
184+
})
185+
}

internal/service/apigateway/service_package_gen.go

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)