Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add export to S3 module #488

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 0 additions & 22 deletions apps-devstg/us-east-1/backups --/.terraform.lock.hcl

This file was deleted.

32 changes: 16 additions & 16 deletions apps-devstg/us-east-1/base-network/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 0 additions & 62 deletions apps-devstg/us-east-1/databases-mysql --/.terraform.lock.hcl

This file was deleted.

2 changes: 1 addition & 1 deletion apps-devstg/us-east-1/databases-mysql --/config.tf
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ provider "vault" {
# Backend Config (partial) #
#=============================#
terraform {
required_version = "~> 1.1.3"
required_version = "~> 1.2.7"

required_providers {
aws = "~> 4.0"
Expand Down
13 changes: 5 additions & 8 deletions apps-devstg/us-east-1/databases-mysql --/db_mysql.tf
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,17 @@ resource "aws_security_group_rule" "allow_mysql_port" {
# Binbash Reference DB
#
module "bb_mysql_db" {
source = "github.com/binbashar/terraform-aws-rds.git?ref=v4.2.0"

source = "github.com/binbashar/terraform-aws-rds.git?ref=v5.6.0"

# Instance settings
# https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_MySQL.html
identifier = "${var.project}-${var.environment}-binbash-mysql"
engine = "mysql"
engine_version = "8.0.21"
instance_class = "db.m5.large"
engine_version = "8.0.28"
instance_class = "db.m6g.large"
allocated_storage = 100
storage_encrypted = true
multi_az = true
multi_az = false

# Database credentials
db_name = "${var.project}_${replace(var.environment, "apps-", "")}_binbash_mysql"
Expand All @@ -45,8 +44,6 @@ module "bb_mysql_db" {
password = data.vault_generic_secret.database_secrets.data["administrator_password"]
port = "3306"



# Backup and maintenance
backup_retention_period = 14
maintenance_window = "Tue:03:00-Tue:06:00"
Expand Down Expand Up @@ -79,7 +76,7 @@ module "bb_mysql_db" {

# Specifies whether any database modifications are applied immediately, or
# during the next maintenance window
apply_immediately = false
apply_immediately = true

# Database Deletion Protection
deletion_protection = false
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
locals {
bucket_name = "${var.project}-${replace(var.environment, "apps-", "")}-binbash-mysql"
}

# -----------------------------------------------------------------------------
# RDS Export To S3 functions
# -----------------------------------------------------------------------------
module "rds_export_to_s3" {
source = "[email protected]:binbashar/terraform-aws-rds-export-to-s3.git?ref=v0.4.0"

# Set a prefix for naming resources
#prefix = "binbashar"

# Which RDS snapshots should be exported?
database_names = "${var.project}-${replace(var.environment, "apps-", "")}-binbash-mysql"

# Which bucket will store the exported snapshots?
snapshots_bucket_name = module.bucket.s3_bucket_id
#snapshots_bucket_name = "export-bucket-name"

# To group objects in a bucket, S3 uses a prefix before object names. The forward slash (/) in the prefix represents a folder.
snapshots_bucket_prefix = "rds_snapshots/"

# Which RDS snapshots events should be included (RDS Aurora or/and RDS non-Aurora)?
#rds_event_ids = "RDS-EVENT-0091, RDS-EVENT-0169"

# Create customer managed key or use default AWS S3 managed key. If set to 'false', then 'customer_kms_key_arn' is used.
create_customer_kms_key = false

# Provide CMK if 'create_customer_kms_key = false'
#customer_kms_key_arn = "arn:aws:kms:us-east-1:523857393444:key/b7a1d584-29cf-4f21-a69f-57ca8eaa1c77"

# SNS topic for export monitor notifications
create_notifications_topic = true

# Which topic should receive notifications about exported snapshots events? Only required if 'create_notifications_topic = false'
#notifications_topic_arn = "arn:aws:sns:us-east-1:000000000000:sns-topic-slack-notifications"

# Set the logging level
# log_level = "DEBUG"

tags = local.tags
#tags = { Deployment = "binbachar-export" }
}


# -----------------------------------------------------------------------------
# This bucket will be used for storing the exported RDS snapshots.
# -----------------------------------------------------------------------------
module "bucket" {
source = "github.com/binbashar/terraform-aws-s3-bucket.git?ref=v2.6.0"

bucket = local.bucket_name
acl = "private"
force_destroy = true

attach_deny_insecure_transport_policy = true

server_side_encryption_configuration = {
rule = {
apply_server_side_encryption_by_default = {
sse_algorithm = "AES256"
}
}
}

block_public_acls = true
block_public_policy = true
ignore_public_acls = true
restrict_public_buckets = true

tags = local.tags
}
65 changes: 65 additions & 0 deletions apps-devstg/us-east-1/databases-mysql/config.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#=============================#
# AWS Provider Settings #
#=============================#
provider "aws" {
region = var.region
profile = var.profile
}

#=============================#
# Vault Provider Settings #
#=============================#
provider "vault" {
address = var.vault_address

/*
Vault token that will be used by Terraform to authenticate.
admin token from https://portal.cloud.hashicorp.com/.
*/
token = var.vault_token
}

#=============================#
# Backend Config (partial) #
#=============================#
terraform {
required_version = "~> 1.2.7"

required_providers {
aws = "~> 4.0"
vault = "~> 3.6.0"
}

backend "s3" {
key = "apps-devstg/databases-mysql/terraform.tfstate"
}
}

#=============================#
# Data sources #
#=============================#
data "terraform_remote_state" "vpc" {
backend = "s3"

config = {
region = var.region
profile = var.profile
bucket = var.bucket
key = "${var.environment}/network/terraform.tfstate"
}
}

data "terraform_remote_state" "vpc-shared" {
backend = "s3"

config = {
region = var.region
profile = "${var.project}-shared-devops"
bucket = "${var.project}-shared-terraform-backend"
key = "shared/network/terraform.tfstate"
}
}

data "vault_generic_secret" "database_secrets" {
path = "secrets/${var.project}/${var.environment}/databases-mysql"
}
Loading