Skip to content

Instantly share code, notes, and snippets.

@softarts
Last active April 10, 2022 04:19
Show Gist options
  • Save softarts/da7865977bd88d36b13543dfc6006ffa to your computer and use it in GitHub Desktop.
Save softarts/da7865977bd88d36b13543dfc6006ffa to your computer and use it in GitHub Desktop.
terraform-rds
terraform {
required_version = ">= 1.0.0, < 2.0.0"
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 4.0"
}
}
}
provider "aws" {
region = "ap-southeast-1"
}
resource "aws_db_instance" "example" {
identifier_prefix = "terraform-example"
engine = "mysql"
allocated_storage = 5
instance_class = "db.t2.micro"
skip_final_snapshot = true
publicly_accessible = true
db_name = var.db_name
username = var.db_username
password = var.db_password
}
output "address" {
value = aws_db_instance.example.address
description = "Connect to the database at this endpoint"
}
output "port" {
value = aws_db_instance.example.port
description = "The port the database is listening on"
}
variable "db_username" {
description = "The username for the database"
type = string
sensitive = true
}
variable "db_password" {
description = "The password for the database"
type = string
sensitive = true
}
variable "db_name" {
description = "The name to use for the database"
type = string
default = "terraform_example_database"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment