diff --git a/README.md b/README.md index cc41414..9ff4fbd 100644 --- a/README.md +++ b/README.md @@ -112,14 +112,14 @@ $ terraform apply | Name | Version | |------|---------| | [terraform](#requirement\_terraform) | >= 1.0 | -| [aws](#requirement\_aws) | >= 4.0 | +| [aws](#requirement\_aws) | >= 4.49 | | [random](#requirement\_random) | >= 2.0 | ## Providers | Name | Version | |------|---------| -| [aws](#provider\_aws) | >= 4.0 | +| [aws](#provider\_aws) | >= 4.49 | ## Modules diff --git a/examples/complete/README.md b/examples/complete/README.md index bd777ce..b2e806a 100644 --- a/examples/complete/README.md +++ b/examples/complete/README.md @@ -21,14 +21,14 @@ Note that this example may create resources which cost money. Run `terraform des | Name | Version | |------|---------| | [terraform](#requirement\_terraform) | >= 1.0 | -| [aws](#requirement\_aws) | >= 4.0 | +| [aws](#requirement\_aws) | >= 4.49 | | [random](#requirement\_random) | >= 2.0 | ## Providers | Name | Version | |------|---------| -| [aws](#provider\_aws) | >= 4.0 | +| [aws](#provider\_aws) | >= 4.49 | | [random](#provider\_random) | >= 2.0 | ## Modules diff --git a/examples/complete/main.tf b/examples/complete/main.tf index bde5e1b..93781fa 100644 --- a/examples/complete/main.tf +++ b/examples/complete/main.tf @@ -2,7 +2,6 @@ provider "aws" { region = "eu-west-1" # Make it faster by skipping something - skip_get_ec2_platforms = true skip_metadata_api_check = true skip_region_validation = true skip_credentials_validation = true @@ -16,7 +15,6 @@ provider "aws" { alias = "us-east-1" # Make it faster by skipping something - skip_get_ec2_platforms = true skip_metadata_api_check = true skip_region_validation = true skip_credentials_validation = true @@ -251,6 +249,19 @@ EOF "None", ] } + + "Query.user" = { + kind = "PIPELINE" + type = "Query" + field = "user" + runtime = { + name = "APPSYNC_JS" + } + code = file("src/index.js") + functions = [ + "None", + ] + } } } diff --git a/examples/complete/schema.graphql b/examples/complete/schema.graphql index eed2ad3..8ed7ba2 100644 --- a/examples/complete/schema.graphql +++ b/examples/complete/schema.graphql @@ -7,9 +7,15 @@ type Post { title: String! } +type User { + id: ID! + name: String +} + type Query { singlePost(id: ID!): Post none(dummyString: String!): String! + user(id: ID!): User } schema { diff --git a/examples/complete/src/index.js b/examples/complete/src/index.js new file mode 100644 index 0000000..a1255bb --- /dev/null +++ b/examples/complete/src/index.js @@ -0,0 +1,10 @@ +// For more examples, refer this doc: https://docs.aws.amazon.com/appsync/latest/devguide/configuring-resolvers-js.html +import { util } from "@aws-appsync/utils"; + +export function request(ctx) { + return {}; +} + +export function response(ctx) { + return ctx.result.items; +} diff --git a/examples/complete/versions.tf b/examples/complete/versions.tf index 981f3b1..0d57522 100644 --- a/examples/complete/versions.tf +++ b/examples/complete/versions.tf @@ -4,7 +4,7 @@ terraform { required_providers { aws = { source = "hashicorp/aws" - version = ">= 4.0" + version = ">= 4.49" } random = { source = "hashicorp/random" diff --git a/main.tf b/main.tf index a0f2aad..7650c49 100644 --- a/main.tf +++ b/main.tf @@ -181,8 +181,20 @@ resource "aws_appsync_resolver" "this" { field = each.value.field kind = lookup(each.value, "kind", null) - request_template = lookup(each.value, "request_template", tobool(lookup(each.value, "direct_lambda", false)) ? var.direct_lambda_request_template : "{}") - response_template = lookup(each.value, "response_template", tobool(lookup(each.value, "direct_lambda", false)) ? var.direct_lambda_response_template : "{}") + dynamic "runtime" { + for_each = try([each.value.runtime], []) + + content { + name = runtime.value.name + runtime_version = try(runtime.value.runtime_version, "1.0.0") + } + } + + # code is required when runtime is APPSYNC_JS + code = try(each.value.kind == "PIPELINE" && each.value.runtime.name == "APPSYNC_JS", false) ? each.value.code : null + + request_template = lookup(each.value, "request_template", tobool(lookup(each.value, "direct_lambda", false)) ? var.direct_lambda_request_template : try(each.value.kind == "PIPELINE" && each.value.runtime.name == "APPSYNC_JS", false) ? null : "{}") + response_template = lookup(each.value, "response_template", tobool(lookup(each.value, "direct_lambda", false)) ? var.direct_lambda_response_template : try(each.value.kind == "PIPELINE" && each.value.runtime.name == "APPSYNC_JS", false) ? null : "{}") data_source = lookup(each.value, "data_source", null) != null ? aws_appsync_datasource.this[each.value.data_source].name : lookup(each.value, "data_source_arn", null) diff --git a/outputs.tf b/outputs.tf index 1726a86..d6b266d 100644 --- a/outputs.tf +++ b/outputs.tf @@ -73,5 +73,5 @@ output "appsync_domain_hosted_zone_id" { # Extra output "appsync_graphql_api_fqdns" { description = "Map of FQDNs associated with the API (no protocol and path)" - value = { for k, v in try(aws_appsync_graphql_api.this[0].uris, "") : k => regex("://([^/?#]*)?", v)[0] if length(aws_appsync_graphql_api.this) > 0 } + value = { for k, v in try(aws_appsync_graphql_api.this[0].uris, []) : k => regex("://([^/?#]*)?", v)[0] if length(aws_appsync_graphql_api.this) > 0 } } diff --git a/versions.tf b/versions.tf index 981f3b1..0d57522 100644 --- a/versions.tf +++ b/versions.tf @@ -4,7 +4,7 @@ terraform { required_providers { aws = { source = "hashicorp/aws" - version = ">= 4.0" + version = ">= 4.49" } random = { source = "hashicorp/random"