This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
variable "region" { | |
type = string | |
description = "(Required) AWS region to use" | |
} | |
variable "vpc_id" { | |
type = string | |
description = "(Required) The VPC ID where to deploy RDS instance" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
terraform { | |
required_providers { | |
aws = { | |
source = "hashicorp/aws" | |
version = "~> 3.45.0" | |
} | |
random = { | |
source = "hashicorp/random" | |
version = "~> 3.1.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
output "db_endpoint" { | |
description = "The database endpoint for connection" | |
value = aws_db_instance.default.endpoint | |
} | |
output "db_address" { | |
description = "The database address for connection" | |
value = aws_db_instance.default.address | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
locals { | |
name = "${var.tags["environment"]}-${var.tags["project"]}-rds" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resource "aws_security_group" "default" { | |
name = local.name | |
description = "Allow inbound access in port 3306 only" | |
vpc_id = var.vpc_id | |
ingress { | |
protocol = "tcp" | |
from_port = var.db_port | |
to_port = var.db_port | |
security_groups = var.allowed_security_groups |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
output "vpc_id" { | |
description = "The default VPC ID" | |
value = aws_default_vpc.default.id | |
} | |
output "subnet_id" { | |
description = "The default subnet ID" | |
value = aws_default_subnet.default.id | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
terraform { | |
required_providers { | |
aws = { | |
source = "hashicorp/aws" | |
version = "~> 3.45.0" | |
} | |
} | |
} | |
provider "aws" { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
locals { | |
name = "${var.tags["environment"]}-${var.tags["project"]}" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
variable "region" { | |
type = string | |
description = "(Required) AWS region" | |
} | |
variable "tags" { | |
type = map(string) | |
description = "(Required) Tags for resources" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resource "aws_default_vpc" "default" { | |
tags = merge({ | |
name = local.name | |
}, var.tags) | |
} | |
resource "aws_default_subnet" "default" { | |
availability_zone = var.availability_zone | |
tags = merge({ | |
name = local.name |