Skip to content

Commit 96dd64c

Browse files
committed
feat: update structure from tf files
1 parent 97de5e7 commit 96dd64c

20 files changed

+848
-76
lines changed

.env

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# project config
2+
PROJECT_NAME_PREFIX="poc2-terraform-node-hw"
3+
AWS_REGION="us-east-1"
4+
5+
# AWS tf infra output names
6+
S3_BUCKET_OUTPUT_NAME="s3_bucket_name"
7+
DYNAMODB_TABLE_OUTPUT_NAME="dynamodb_lock_table_name"
8+
9+
# ALB config
10+
# MIN_NUM_INSTANCES=1
11+
# MAX_NUM_INSTANCES=2
12+
# INSTANCES_RUNNING_AT_SAME_TIME=1
13+
14+
# terraform configuration files paths
15+
PRE_TERRAFORM_DIR="./00-tf-infra"
16+
APP_TERRAFORM_DIR="./01-tf"
17+
GENERATED_VARIABLES_TF_FILENAME="auto_generated_variables.tf"
18+
GENERATED_BACKEND_TF_FILENAME="auto_generated_backend.tf"

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ node_modules/
33
npm-debug.log
44
yarn-error.log
55

6+
# .env
7+
68
# Terraform
79
.terraform/
810
*.tfstate

00-tf-infra/README.md

Whitespace-only changes.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# !!! DO NOT MODIFY THIS FILE MANUALLY !!!
2+
# File generated by 'setup_tf_backend.sh' dont modify this file manually
3+
# unless you know what you are doing
4+
5+
variable "aws_region" {
6+
description = "AWS region for ECR repository"
7+
type = string
8+
default = "us-east-1"
9+
}
10+
11+
variable "project_name_prefix" {
12+
description = "Prefix for the names of the aws resources to ensure uniqueness."
13+
type = string
14+
default = "poc2-terraform-node-hw"
15+
}

00-tf-infra/main.tf

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
provider "aws" {
2-
region = var.AWS_REGION
2+
region = var.aws_region
33
profile = "my-dev-profile"
44
}
55

6-
# Usamos el Account ID para asegurar nombres de bucket S3 únicos globalmente.
76
data "aws_caller_identity" "current" {}
87

98
resource "aws_s3_bucket" "terraform_state" {
10-
bucket = "${var.PROJECT_NAME_PREFIX}-tfstate-${data.aws_caller_identity.current.account_id}-${var.AWS_REGION}"
9+
bucket = "${var.project_name_prefix}-tfstate-${data.aws_caller_identity.current.account_id}-${var.aws_region}"
1110

1211
tags = {
13-
Name = "${var.PROJECT_NAME_PREFIX}-terraform-state-bucket"
12+
Name = "${var.project_name_prefix}-terraform-state-bucket"
1413
Environment = "TerraformBackend"
1514
ManagedBy = "Terraform"
1615
}
@@ -26,7 +25,7 @@ resource "aws_s3_bucket_server_side_encryption_configuration" "terraform_state_e
2625
}
2726
}
2827

29-
# Habilitar versionado para el historial de archivos de estado
28+
# activate versioning for the state bucket
3029
resource "aws_s3_bucket_versioning" "terraform_state_versioning" {
3130
bucket = aws_s3_bucket.terraform_state.id
3231
versioning_configuration {
@@ -35,17 +34,17 @@ resource "aws_s3_bucket_versioning" "terraform_state_versioning" {
3534
}
3635

3736
resource "aws_dynamodb_table" "terraform_locks" {
38-
name = "${var.PROJECT_NAME_PREFIX}-terraform-lock-table"
39-
billing_mode = "PAY_PER_REQUEST" # Rentable para uso infrecuente como bloqueos de TF
40-
hash_key = "LockID" # La clave de partición DEBE ser "LockID"
37+
name = "${var.project_name_prefix}-terraform-lock-table"
38+
billing_mode = "PAY_PER_REQUEST"
39+
hash_key = "LockID"
4140

4241
attribute {
4342
name = "LockID"
4443
type = "S" # String
4544
}
4645

4746
tags = {
48-
Name = "${var.PROJECT_NAME_PREFIX}-terraform-lock-table"
47+
Name = "${var.project_name_prefix}-terraform-lock-table"
4948
Environment = "TerraformBackend"
5049
ManagedBy = "Terraform"
5150
}

00-tf-infra/variables.tf

Lines changed: 0 additions & 11 deletions
This file was deleted.

01-tf/auto_generated_backend.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
terraform {
66
backend "s3" {
7-
bucket = "poc-hello-world-tfstate-058264118467-us-east-1"
8-
key = "states/poc-hello-world/terraform.tfstate"
7+
bucket = "poc2-terraform-node-hw-tfstate-058264118467-us-east-1"
8+
key = "states/poc2-terraform-node-hw/terraform.tfstate"
99
region = "us-east-1"
10-
dynamodb_table = "poc-hello-world-terraform-lock-table"
10+
dynamodb_table = "poc2-terraform-node-hw-terraform-lock-table"
1111
encrypt = true
1212
}
1313
}

01-tf/auto_generated_variables.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
# File generated by 'setup_tf_backend.sh' dont modify this file manually
33
# unless you know what you are doing
44

5-
variable "AWS_REGION" {
5+
variable "aws_region" {
66
description = "AWS region for ECR repository"
77
type = string
88
default = "us-east-1"
99
}
1010

11-
variable "ECR_REPOSITORY_NAME" {
12-
description = "Name for the ECR repository"
11+
variable "project_name_prefix" {
12+
description = "Prefix for the names of the aws resources to ensure uniqueness."
1313
type = string
14-
default = "poc-hello-world"
14+
default = "poc2-terraform-node-hw"
1515
}

01-tf/main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
provider "aws" {
2-
region = var.AWS_REGION
2+
region = var.aws_region
33
}
44

55
resource "aws_ecr_repository" "app_ecr" {
6-
name = var.ECR_REPOSITORY_NAME
6+
name = "${var.project_name_prefix}/app-ecr"
77

88
tags = {
99
Environment = "dev"

01-tf/outputs.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ output "ecr_repository_url" {
55

66
output "aws_region_configured" {
77
description = "The AWS region configured for the provider"
8-
value = var.AWS_REGION
8+
value = var.aws_region
99
}

0 commit comments

Comments
 (0)