Skip to content

Commit

Permalink
Merge pull request #2 from jetbrains-infra/feature/terraform_0.12_sup…
Browse files Browse the repository at this point in the history
…port

syntax (interpolation) changes to support terraform 0.12
  • Loading branch information
sugdyzhekov authored Mar 18, 2020
2 parents 74b6c96 + 8d96823 commit 23d4b2a
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 85 deletions.
12 changes: 6 additions & 6 deletions outputs.tf
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
output "password" {
sensitive = true
description = "RDS master password"
value = "${local.password}"
value = local.password
}

output "username" {
description = "DB master user name"
value = "${local.username}"
value = local.username
}

output "address" {
description = "The address of the RDS instance."
value = "${local.address}"
value = local.address
}

output "database" {
description = "The database name."
value = "${local.database}"
value = local.database
}

output "hosted_zone_id" {
description = "The canonical hosted zone ID of the DB instance (to be used in a Route 53 Alias record)."
value = "${local.hosted_zone_id}"
value = local.hosted_zone_id
}

output "rds_id" {
description = "The RDS instance ID"
value = "${local.rds_id}"
value = local.rds_id
}
74 changes: 37 additions & 37 deletions rds.tf
Original file line number Diff line number Diff line change
@@ -1,54 +1,54 @@
resource "aws_db_instance" "default" {
count = "${local.rds_without_param_group}"
instance_class = "${local.instance_type}"
count = local.rds_without_param_group
instance_class = local.instance_type
engine = "mysql"
engine_version = "${local.engine_version}"
vpc_security_group_ids = ["${aws_security_group.default.id}"]
db_subnet_group_name = "${aws_db_subnet_group.default.name}"
identifier = "${local.id}"
engine_version = local.engine_version
vpc_security_group_ids = [aws_security_group.default.id]
db_subnet_group_name = aws_db_subnet_group.default.name
identifier = local.id
skip_final_snapshot = true
allocated_storage = "${local.disk_size}"
allocated_storage = local.disk_size
storage_type = "gp2"
multi_az = "${local.multi_az}"
backup_window = "${local.backup_window}"
backup_retention_period = "${local.backup_retention_period}"
name = "${local.database}"
username = "${local.username}"
password = "${local.password}"
publicly_accessible = "${local.publicly_accessible}"
multi_az = local.multi_az
backup_window = local.backup_window
backup_retention_period = local.backup_retention_period
name = local.database
username = local.username
password = local.password
publicly_accessible = local.publicly_accessible
storage_encrypted = true
apply_immediately = "${local.apply_immediately}"
enabled_cloudwatch_logs_exports = ["${local.logs_set}"]
apply_immediately = local.apply_immediately
enabled_cloudwatch_logs_exports = local.logs_set

tags {
Project = "${local.project}"
tags = {
Project = local.project
}
}

resource "aws_db_instance" "parameterized" {
count = "${local.rds_with_param_group}"
instance_class = "${local.instance_type}"
count = local.rds_with_param_group
instance_class = local.instance_type
engine = "mysql"
engine_version = "${local.engine_version}"
vpc_security_group_ids = ["${aws_security_group.default.id}"]
db_subnet_group_name = "${aws_db_subnet_group.default.name}"
identifier = "${local.id}"
parameter_group_name = "${local.parameter_group_name}"
engine_version = local.engine_version
vpc_security_group_ids = [aws_security_group.default.id]
db_subnet_group_name = aws_db_subnet_group.default.name
identifier = local.id
parameter_group_name = local.parameter_group_name
skip_final_snapshot = true
allocated_storage = "${local.disk_size}"
allocated_storage = local.disk_size
storage_type = "gp2"
multi_az = "${local.multi_az}"
backup_window = "${local.backup_window}"
backup_retention_period = "${local.backup_retention_period}"
name = "${local.database}"
username = "${local.username}"
password = "${local.password}"
publicly_accessible = "${local.publicly_accessible}"
multi_az = local.multi_az
backup_window = local.backup_window
backup_retention_period = local.backup_retention_period
name = local.database
username = local.username
password = local.password
publicly_accessible = local.publicly_accessible
storage_encrypted = true
apply_immediately = "${local.apply_immediately}"
enabled_cloudwatch_logs_exports = ["${local.logs_set}"]
apply_immediately = local.apply_immediately
enabled_cloudwatch_logs_exports = local.logs_set

tags {
Project = "${local.project}"
tags = {
Project = local.project
}
}
10 changes: 5 additions & 5 deletions security_groups.tf
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
resource "aws_security_group" "default" {
name = "${local.name}"
vpc_id = "${local.vpc_id}"
name = local.name
vpc_id = local.vpc_id

ingress {
from_port = 3306
protocol = "TCP"
to_port = 3306
cidr_blocks = ["${local.trusted_cidr_blocks}"]
cidr_blocks = local.trusted_cidr_blocks
}

tags {
Project = "${local.project}"
tags = {
Project = local.project
}
}
8 changes: 4 additions & 4 deletions subnet_group.tf
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
resource "aws_db_subnet_group" "default" {
name = "${local.subnet_group_name}"
subnet_ids = ["${local.db_subnets}"]
name = local.subnet_group_name
subnet_ids = local.db_subnets

tags {
Project = "${local.project}"
tags = {
Project = local.project
}
}
61 changes: 28 additions & 33 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ variable "disk_size" {

variable "db_subnets" {
description = "A list of VPC subnet IDs"
type = "list"
type = list(string)
}

variable "password" {
Expand Down Expand Up @@ -73,7 +73,7 @@ variable "backup_window" {

variable "trusted_cidr_blocks" {
description = "A list of trusted external IP. You may specify office IPs f.e. Of course, RDS should be public accessible."
type = "list"
type = list(string)
default = []
}

Expand All @@ -83,11 +83,11 @@ variable "instance_type" {
}

data "aws_subnet" "default" {
id = "${var.db_subnets[0]}"
id = var.db_subnets[0]
}

locals {
vpc_id = "${data.aws_subnet.default.vpc_id}"
vpc_id = data.aws_subnet.default.vpc_id
}

variable "engine_version" {
Expand All @@ -110,33 +110,28 @@ variable "parameter_group_name" {
}

locals {
project = "${var.project}"
name = "${var.name}"
id = "${lower(replace(var.name, " ", "-"))}"
subnet_group_name = "${lower(replace(var.name, " ", "-"))}"
username = "${var.username == "" ? random_pet.username.id : var.username}"
password = "${var.password == "" ? random_string.password.result : var.password}"
database = "${var.database == "" ? random_pet.db_name.id : var.database}"
parameter_group_name = "${var.parameter_group_name}"
rds_with_param_group = "${local.parameter_group_name == "" ? 0 : 1}"
rds_without_param_group = "${local.parameter_group_name == "" ? 1 : 0}"
instance_type = "${var.instance_type}"
engine_version = "${var.engine_version}"
disk_size = "${var.disk_size}"
multi_az = "${var.multi_az}"
backup_window = "${var.backup_window}"
backup_retention_period = "${var.backup_retention_period}"
publicly_accessible = "${var.publicly_accessible}"
apply_immediately = "${var.apply_immediately}"
trusted_cidr_blocks = ["${var.trusted_cidr_blocks}"]
db_subnets = ["${var.db_subnets}"]
address = "${local.parameter_group_name == "" ? join("", aws_db_instance.default.*.address) : join("", aws_db_instance.parameterized.*.address)}"
hosted_zone_id = "${var.parameter_group_name == "" ? join("", aws_db_instance.default.*.hosted_zone_id) : join("", aws_db_instance.parameterized.*.hosted_zone_id)}"
rds_id = "${var.parameter_group_name == "" ? join("", aws_db_instance.default.*.id) : join("", aws_db_instance.parameterized.*.id)}"
logs_set = ["${compact(list(
"${var.enable_audit_log ? "audit" : "" }",
"${var.enable_error_log ? "error" : "" }",
"${var.enable_general_log ? "general" : "" }",
"${var.enable_slowquery_log ? "slowquery" : "" }"
))}"]
project = var.project
name = var.name
id = lower(replace(var.name, " ", "-"))
subnet_group_name = lower(replace(var.name, " ", "-"))
username = var.username == "" ? random_pet.username.id : var.username
password = var.password == "" ? random_string.password.result : var.password
database = var.database == "" ? random_pet.db_name.id : var.database
parameter_group_name = var.parameter_group_name
rds_with_param_group = local.parameter_group_name == "" ? 0 : 1
rds_without_param_group = local.parameter_group_name == "" ? 1 : 0
instance_type = var.instance_type
engine_version = var.engine_version
disk_size = var.disk_size
multi_az = var.multi_az
backup_window = var.backup_window
backup_retention_period = var.backup_retention_period
publicly_accessible = var.publicly_accessible
apply_immediately = var.apply_immediately
trusted_cidr_blocks = var.trusted_cidr_blocks
db_subnets = var.db_subnets
address = local.parameter_group_name == "" ? join("", aws_db_instance.default.*.address) : join("", aws_db_instance.parameterized.*.address)
hosted_zone_id = var.parameter_group_name == "" ? join("", aws_db_instance.default.*.hosted_zone_id) : join("", aws_db_instance.parameterized.*.hosted_zone_id)
rds_id = var.parameter_group_name == "" ? join("", aws_db_instance.default.*.id) : join("", aws_db_instance.parameterized.*.id)
logs_set = compact(list(var.enable_audit_log ? "audit" : "",var.enable_error_log ? "error" : "",var.enable_general_log ? "general" : "",var.enable_slowquery_log ? "slowquery" : ""))
}

0 comments on commit 23d4b2a

Please sign in to comment.