Skip to content

Commit 4b7f0b1

Browse files
chore!: Rename resource aws_appsync_api_cache (#70)
Co-authored-by: Anton Babenko <[email protected]>
1 parent ea0f847 commit 4b7f0b1

File tree

8 files changed

+87
-29
lines changed

8 files changed

+87
-29
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ $ terraform apply
132132

133133
| Name | Version |
134134
|------|---------|
135-
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
135+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3.2 |
136136
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.61.0 |
137137

138138
## Providers
@@ -149,7 +149,7 @@ No modules.
149149

150150
| Name | Type |
151151
|------|------|
152-
| [aws_appsync_api_cache.example](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/appsync_api_cache) | resource |
152+
| [aws_appsync_api_cache.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/appsync_api_cache) | resource |
153153
| [aws_appsync_api_key.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/appsync_api_key) | resource |
154154
| [aws_appsync_datasource.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/appsync_datasource) | resource |
155155
| [aws_appsync_domain_name.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/appsync_domain_name) | resource |

examples/complete/README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,14 @@ Note that this example may create resources which cost money. Run `terraform des
2929
| Name | Version |
3030
|------|---------|
3131
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.1 |
32+
| <a name="provider_aws.us-east-1"></a> [aws.us-east-1](#provider\_aws.us-east-1) | >= 5.1 |
3233
| <a name="provider_random"></a> [random](#provider\_random) | >= 2.0 |
3334

3435
## Modules
3536

3637
| Name | Source | Version |
3738
|------|--------|---------|
38-
| <a name="module_acm"></a> [acm](#module\_acm) | terraform-aws-modules/acm/aws | ~> 3 |
39+
| <a name="module_acm"></a> [acm](#module\_acm) | terraform-aws-modules/acm/aws | ~> 5.0 |
3940
| <a name="module_appsync"></a> [appsync](#module\_appsync) | ../../ | n/a |
4041
| <a name="module_disabled"></a> [disabled](#module\_disabled) | ../../ | n/a |
4142

@@ -48,11 +49,20 @@ Note that this example may create resources which cost money. Run `terraform des
4849
| [aws_route53_record.api](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route53_record) | resource |
4950
| [aws_route53_zone.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route53_zone) | resource |
5051
| [random_pet.this](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/pet) | resource |
52+
| [aws_acm_certificate.existing_certificate](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/acm_certificate) | data source |
53+
| [aws_caller_identity.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source |
54+
| [aws_region.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/region) | data source |
5155
| [aws_route53_zone.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/route53_zone) | data source |
5256

5357
## Inputs
5458

55-
No inputs.
59+
| Name | Description | Type | Default | Required |
60+
|------|-------------|------|---------|:--------:|
61+
| <a name="input_existing_acm_certificate_domain_name"></a> [existing\_acm\_certificate\_domain\_name](#input\_existing\_acm\_certificate\_domain\_name) | Existing ACM certificate domain name | `string` | `"terraform-aws-modules.modules.tf"` | no |
62+
| <a name="input_region"></a> [region](#input\_region) | AWS region where resources will be created | `string` | `"eu-west-1"` | no |
63+
| <a name="input_route53_domain_name"></a> [route53\_domain\_name](#input\_route53\_domain\_name) | Existing Route 53 domain name | `string` | `"terraform-aws-modules.modules.tf"` | no |
64+
| <a name="input_use_existing_acm_certificate"></a> [use\_existing\_acm\_certificate](#input\_use\_existing\_acm\_certificate) | Whether to use an existing ACM certificate | `bool` | `false` | no |
65+
| <a name="input_use_existing_route53_zone"></a> [use\_existing\_route53\_zone](#input\_use\_existing\_route53\_zone) | Whether to use an existing Route 53 zone | `bool` | `true` | no |
5666

5767
## Outputs
5868

examples/complete/main.tf

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
provider "aws" {
2-
region = "eu-west-1"
2+
region = var.region
33

44
# Make it faster by skipping something
55
skip_metadata_api_check = true
@@ -24,60 +24,71 @@ provider "aws" {
2424
}
2525

2626
locals {
27-
# Use existing (via data source) or create new zone (will fail validation, if zone is not reachable)
28-
use_existing_route53_zone = true
29-
30-
domain = "terraform-aws-modules.modules.tf"
31-
3227
# Removing trailing dot from domain - just to be sure :)
33-
domain_name = trimsuffix(local.domain, ".")
28+
route53_domain_name = trimsuffix(var.route53_domain_name, ".")
3429
}
3530

3631
data "aws_route53_zone" "this" {
37-
count = local.use_existing_route53_zone ? 1 : 0
32+
count = var.use_existing_route53_zone ? 1 : 0
3833

39-
name = local.domain_name
34+
name = local.route53_domain_name
4035
private_zone = false
4136
}
4237

4338
resource "aws_route53_zone" "this" {
44-
count = !local.use_existing_route53_zone ? 1 : 0
45-
name = local.domain_name
39+
count = !var.use_existing_route53_zone ? 1 : 0
40+
41+
name = local.route53_domain_name
4642
}
4743

4844
resource "aws_route53_record" "api" {
4945
zone_id = try(data.aws_route53_zone.this[0].zone_id, aws_route53_zone.this[0].zone_id)
50-
name = "api.${local.domain}"
46+
name = "api.${var.route53_domain_name}"
5147
type = "CNAME"
5248
ttl = "300"
5349
records = [module.appsync.appsync_domain_name]
5450
}
5551

52+
data "aws_acm_certificate" "existing_certificate" {
53+
count = var.use_existing_acm_certificate ? 1 : 0
54+
55+
domain = var.existing_acm_certificate_domain_name
56+
57+
provider = aws.us-east-1
58+
}
59+
5660
module "acm" {
61+
count = var.use_existing_acm_certificate ? 0 : 1
62+
5763
source = "terraform-aws-modules/acm/aws"
58-
version = "~> 3"
64+
version = "~> 5.0"
5965

60-
domain_name = local.domain_name
66+
domain_name = local.route53_domain_name
6167
zone_id = try(data.aws_route53_zone.this[0].zone_id, aws_route53_zone.this[0].zone_id)
6268

6369
subject_alternative_names = [
64-
"*.alerts.${local.domain_name}",
65-
"new.sub.${local.domain_name}",
66-
"*.${local.domain_name}",
67-
"alerts.${local.domain_name}",
70+
"*.alerts.${local.route53_domain_name}",
71+
"new.sub.${local.route53_domain_name}",
72+
"*.${local.route53_domain_name}",
73+
"alerts.${local.route53_domain_name}",
6874
]
6975

7076
wait_for_validation = true
7177

78+
validation_method = "DNS"
79+
7280
tags = {
73-
Name = local.domain_name
81+
Name = local.route53_domain_name
7482
}
7583

7684
providers = {
7785
aws = aws.us-east-1
7886
}
7987
}
8088

89+
data "aws_caller_identity" "current" {}
90+
data "aws_region" "current" {}
91+
8192
module "appsync" {
8293
source = "../../"
8394

@@ -94,9 +105,9 @@ module "appsync" {
94105
query_depth_limit = 10
95106
resolver_count_limit = 25
96107

97-
domain_name = "api.${local.domain}"
108+
domain_name = "api.${var.route53_domain_name}"
98109
domain_name_description = "My ${random_pet.this.id} AppSync Domain"
99-
certificate_arn = module.acm.acm_certificate_arn
110+
certificate_arn = var.use_existing_acm_certificate ? data.aws_acm_certificate.existing_certificate[0].arn : module.acm[0].acm_certificate_arn
100111

101112
caching_behavior = "PER_RESOLVER_CACHING"
102113
cache_type = "SMALL"
@@ -147,7 +158,7 @@ module "appsync" {
147158
lambda = {
148159
authentication_type = "AWS_LAMBDA"
149160
lambda_authorizer_config = {
150-
authorizer_uri = "arn:aws:lambda:eu-west-1:835367859851:function:appsync_auth_2"
161+
authorizer_uri = "arn:aws:lambda:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:function:appsync_auth_2"
151162
}
152163
}
153164
}

examples/complete/variables.tf

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
variable "region" {
2+
description = "AWS region where resources will be created"
3+
type = string
4+
default = "eu-west-1"
5+
}
6+
7+
variable "use_existing_route53_zone" {
8+
description = "Whether to use an existing Route 53 zone"
9+
type = bool
10+
default = true
11+
}
12+
13+
variable "route53_domain_name" {
14+
description = "Existing Route 53 domain name"
15+
type = string
16+
default = "terraform-aws-modules.modules.tf"
17+
}
18+
19+
variable "use_existing_acm_certificate" {
20+
description = "Whether to use an existing ACM certificate"
21+
type = bool
22+
default = false
23+
}
24+
25+
variable "existing_acm_certificate_domain_name" {
26+
description = "Existing ACM certificate domain name"
27+
type = string
28+
default = "terraform-aws-modules.modules.tf"
29+
}

main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ resource "aws_appsync_domain_name_api_association" "this" {
129129
}
130130

131131
# API Cache
132-
resource "aws_appsync_api_cache" "example" {
132+
resource "aws_appsync_api_cache" "this" {
133133
count = var.create_graphql_api && var.caching_enabled ? 1 : 0
134134

135135
api_id = aws_appsync_graphql_api.this[0].id

migrations.tf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
################################################################################
2+
# Migrations: v2.6.0 -> v3.0.0
3+
################################################################################
4+
5+
moved {
6+
from = aws_appsync_api_cache.example
7+
to = aws_appsync_api_cache.this
8+
}

versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
terraform {
2-
required_version = ">= 1.0"
2+
required_version = ">= 1.3.2"
33

44
required_providers {
55
aws = {

wrappers/versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
terraform {
2-
required_version = ">= 1.0"
2+
required_version = ">= 1.3.2"
33

44
required_providers {
55
aws = {

0 commit comments

Comments
 (0)