Skip to content

Commit c168c1e

Browse files
committed
feat: Add introspection and limit args to aws_appsync_graphql_api
1 parent 62aa986 commit c168c1e

File tree

5 files changed

+185
-0
lines changed

5 files changed

+185
-0
lines changed

.changelog/35631.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
resource/aws_appsync_graphql_api: Add `introspection_config`, `query_depth_limit`, and `resolver_count_limit` arguments
3+
```

internal/service/appsync/appsync_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ func TestAccAppSync_serial(t *testing.T) {
6767
"AdditionalAuthentication_multiple": testAccGraphQLAPI_AdditionalAuthentication_multiple,
6868
"xrayEnabled": testAccGraphQLAPI_xrayEnabled,
6969
"visibility": testAccGraphQLAPI_visibility,
70+
"introspectionConfig": testAccGraphQLAPI_introspectionConfig,
71+
"queryDepthLimit": testAccGraphQLAPI_queryDepthLimit,
72+
"resolverCountLimit": testAccGraphQLAPI_resolverCountLimit,
7073
},
7174
"Function": {
7275
"basic": testAccFunction_basic,

internal/service/appsync/graphql_api.go

+45
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,12 @@ func ResourceGraphQLAPI() *schema.Resource {
136136
Required: true,
137137
ValidateFunc: validation.StringInSlice(appsync.AuthenticationType_Values(), false),
138138
},
139+
"introspection_config": {
140+
Type: schema.TypeString,
141+
Optional: true,
142+
Default: appsync.GraphQLApiIntrospectionConfigEnabled,
143+
ValidateFunc: validation.StringInSlice(appsync.GraphQLApiIntrospectionConfig_Values(), false),
144+
},
139145
"lambda_authorizer_config": {
140146
Type: schema.TypeList,
141147
Optional: true,
@@ -219,6 +225,18 @@ func ResourceGraphQLAPI() *schema.Resource {
219225
},
220226
},
221227
},
228+
"query_depth_limit": {
229+
Type: schema.TypeInt,
230+
Optional: true,
231+
Default: 0,
232+
ValidateFunc: validation.IntBetween(0, 75),
233+
},
234+
"resolver_count_limit": {
235+
Type: schema.TypeInt,
236+
Optional: true,
237+
Default: 0,
238+
ValidateFunc: validation.IntBetween(0, 10000),
239+
},
222240
"schema": {
223241
Type: schema.TypeString,
224242
Optional: true,
@@ -305,6 +323,18 @@ func resourceGraphQLAPICreate(ctx context.Context, d *schema.ResourceData, meta
305323
input.UserPoolConfig = expandGraphQLAPIUserPoolConfig(v.([]interface{}), meta.(*conns.AWSClient).Region)
306324
}
307325

326+
if v, ok := d.GetOk("introspection_config"); ok {
327+
input.IntrospectionConfig = aws.String(v.(string))
328+
}
329+
330+
if v, ok := d.GetOk("query_depth_limit"); ok {
331+
input.QueryDepthLimit = aws.Int64(int64(v.(int)))
332+
}
333+
334+
if v, ok := d.GetOk("resolver_count_limit"); ok {
335+
input.ResolverCountLimit = aws.Int64(int64(v.(int)))
336+
}
337+
308338
if v, ok := d.GetOk("xray_enabled"); ok {
309339
input.XrayEnabled = aws.Bool(v.(bool))
310340
}
@@ -360,7 +390,10 @@ func resourceGraphQLAPIRead(ctx context.Context, d *schema.ResourceData, meta in
360390
if err := d.Set("openid_connect_config", flattenGraphQLAPIOpenIDConnectConfig(api.OpenIDConnectConfig)); err != nil {
361391
return sdkdiag.AppendErrorf(diags, "setting openid_connect_config: %s", err)
362392
}
393+
d.Set("introspection_config", api.IntrospectionConfig)
363394
d.Set("name", api.Name)
395+
d.Set("query_depth_limit", api.QueryDepthLimit)
396+
d.Set("resolver_count_limit", api.ResolverCountLimit)
364397
d.Set("uris", aws.StringValueMap(api.Uris))
365398
if err := d.Set("user_pool_config", flattenGraphQLAPIUserPoolConfig(api.UserPoolConfig)); err != nil {
366399
return sdkdiag.AppendErrorf(diags, "setting user_pool_config: %s", err)
@@ -406,6 +439,18 @@ func resourceGraphQLAPIUpdate(ctx context.Context, d *schema.ResourceData, meta
406439
input.UserPoolConfig = expandGraphQLAPIUserPoolConfig(v.([]interface{}), meta.(*conns.AWSClient).Region)
407440
}
408441

442+
if v, ok := d.GetOk("introspection_config"); ok {
443+
input.IntrospectionConfig = aws.String(v.(string))
444+
}
445+
446+
if v, ok := d.GetOk("query_depth_limit"); ok {
447+
input.QueryDepthLimit = aws.Int64(int64(v.(int)))
448+
}
449+
450+
if v, ok := d.GetOk("resolver_count_limit"); ok {
451+
input.ResolverCountLimit = aws.Int64(int64(v.(int)))
452+
}
453+
409454
if v, ok := d.GetOk("xray_enabled"); ok {
410455
input.XrayEnabled = aws.Bool(v.(bool))
411456
}

internal/service/appsync/graphql_api_test.go

+117
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ func testAccGraphQLAPI_basic(t *testing.T) {
4949
resource.TestCheckResourceAttr(resourceName, "additional_authentication_provider.#", "0"),
5050
resource.TestCheckResourceAttr(resourceName, "xray_enabled", "false"),
5151
resource.TestCheckResourceAttr(resourceName, "visibility", "GLOBAL"),
52+
resource.TestCheckResourceAttr(resourceName, "introspection_config", "ENABLED"),
53+
resource.TestCheckResourceAttr(resourceName, "query_depth_limit", "0"),
54+
resource.TestCheckResourceAttr(resourceName, "resolver_count_limit", "0"),
5255
),
5356
},
5457
{
@@ -1208,6 +1211,90 @@ func testAccGraphQLAPI_visibility(t *testing.T) {
12081211
})
12091212
}
12101213

1214+
func testAccGraphQLAPI_introspectionConfig(t *testing.T) {
1215+
ctx := acctest.Context(t)
1216+
var api1 appsync.GraphqlApi
1217+
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
1218+
resourceName := "aws_appsync_graphql_api.test"
1219+
1220+
resource.Test(t, resource.TestCase{
1221+
PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckPartitionHasService(t, appsync.EndpointsID) },
1222+
ErrorCheck: acctest.ErrorCheck(t, appsync.EndpointsID),
1223+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
1224+
CheckDestroy: testAccCheckGraphQLAPIDestroy(ctx),
1225+
Steps: []resource.TestStep{
1226+
{
1227+
Config: testAccGraphQLAPIConfig_introspectionConfig(rName, "DISABLED"),
1228+
Check: resource.ComposeTestCheckFunc(
1229+
testAccCheckGraphQLAPIExists(ctx, resourceName, &api1),
1230+
resource.TestCheckResourceAttr(resourceName, "introspection_config", "DISABLED"),
1231+
),
1232+
},
1233+
{
1234+
ResourceName: resourceName,
1235+
ImportState: true,
1236+
ImportStateVerify: true,
1237+
},
1238+
},
1239+
})
1240+
}
1241+
1242+
func testAccGraphQLAPI_queryDepthLimit(t *testing.T) {
1243+
ctx := acctest.Context(t)
1244+
var api1 appsync.GraphqlApi
1245+
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
1246+
resourceName := "aws_appsync_graphql_api.test"
1247+
1248+
resource.Test(t, resource.TestCase{
1249+
PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckPartitionHasService(t, appsync.EndpointsID) },
1250+
ErrorCheck: acctest.ErrorCheck(t, appsync.EndpointsID),
1251+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
1252+
CheckDestroy: testAccCheckGraphQLAPIDestroy(ctx),
1253+
Steps: []resource.TestStep{
1254+
{
1255+
Config: testAccGraphQLAPIConfig_queryDepthLimit(rName, 2),
1256+
Check: resource.ComposeTestCheckFunc(
1257+
testAccCheckGraphQLAPIExists(ctx, resourceName, &api1),
1258+
resource.TestCheckResourceAttr(resourceName, "query_depth_limit", "2"),
1259+
),
1260+
},
1261+
{
1262+
ResourceName: resourceName,
1263+
ImportState: true,
1264+
ImportStateVerify: true,
1265+
},
1266+
},
1267+
})
1268+
}
1269+
1270+
func testAccGraphQLAPI_resolverCountLimit(t *testing.T) {
1271+
ctx := acctest.Context(t)
1272+
var api1 appsync.GraphqlApi
1273+
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
1274+
resourceName := "aws_appsync_graphql_api.test"
1275+
1276+
resource.Test(t, resource.TestCase{
1277+
PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckPartitionHasService(t, appsync.EndpointsID) },
1278+
ErrorCheck: acctest.ErrorCheck(t, appsync.EndpointsID),
1279+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
1280+
CheckDestroy: testAccCheckGraphQLAPIDestroy(ctx),
1281+
Steps: []resource.TestStep{
1282+
{
1283+
Config: testAccGraphQLAPIConfig_resolverCountLimit(rName, 2),
1284+
Check: resource.ComposeTestCheckFunc(
1285+
testAccCheckGraphQLAPIExists(ctx, resourceName, &api1),
1286+
resource.TestCheckResourceAttr(resourceName, "resolver_count_limit", "2"),
1287+
),
1288+
},
1289+
{
1290+
ResourceName: resourceName,
1291+
ImportState: true,
1292+
ImportStateVerify: true,
1293+
},
1294+
},
1295+
})
1296+
}
1297+
12111298
func testAccCheckGraphQLAPIDestroy(ctx context.Context) resource.TestCheckFunc {
12121299
return func(s *terraform.State) error {
12131300
conn := acctest.Provider.Meta().(*conns.AWSClient).AppSyncConn(ctx)
@@ -1707,3 +1794,33 @@ resource "aws_appsync_graphql_api" "test" {
17071794
}
17081795
`, rName, xrayEnabled)
17091796
}
1797+
1798+
func testAccGraphQLAPIConfig_introspectionConfig(rName, introspectionConfig string) string {
1799+
return fmt.Sprintf(`
1800+
resource "aws_appsync_graphql_api" "test" {
1801+
authentication_type = "API_KEY"
1802+
name = %[1]q
1803+
introspection_config = %[2]q
1804+
}
1805+
`, rName, introspectionConfig)
1806+
}
1807+
1808+
func testAccGraphQLAPIConfig_queryDepthLimit(rName string, queryDepthLimit int) string {
1809+
return fmt.Sprintf(`
1810+
resource "aws_appsync_graphql_api" "test" {
1811+
authentication_type = "API_KEY"
1812+
name = %[1]q
1813+
query_depth_limit = %[2]d
1814+
}
1815+
`, rName, queryDepthLimit)
1816+
}
1817+
1818+
func testAccGraphQLAPIConfig_resolverCountLimit(rName string, resolverCountLimit int) string {
1819+
return fmt.Sprintf(`
1820+
resource "aws_appsync_graphql_api" "test" {
1821+
authentication_type = "API_KEY"
1822+
name = %[1]q
1823+
resolver_count_limit = %[2]d
1824+
}
1825+
`, rName, resolverCountLimit)
1826+
}

website/docs/r/appsync_graphql_api.html.markdown

+17
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,18 @@ resource "aws_wafv2_web_acl" "example" {
198198
}
199199
```
200200

201+
### GraphQL run complexity, query depth, and introspection
202+
203+
```terraform
204+
resource "aws_appsync_graphql_api" "example" {
205+
authentication_type = "AWS_IAM"
206+
name = "example"
207+
introspection_config = "ENABLED"
208+
query_depth_limit = 2
209+
resolver_count_limit = 2
210+
}
211+
```
212+
201213
## Argument Reference
202214

203215
This resource supports the following arguments:
@@ -210,6 +222,11 @@ This resource supports the following arguments:
210222
* `lambda_authorizer_config` - (Optional) Nested argument containing Lambda authorizer configuration. Defined below.
211223
* `schema` - (Optional) Schema definition, in GraphQL schema language format. Terraform cannot perform drift detection of this configuration.
212224
* `additional_authentication_provider` - (Optional) One or more additional authentication providers for the GraphqlApi. Defined below.
225+
* `introspection_config` - (Optional) Sets the value of the GraphQL API to enable (`ENABLED`) or disable (`DISABLED`) introspection. If no value is provided, the introspection configuration will be set to ENABLED by default. This field will produce an error if the operation attempts to use the introspection feature while this field is disabled. For more information about introspection, see [GraphQL introspection](https://graphql.org/learn/introspection/).
226+
* `query_depth_limit` - (Optional) The maximum depth a query can have in a single request. Depth refers to the amount of nested levels allowed in the body of query. The default value is `0` (or unspecified), which indicates there's no depth limit. If you set a limit, it can be between `1` and `75` nested levels. This field will produce a limit error if the operation falls out of bounds.
227+
228+
Note that fields can still be set to nullable or non-nullable. If a non-nullable field produces an error, the error will be thrown upwards to the first nullable field available.
229+
* `resolver_count_limit` - (Optional) The maximum number of resolvers that can be invoked in a single request. The default value is `0` (or unspecified), which will set the limit to `10000`. When specified, the limit value can be between `1` and `10000`. This field will produce a limit error if the operation falls out of bounds.
213230
* `tags` - (Optional) Map of tags to assign to the resource. If configured with a provider [`default_tags` configuration block](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#default_tags-configuration-block) present, tags with matching keys will overwrite those defined at the provider-level.
214231
* `xray_enabled` - (Optional) Whether tracing with X-ray is enabled. Defaults to false.
215232
* `visibility` - (Optional) Sets the value of the GraphQL API to public (`GLOBAL`) or private (`PRIVATE`). If no value is provided, the visibility will be set to `GLOBAL` by default. This value cannot be changed once the API has been created.

0 commit comments

Comments
 (0)