Skip to content

Commit

Permalink
refactoring estructure resources
Browse files Browse the repository at this point in the history
  • Loading branch information
mrk-qa committed Jan 16, 2024
1 parent fba5c87 commit 031995d
Show file tree
Hide file tree
Showing 17 changed files with 276 additions and 276 deletions.
Binary file added assets/terraform_terratest_githubactions.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
108 changes: 54 additions & 54 deletions db/db.tf → resources/db/db.tf
Original file line number Diff line number Diff line change
@@ -1,55 +1,55 @@
resource "aws_db_instance" "db_instance" {
identifier = var.name
engine = var.engine_name
engine_version = var.engine_version
port = var.port
db_name = var.database_name
username = var.username
password = var.password
instance_class = var.instance_class
allocated_storage = var.allocated_storage
skip_final_snapshot = true
license_model = var.license_model
db_subnet_group_name = aws_db_subnet_group.db_subnet_group.id
vpc_security_group_ids = [aws_security_group.db_instance.id]
publicly_accessible = true
parameter_group_name = aws_db_parameter_group.db_parameter.id
option_group_name = aws_db_option_group.db_option.id

tags = {
Name = var.tag_id_aws
}
}

resource "aws_db_option_group" "db_option" {
name = var.name
engine_name = var.engine_name
major_engine_version = var.major_engine_version

option {
option_name = "MARIADB_AUDIT_PLUGIN"

option_settings {
name = "SERVER_AUDIT_EVENTS"
value = "CONNECT"
}
}

tags = {
Name = var.tag_id_aws
}
}

resource "aws_db_parameter_group" "db_parameter" {
name = var.name
family = var.family

parameter {
name = "general_log"
value = "0"
}

tags = {
Name = var.tag_id_aws
}
resource "aws_db_instance" "db_instance" {
identifier = var.name
engine = var.engine_name
engine_version = var.engine_version
port = var.port
db_name = var.database_name
username = var.username
password = var.password
instance_class = var.instance_class
allocated_storage = var.allocated_storage
skip_final_snapshot = true
license_model = var.license_model
db_subnet_group_name = aws_db_subnet_group.db_subnet_group.id
vpc_security_group_ids = [aws_security_group.db_instance.id]
publicly_accessible = true
parameter_group_name = aws_db_parameter_group.db_parameter.id
option_group_name = aws_db_option_group.db_option.id

tags = {
Name = var.tag_id_aws
}
}

resource "aws_db_option_group" "db_option" {
name = var.name
engine_name = var.engine_name
major_engine_version = var.major_engine_version

option {
option_name = "MARIADB_AUDIT_PLUGIN"

option_settings {
name = "SERVER_AUDIT_EVENTS"
value = "CONNECT"
}
}

tags = {
Name = var.tag_id_aws
}
}

resource "aws_db_parameter_group" "db_parameter" {
name = var.name
family = var.family

parameter {
name = "general_log"
value = "0"
}

tags = {
Name = var.tag_id_aws
}
}
42 changes: 21 additions & 21 deletions db/main.tf → resources/db/main.tf
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
terraform {
required_version = ">= 0.12.26"

required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 4.61.0, < 5.0.0"
}
}
}

provider "aws" {
region = "us-east-1"


default_tags {
tags = {
owner = "marco-qa"
managed-by = "terraform"
}
}
terraform {
required_version = ">= 0.12.26"

required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 4.61.0, < 5.0.0"
}
}
}

provider "aws" {
region = "us-east-1"


default_tags {
tags = {
owner = "marco-qa"
managed-by = "terraform"
}
}
}
64 changes: 32 additions & 32 deletions db/network.tf → resources/db/network.tf
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
data "aws_vpc" "default" {
default = true
}

data "aws_subnets" "all" {
filter {
name = "vpc-id"
values = [data.aws_vpc.default.id]
}
}

resource "aws_security_group" "db_instance" {
name = var.name
vpc_id = data.aws_vpc.default.id
}

resource "aws_security_group_rule" "allow_db_access" {
type = "ingress"
from_port = var.port
to_port = var.port
protocol = "tcp"
security_group_id = aws_security_group.db_instance.id
cidr_blocks = ["0.0.0.0/0"]
}

resource "aws_db_subnet_group" "db_subnet_group" {
name = var.name
subnet_ids = data.aws_subnets.all.ids

tags = {
Name = var.tag_id_aws
}
data "aws_vpc" "default" {
default = true
}

data "aws_subnets" "all" {
filter {
name = "vpc-id"
values = [data.aws_vpc.default.id]
}
}

resource "aws_security_group" "db_instance" {
name = var.name
vpc_id = data.aws_vpc.default.id
}

resource "aws_security_group_rule" "allow_db_access" {
type = "ingress"
from_port = var.port
to_port = var.port
protocol = "tcp"
security_group_id = aws_security_group.db_instance.id
cidr_blocks = ["0.0.0.0/0"]
}

resource "aws_db_subnet_group" "db_subnet_group" {
name = var.name
subnet_ids = data.aws_subnets.all.ids

tags = {
Name = var.tag_id_aws
}
}
4 changes: 2 additions & 2 deletions db/outputs.tf → resources/db/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
output "db_instance_id" {
value = aws_db_instance.db_instance.id
output "db_instance_id" {
value = aws_db_instance.db_instance.id
}
164 changes: 82 additions & 82 deletions db/variables.tf → resources/db/variables.tf
Original file line number Diff line number Diff line change
@@ -1,83 +1,83 @@
variable "region" {
description = "The AWS region to deploy to"
type = string
default = "us-east-1"
}

variable "username" {
description = "Master username of the DB"
type = string
default = "marcoqadb"
}

variable "password" {
description = "Master password of the DB"
type = string
default = "12345678"
}

variable "database_name" {
description = "Name of the database to be created"
type = string
default = "marcoqadb123"
}

variable "name" {
description = "Name of the database"
type = string
default = "dbinfraterratest123"
}

variable "engine_name" {
description = "Name of the database engine"
type = string
default = "mysql"
}

variable "family" {
description = "Family of the database"
type = string
default = "mysql5.7"
}

variable "port" {
description = "Port which the database should run on"
type = number
default = 3306
}

variable "major_engine_version" {
description = "MAJOR.MINOR version of the DB engine"
type = string
default = "5.7"
}

variable "engine_version" {
description = "Version of the database to be launched"
default = "5.7.44"
type = string
}

variable "allocated_storage" {
description = "Disk space to be allocated to the DB instance"
type = number
default = 5
}

variable "license_model" {
description = "License model of the DB instance"
type = string
default = "general-public-license"
}

variable "instance_class" {
description = "Instance class to be used to run the database"
type = string
default = "db.t2.micro"
}

variable "tag_id_aws" {
description = "Tag usado na AWS"
type = string
default = "terraform-with-terratest"
variable "region" {
description = "The AWS region to deploy to"
type = string
default = "us-east-1"
}

variable "username" {
description = "Master username of the DB"
type = string
default = "marcoqadb"
}

variable "password" {
description = "Master password of the DB"
type = string
default = "12345678"
}

variable "database_name" {
description = "Name of the database to be created"
type = string
default = "marcoqadb123"
}

variable "name" {
description = "Name of the database"
type = string
default = "dbinfraterratest123"
}

variable "engine_name" {
description = "Name of the database engine"
type = string
default = "mysql"
}

variable "family" {
description = "Family of the database"
type = string
default = "mysql5.7"
}

variable "port" {
description = "Port which the database should run on"
type = number
default = 3306
}

variable "major_engine_version" {
description = "MAJOR.MINOR version of the DB engine"
type = string
default = "5.7"
}

variable "engine_version" {
description = "Version of the database to be launched"
default = "5.7.44"
type = string
}

variable "allocated_storage" {
description = "Disk space to be allocated to the DB instance"
type = number
default = 5
}

variable "license_model" {
description = "License model of the DB instance"
type = string
default = "general-public-license"
}

variable "instance_class" {
description = "Instance class to be used to run the database"
type = string
default = "db.t2.micro"
}

variable "tag_id_aws" {
description = "Tag usado na AWS"
type = string
default = "terraform-with-terratest"
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 031995d

Please sign in to comment.