Skip to content

Commit 4659501

Browse files
authored
fix: add outputs and make args optional (#14)
1 parent 01b7057 commit 4659501

File tree

2 files changed

+46
-20
lines changed

2 files changed

+46
-20
lines changed

main.tf

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,26 @@ resource "aws_neptune_cluster" "this" {
1515
engine = "neptune"
1616
engine_version = var.engine_version
1717
port = try(var.port, 8182)
18-
storage_encrypted = var.storage_encrypted
18+
storage_encrypted = try(var.storage_encrypted, null)
1919
storage_type = try(var.storage_type, "standard")
20-
deletion_protection = var.deletion_protection
21-
apply_immediately = var.apply_immediately
22-
allow_major_version_upgrade = var.allow_major_version_upgrade
23-
backup_retention_period = var.backup_retention_period
20+
deletion_protection = try(var.deletion_protection, null)
21+
apply_immediately = try(var.apply_immediately, null)
22+
allow_major_version_upgrade = try(var.allow_major_version_upgrade, null)
23+
backup_retention_period = try(var.backup_retention_period, null)
2424

2525
# Optional references
2626
neptune_cluster_parameter_group_name = try(aws_neptune_cluster_parameter_group.this[0].name, null)
2727
neptune_subnet_group_name = try(aws_neptune_subnet_group.this[0].name, null)
2828
kms_key_arn = try(var.kms_key_arn, null)
29-
iam_database_authentication_enabled = var.iam_database_authentication_enabled
29+
iam_database_authentication_enabled = try(var.iam_database_authentication_enabled, null)
3030
iam_roles = try([aws_iam_role.this[0].arn], var.iam_roles)
3131
availability_zones = try(var.availability_zones, null)
3232
copy_tags_to_snapshot = try(var.copy_tags_to_snapshot, null)
3333
final_snapshot_identifier = try(var.final_snapshot_identifier, null)
3434
global_cluster_identifier = try(var.global_cluster_identifier, null)
3535
replication_source_identifier = try(var.replication_source_identifier, null)
3636
snapshot_identifier = try(var.snapshot_identifier, null)
37-
preferred_backup_window = var.preferred_backup_window
37+
preferred_backup_window = try(var.preferred_backup_window, null)
3838
preferred_maintenance_window = try(var.preferred_maintenance_window, null)
3939

4040
# CloudWatch logs
@@ -50,12 +50,12 @@ resource "aws_neptune_cluster" "this" {
5050
}
5151

5252
# Skipping final snapshot if needed
53-
skip_final_snapshot = var.skip_final_snapshot
53+
skip_final_snapshot = try(var.skip_final_snapshot, null)
5454

5555
# Security groups
5656
vpc_security_group_ids = try([aws_security_group.this[0].id], var.vpc_security_group_ids)
5757

58-
tags = var.tags
58+
tags = try(var.tags, null)
5959
}
6060

6161
######################
@@ -68,7 +68,7 @@ resource "aws_neptune_global_cluster" "this" {
6868
global_cluster_identifier = var.global_cluster_identifier
6969
engine = try(var.global_cluster_engine, null)
7070
engine_version = try(var.global_cluster_engine_version, null)
71-
deletion_protection = var.global_cluster_deletion_protection
71+
deletion_protection = try(var.global_cluster_deletion_protection, null)
7272
source_db_cluster_identifier = try(var.global_cluster_source_db_cluster_identifier, null)
7373
storage_encrypted = try(var.global_cluster_storage_encrypted, null)
7474
}
@@ -86,7 +86,10 @@ resource "aws_neptune_cluster_instance" "primary" {
8686
neptune_parameter_group_name = try(aws_neptune_parameter_group.this[0].name, null)
8787
neptune_subnet_group_name = try(aws_neptune_subnet_group.this[0].name, null)
8888

89-
tags = merge(var.tags, var.neptune_cluster_instance_tags)
89+
tags = merge(
90+
try(var.tags, {}),
91+
try(var.neptune_cluster_instance_tags, {})
92+
)
9093
}
9194

9295
######################
@@ -101,7 +104,10 @@ resource "aws_neptune_cluster_instance" "read_replicas" {
101104
neptune_parameter_group_name = try(aws_neptune_parameter_group.this[0].name, null)
102105
neptune_subnet_group_name = try(aws_neptune_subnet_group.this[0].name, null)
103106

104-
tags = merge(var.tags, var.neptune_cluster_instance_tags)
107+
tags = merge(
108+
try(var.tags, {}),
109+
try(var.neptune_cluster_instance_tags, {})
110+
)
105111
}
106112

107113

@@ -113,7 +119,7 @@ resource "aws_neptune_cluster_snapshot" "this" {
113119
count = var.create_neptune_cluster_snapshot ? 1 : 0
114120

115121
db_cluster_identifier = try(aws_neptune_cluster.this[0].id, var.db_cluster_identifier)
116-
db_cluster_snapshot_identifier = var.db_cluster_snapshot_identifier
122+
db_cluster_snapshot_identifier = try(aws_neptune_cluster_snapshot.this[0].id, var.db_cluster_snapshot_identifier)
117123

118124
dynamic "timeouts" {
119125
for_each = var.db_cluster_identifier != null ? [1] : []
@@ -142,7 +148,10 @@ resource "aws_neptune_cluster_parameter_group" "this" {
142148
}
143149
}
144150

145-
tags = merge(var.tags, var.neptune_cluster_parameter_group_tags)
151+
tags = merge(
152+
try(var.tags, {}),
153+
try(var.neptune_cluster_parameter_group_tags, {})
154+
)
146155
}
147156

148157
resource "aws_neptune_parameter_group" "this" {
@@ -160,7 +169,10 @@ resource "aws_neptune_parameter_group" "this" {
160169
}
161170
}
162171

163-
tags = merge(var.tags, var.neptune_parameter_group_tags)
172+
tags = merge(
173+
try(var.tags, {}),
174+
try(var.neptune_parameter_group_tags, {})
175+
)
164176
}
165177

166178
######################
@@ -174,7 +186,10 @@ resource "aws_neptune_subnet_group" "this" {
174186
description = "Neptune Subnet Group"
175187
subnet_ids = var.subnet_ids
176188

177-
tags = merge(var.tags, var.neptune_subnet_group_tags)
189+
tags = merge(
190+
try(var.tags, {}),
191+
try(var.neptune_subnet_group_tags, {})
192+
)
178193
}
179194

180195
######################
@@ -189,7 +204,10 @@ resource "aws_neptune_event_subscription" "this" {
189204
source_type = var.event_subscriptions != null ? "db-instance" : null
190205
source_ids = var.create_neptune_instance ? [aws_neptune_cluster_instance.primary[0].id] : []
191206

192-
tags = merge(var.tags, var.neptune_event_subscription_tags)
207+
tags = merge(
208+
try(var.tags, {}),
209+
try(var.neptune_event_subscription_tags, {})
210+
)
193211
}
194212

195213
######################
@@ -235,7 +253,10 @@ resource "aws_security_group" "this" {
235253
cidr_blocks = var.neptune_subnet_cidrs
236254
}
237255

238-
tags = merge(var.tags, var.neptune_security_group_tags)
256+
tags = merge(
257+
try(var.tags, {}),
258+
try(var.neptune_security_group_tags, {})
259+
)
239260
}
240261

241262
######################
@@ -269,7 +290,7 @@ resource "aws_iam_role" "this" {
269290
{
270291
"Name" = format("%s", var.neptune_role_name)
271292
},
272-
var.tags,
293+
try(var.tags, {}),
273294
)
274295
}
275296

outputs.tf

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,13 @@ output "neptune_cluster_arn" {
88
value = try(aws_neptune_cluster.this[0].arn, null)
99
}
1010

11+
output "neptune_cluster_members" {
12+
description = "List of Neptune Instances that are a part of this cluster"
13+
value = try(aws_neptune_cluster.this[0].cluster_members, null)
14+
}
15+
1116
output "neptune_cluster_endpoint" {
12-
description = "The endpoint of the Neptune cluster"
17+
description = "The DNS endpoint of the Neptune cluster instance"
1318
value = try(aws_neptune_cluster.this[0].endpoint, null)
1419
}
1520

0 commit comments

Comments
 (0)