Skip to content

Commit

Permalink
chore!: Rename resource aws_appsync_api_cache (#70)
Browse files Browse the repository at this point in the history
Co-authored-by: Anton Babenko <[email protected]>
  • Loading branch information
taufort and antonbabenko authored Jan 9, 2025
1 parent ea0f847 commit 4b7f0b1
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 29 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ $ terraform apply

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

## Providers
Expand All @@ -149,7 +149,7 @@ No modules.

| Name | Type |
|------|------|
| [aws_appsync_api_cache.example](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/appsync_api_cache) | resource |
| [aws_appsync_api_cache.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/appsync_api_cache) | resource |
| [aws_appsync_api_key.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/appsync_api_key) | resource |
| [aws_appsync_datasource.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/appsync_datasource) | resource |
| [aws_appsync_domain_name.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/appsync_domain_name) | resource |
Expand Down
14 changes: 12 additions & 2 deletions examples/complete/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@ Note that this example may create resources which cost money. Run `terraform des
| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.1 |
| <a name="provider_aws.us-east-1"></a> [aws.us-east-1](#provider\_aws.us-east-1) | >= 5.1 |
| <a name="provider_random"></a> [random](#provider\_random) | >= 2.0 |

## Modules

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

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

## Inputs

No inputs.
| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <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 |
| <a name="input_region"></a> [region](#input\_region) | AWS region where resources will be created | `string` | `"eu-west-1"` | no |
| <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 |
| <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 |
| <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 |

## Outputs

Expand Down
55 changes: 33 additions & 22 deletions examples/complete/main.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
provider "aws" {
region = "eu-west-1"
region = var.region

# Make it faster by skipping something
skip_metadata_api_check = true
Expand All @@ -24,60 +24,71 @@ provider "aws" {
}

locals {
# Use existing (via data source) or create new zone (will fail validation, if zone is not reachable)
use_existing_route53_zone = true

domain = "terraform-aws-modules.modules.tf"

# Removing trailing dot from domain - just to be sure :)
domain_name = trimsuffix(local.domain, ".")
route53_domain_name = trimsuffix(var.route53_domain_name, ".")
}

data "aws_route53_zone" "this" {
count = local.use_existing_route53_zone ? 1 : 0
count = var.use_existing_route53_zone ? 1 : 0

name = local.domain_name
name = local.route53_domain_name
private_zone = false
}

resource "aws_route53_zone" "this" {
count = !local.use_existing_route53_zone ? 1 : 0
name = local.domain_name
count = !var.use_existing_route53_zone ? 1 : 0

name = local.route53_domain_name
}

resource "aws_route53_record" "api" {
zone_id = try(data.aws_route53_zone.this[0].zone_id, aws_route53_zone.this[0].zone_id)
name = "api.${local.domain}"
name = "api.${var.route53_domain_name}"
type = "CNAME"
ttl = "300"
records = [module.appsync.appsync_domain_name]
}

data "aws_acm_certificate" "existing_certificate" {
count = var.use_existing_acm_certificate ? 1 : 0

domain = var.existing_acm_certificate_domain_name

provider = aws.us-east-1
}

module "acm" {
count = var.use_existing_acm_certificate ? 0 : 1

source = "terraform-aws-modules/acm/aws"
version = "~> 3"
version = "~> 5.0"

domain_name = local.domain_name
domain_name = local.route53_domain_name
zone_id = try(data.aws_route53_zone.this[0].zone_id, aws_route53_zone.this[0].zone_id)

subject_alternative_names = [
"*.alerts.${local.domain_name}",
"new.sub.${local.domain_name}",
"*.${local.domain_name}",
"alerts.${local.domain_name}",
"*.alerts.${local.route53_domain_name}",
"new.sub.${local.route53_domain_name}",
"*.${local.route53_domain_name}",
"alerts.${local.route53_domain_name}",
]

wait_for_validation = true

validation_method = "DNS"

tags = {
Name = local.domain_name
Name = local.route53_domain_name
}

providers = {
aws = aws.us-east-1
}
}

data "aws_caller_identity" "current" {}
data "aws_region" "current" {}

module "appsync" {
source = "../../"

Expand All @@ -94,9 +105,9 @@ module "appsync" {
query_depth_limit = 10
resolver_count_limit = 25

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

caching_behavior = "PER_RESOLVER_CACHING"
cache_type = "SMALL"
Expand Down Expand Up @@ -147,7 +158,7 @@ module "appsync" {
lambda = {
authentication_type = "AWS_LAMBDA"
lambda_authorizer_config = {
authorizer_uri = "arn:aws:lambda:eu-west-1:835367859851:function:appsync_auth_2"
authorizer_uri = "arn:aws:lambda:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:function:appsync_auth_2"
}
}
}
Expand Down
29 changes: 29 additions & 0 deletions examples/complete/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
variable "region" {
description = "AWS region where resources will be created"
type = string
default = "eu-west-1"
}

variable "use_existing_route53_zone" {
description = "Whether to use an existing Route 53 zone"
type = bool
default = true
}

variable "route53_domain_name" {
description = "Existing Route 53 domain name"
type = string
default = "terraform-aws-modules.modules.tf"
}

variable "use_existing_acm_certificate" {
description = "Whether to use an existing ACM certificate"
type = bool
default = false
}

variable "existing_acm_certificate_domain_name" {
description = "Existing ACM certificate domain name"
type = string
default = "terraform-aws-modules.modules.tf"
}
2 changes: 1 addition & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ resource "aws_appsync_domain_name_api_association" "this" {
}

# API Cache
resource "aws_appsync_api_cache" "example" {
resource "aws_appsync_api_cache" "this" {
count = var.create_graphql_api && var.caching_enabled ? 1 : 0

api_id = aws_appsync_graphql_api.this[0].id
Expand Down
8 changes: 8 additions & 0 deletions migrations.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
################################################################################
# Migrations: v2.6.0 -> v3.0.0
################################################################################

moved {
from = aws_appsync_api_cache.example
to = aws_appsync_api_cache.this
}
2 changes: 1 addition & 1 deletion versions.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
terraform {
required_version = ">= 1.0"
required_version = ">= 1.3.2"

required_providers {
aws = {
Expand Down
2 changes: 1 addition & 1 deletion wrappers/versions.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
terraform {
required_version = ">= 1.0"
required_version = ">= 1.3.2"

required_providers {
aws = {
Expand Down

0 comments on commit 4b7f0b1

Please sign in to comment.