Skip to content

Commit

Permalink
ci: refactor terraform
Browse files Browse the repository at this point in the history
  • Loading branch information
jedwards1230 committed Dec 18, 2023
1 parent b3b18d4 commit ee5ccb9
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 31 deletions.
6 changes: 4 additions & 2 deletions terraform/dev/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ terraform {
}

module "infra" {
source = "../shared"
stage = "dev"
source = "../shared"
stage = var.stage
project-name = var.project-name
region = var.region
}
3 changes: 3 additions & 0 deletions terraform/dev/terraform.tfvars.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
project-name = ""
stage = ""
region = ""
14 changes: 14 additions & 0 deletions terraform/dev/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
variable "project-name" {
description = "Project name"
default = "personal-website"
}

variable "stage" {
description = "Stage (dev, prod)"
default = "dev"
}

variable "region" {
description = "AWS region"
default = "us-east-1"
}
28 changes: 9 additions & 19 deletions terraform/init-state/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,11 @@ terraform {
}

provider "aws" {
region = "us-east-1"
region = var.region
}

data "aws_caller_identity" "current" {}

variable "common_tags" {
description = "Common tags to be applied to all resources"
type = map(string)
default = {
awsApplication = "personal-website"
}
}

variable "project-name" {
description = "Project name"
default = "personal-website"
}

locals {
bucket_name = "${var.project-name}-${data.aws_caller_identity.current.account_id}-terraform-state"
dynamodb_table_name = "${var.project-name}-terraform-locks"
}

resource "aws_resourcegroups_group" "resource_group" {
name = var.project-name

Expand All @@ -53,6 +35,14 @@ resource "aws_resourcegroups_group" "resource_group" {
}
}

# Route 53 Hosted Zone
# Creates a Route 53 hosted zone for the domain name 'jedwards.cc'. This hosted zone is used to
# manage DNS records for the domain.
resource "aws_route53_zone" "main" {
name = var.domain_name
tags = var.common_tags
}

resource "aws_s3_bucket" "terraform_state" {
bucket = local.bucket_name
tags = var.common_tags
Expand Down
3 changes: 3 additions & 0 deletions terraform/init-state/terraform.tfvars.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
project-name = ""
region = ""
domain_name = ""
27 changes: 27 additions & 0 deletions terraform/init-state/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
variable "common_tags" {
description = "Common tags to be applied to all resources"
type = map(string)
default = {
awsApplication = "personal-website"
}
}

variable "project-name" {
description = "Project name"
default = "personal-website"
}

variable "region" {
description = "AWS region"
default = "us-east-1"
}

variable "domain_name" {
description = "Domain name"
default = "example.com"
}

locals {
bucket_name = "${var.project-name}-${data.aws_caller_identity.current.account_id}-terraform-state"
dynamodb_table_name = "${var.project-name}-terraform-locks"
}
6 changes: 4 additions & 2 deletions terraform/prod/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ terraform {
}

module "infra" {
source = "../shared"
stage = "prod"
source = "../shared"
stage = var.stage
project-name = var.project-name
region = var.region
}
3 changes: 3 additions & 0 deletions terraform/prod/terraform.tfvars.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
project-name = ""
stage = ""
region = ""
14 changes: 14 additions & 0 deletions terraform/prod/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
variable "project-name" {
description = "Project name"
default = "personal-website"
}

variable "stage" {
description = "Stage (dev, prod)"
default = "dev"
}

variable "region" {
description = "AWS region"
default = "us-east-1"
}
8 changes: 0 additions & 8 deletions terraform/shared/network.tf
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
# Route 53 Hosted Zone
# Creates a Route 53 hosted zone for the domain name 'lanecontrols.net'. This hosted zone is used to
# manage DNS records for the domain.
resource "aws_route53_zone" "main" {
name = "jedwards.cc"
tags = local.common_tags
}

# Request a new ACM certificate
resource "aws_acm_certificate" "cert" {
domain_name = "test.jedwards.cc"
Expand Down

0 comments on commit ee5ccb9

Please sign in to comment.