Skip to content

Commit

Permalink
fix: make cluster_identifier optional for use with global clusters (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
dstrates authored Jan 6, 2025
1 parent f8fc0aa commit 39307ee
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 29 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Neptune serverless requires that the `engine_version` attribute must be `1.2.0.1
module "neptune" {
source = "dstrates/neptune/aws"
version = "0.1.2"
version = "0.1.3"
apply_immediately = true
backup_retention_period = 5
Expand Down Expand Up @@ -77,7 +77,7 @@ module "neptune" {
```hcl
module "neptune" {
source = "dstrates/neptune/aws"
version = "0.1.2"
version = "0.1.3"
# Standard configuration
# ...
Expand Down Expand Up @@ -166,7 +166,7 @@ No modules.
| <a name="input_apply_immediately"></a> [apply\_immediately](#input\_apply\_immediately) | Specifies whether cluster modifications are applied immediately | `bool` | `true` | no |
| <a name="input_availability_zones"></a> [availability\_zones](#input\_availability\_zones) | (Optional) A list of EC2 Availability Zones that instances in the Neptune cluster can be created in. | `list(string)` | `null` | no |
| <a name="input_backup_retention_period"></a> [backup\_retention\_period](#input\_backup\_retention\_period) | The number of days to retain backups for | `number` | `7` | no |
| <a name="input_cluster_identifier"></a> [cluster\_identifier](#input\_cluster\_identifier) | The cluster identifier | `string` | n/a | yes |
| <a name="input_cluster_identifier"></a> [cluster\_identifier](#input\_cluster\_identifier) | The cluster identifier. Required if create\_neptune\_cluster is true. | `string` | `null` | no |
| <a name="input_cluster_identifier_prefix"></a> [cluster\_identifier\_prefix](#input\_cluster\_identifier\_prefix) | (Optional) Creates a unique cluster identifier beginning with the specified prefix. Conflicts with cluster\_identifier. | `string` | `null` | no |
| <a name="input_copy_tags_to_snapshot"></a> [copy\_tags\_to\_snapshot](#input\_copy\_tags\_to\_snapshot) | (Optional) If set to true, tags are copied to any snapshot of the DB cluster that is created. | `bool` | `null` | no |
| <a name="input_create_neptune_cluster"></a> [create\_neptune\_cluster](#input\_create\_neptune\_cluster) | Whether or not to create a Neptune cluster | `bool` | `true` | no |
Expand All @@ -192,7 +192,7 @@ No modules.
| <a name="input_global_cluster_engine"></a> [global\_cluster\_engine](#input\_global\_cluster\_engine) | (Optional) Name of the database engine to be used for the global cluster. Valid values: neptune. | `string` | `null` | no |
| <a name="input_global_cluster_engine_version"></a> [global\_cluster\_engine\_version](#input\_global\_cluster\_engine\_version) | (Optional) Engine version of the global database. Must be compatible with Neptune global cluster versions. | `string` | `null` | no |
| <a name="input_global_cluster_identifier"></a> [global\_cluster\_identifier](#input\_global\_cluster\_identifier) | (Optional) The global cluster identifier specified on aws\_neptune\_global\_cluster. | `string` | `null` | no |
| <a name="input_global_cluster_source_db_cluster_identifier"></a> [global\_cluster\_source\_db\_cluster\_identifier](#input\_global\_cluster\_source\_db\_cluster\_identifier) | (Optional) ARN of a Neptune DB Cluster to use as the primary DB cluster of the global cluster. | `string` | `null` | no |
| <a name="input_global_cluster_source_db_cluster_identifier"></a> [global\_cluster\_source\_db\_cluster\_identifier](#input\_global\_cluster\_source\_db\_cluster\_identifier) | (Optional) Amazon Resource Name (ARN) to use as the primary DB Cluster of the Global Cluster on creation. Terraform cannot perform drift detection of this value. | `string` | `null` | no |
| <a name="input_global_cluster_storage_encrypted"></a> [global\_cluster\_storage\_encrypted](#input\_global\_cluster\_storage\_encrypted) | (Optional) Specifies whether the global cluster is encrypted. The default is false unless the source DB cluster is encrypted. | `bool` | `null` | no |
| <a name="input_iam_database_authentication_enabled"></a> [iam\_database\_authentication\_enabled](#input\_iam\_database\_authentication\_enabled) | Specifies whether IAM database authentication is enabled | `bool` | `true` | no |
| <a name="input_iam_roles"></a> [iam\_roles](#input\_iam\_roles) | (Optional) A List of ARNs for the IAM roles to associate to the Neptune Cluster | `list(string)` | `null` | no |
Expand Down
29 changes: 12 additions & 17 deletions examples/global-cluster-existing/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ data "aws_kms_key" "default" {
}

########################################
# Create a Neptune cluster from existing DB cluster
# Create a Global cluster from existing DB cluster
########################################

# Assuming you have an existing standard Neptune cluster
module "neptune_existing_cluster" {
source = "dstrates/neptune/aws"
version = "0.1.2"
version = "0.1.3"

# Create a standard Neptune cluster first
create_neptune_cluster = true
create_neptune_subnet_group = true
create_neptune_cluster_parameter_group = true
Expand Down Expand Up @@ -90,23 +90,18 @@ module "neptune_existing_cluster" {
Name = "existing-neptune-cluster"
Environment = "dev"
}

# IMPORTANT:
# We'll use this cluster as a source for a global cluster.
# The global_cluster_identifier attribute will be set by the global cluster resource.
# We must instruct Terraform to ignore changes to global_cluster_identifier to prevent drift.
lifecycle {
ignore_changes = [global_cluster_identifier]
}
}

########################################
# Create a Global Cluster from the Existing DB Cluster
########################################
# Create a global cluster referencing that cluster
module "neptune_global_cluster" {
source = "dstrates/neptune/aws"
version = "0.1.3"

resource "aws_neptune_global_cluster" "this" {
global_cluster_identifier = "my-global-neptune-cluster"
source_db_cluster_identifier = module.neptune_existing_cluster.aws_neptune_cluster_arn
create_neptune_global_cluster = true
global_cluster_engine = "neptune"
global_cluster_engine_version = "1.2.0.1"
global_cluster_identifier = "my-global-neptune-cluster"
global_cluster_source_db_cluster_identifier = module.neptune_existing_cluster.aws_neptune_cluster_arn
}

########################################
Expand Down
2 changes: 1 addition & 1 deletion examples/global-cluster-new/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ module "neptune_global_primary" {

module "neptune_global_secondary" {
source = "dstrates/neptune/aws"
version = "0.1.0"
version = "0.1.2"

providers = {
aws = aws.secondary
Expand Down
4 changes: 2 additions & 2 deletions examples/read-replica/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ data "aws_kms_key" "secondary" {

module "neptune_primary" {
source = "dstrates/neptune/aws"
version = "0.1.2"
version = "0.1.3"

providers = {
aws = aws.primary
Expand Down Expand Up @@ -145,7 +145,7 @@ module "neptune_primary" {

module "neptune_replica" {
source = "dstrates/neptune/aws"
version = "0.1.2"
version = "0.1.3"

providers = {
aws = aws.secondary
Expand Down
4 changes: 1 addition & 3 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ resource "aws_neptune_global_cluster" "this" {
storage_encrypted = try(var.global_cluster_storage_encrypted, null)
}


######################
# Primary Cluster instance
######################
Expand Down Expand Up @@ -110,15 +109,14 @@ resource "aws_neptune_cluster_instance" "read_replicas" {
)
}


######################
# Cluster snapshot
######################

resource "aws_neptune_cluster_snapshot" "this" {
count = var.create_neptune_cluster_snapshot ? 1 : 0

db_cluster_identifier = try(aws_neptune_cluster.this[0].id, var.db_cluster_identifier)
db_cluster_identifier = try(aws_neptune_cluster.this[0].id, var.db_cluster_identifier)
db_cluster_snapshot_identifier = coalesce(
var.db_cluster_snapshot_identifier,
format("%s-%s", aws_neptune_cluster.this[0].id, random_id.snapshot_suffix.hex)
Expand Down
5 changes: 3 additions & 2 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ variable "backup_retention_period" {
}

variable "cluster_identifier" {
description = "The cluster identifier"
description = "The cluster identifier. Required if create_neptune_cluster is true."
type = string
default = null
}

variable "cluster_identifier_prefix" {
Expand Down Expand Up @@ -181,7 +182,7 @@ variable "global_cluster_identifier" {
}

variable "global_cluster_source_db_cluster_identifier" {
description = "(Optional) ARN of a Neptune DB Cluster to use as the primary DB cluster of the global cluster."
description = "(Optional) Amazon Resource Name (ARN) to use as the primary DB Cluster of the Global Cluster on creation. Terraform cannot perform drift detection of this value."
type = string
default = null
}
Expand Down

0 comments on commit 39307ee

Please sign in to comment.