Skip to content

Commit

Permalink
TG rework changes (#137)
Browse files Browse the repository at this point in the history
Co-authored-by: Vijay Jadhav <[email protected]>
  • Loading branch information
vjremotegithub and Vijay Jadhav authored Jul 12, 2024
1 parent 60a581f commit 643b9fd
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 75 deletions.
6 changes: 3 additions & 3 deletions modules/products/static-site/WAF.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
resource "aws_wafv2_web_acl" "default" {
name = "cc-static-site-${var.product}-${var.component}"
description = "Static Site WAF rule for ${var.product} ${var.component}"
name = "cc-static-site-${var.tags.product}-${var.tags.component}"
description = "Static Site WAF rule for ${var.tags.product} ${var.tags.component}"
scope = "REGIONAL"

tags = local.common_tags
Expand All @@ -11,7 +11,7 @@ resource "aws_wafv2_web_acl" "default" {

visibility_config {
cloudwatch_metrics_enabled = false
metric_name = "static-site-${var.product}-${var.component}"
metric_name = "static-site-${var.tags.product}-${var.tags.component}"
sampled_requests_enabled = false
}

Expand Down
10 changes: 5 additions & 5 deletions modules/products/static-site/cloudfront.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
resource "aws_cloudfront_origin_access_control" "static_site_identity" {
name = "cc-static-site-${var.product}-${var.component}"
description = "Origin access control for ${var.product} ${var.component}"
name = "cc-static-site-${var.tags.product}-${var.tags.component}"
description = "Origin access control for ${var.tags.product} ${var.tags.component}"
origin_access_control_origin_type = "s3"
signing_behavior = "always"
signing_protocol = "sigv4"
Expand All @@ -14,7 +14,7 @@ resource "aws_cloudfront_distribution" "static_site_distribution" {

enabled = true
is_ipv6_enabled = true
comment = "Cloudfront distribution for ${var.product} ${var.component}"
comment = "Cloudfront distribution for ${var.tags.product} ${var.tags.component}"
default_root_object = "index.html"

# logging_config {
Expand All @@ -23,7 +23,7 @@ resource "aws_cloudfront_distribution" "static_site_distribution" {
# prefix = "myprefix"
# }

aliases = var.cloudfront_aliases
aliases = var.cloud_front_vars.cloudfront_aliases

default_cache_behavior {
allowed_methods = ["DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT"]
Expand All @@ -44,7 +44,7 @@ resource "aws_cloudfront_distribution" "static_site_distribution" {
max_ttl = 86400
}

price_class = var.cloudfront_price_class
price_class = var.cloud_front_vars.cloudfront_price_class

tags = local.common_tags

Expand Down
4 changes: 2 additions & 2 deletions modules/products/static-site/iam.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
resource "aws_iam_role" "static_site_actions_push" {
name = "cc-static-site-${var.product}-${var.component}"
name = "cc-static-site-${var.tags.product}-${var.tags.component}"
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [
Expand All @@ -12,7 +12,7 @@ resource "aws_iam_role" "static_site_actions_push" {
}
Condition = {
StringLike = {
"token.actions.githubusercontent.com:sub:" : var.repository
"token.actions.githubusercontent.com:sub:" : var.tags.repository
"sts:RoleSessionName" : "GitHubActions"
}
StringEquals = {
Expand Down
29 changes: 3 additions & 26 deletions modules/products/static-site/main.tf
Original file line number Diff line number Diff line change
@@ -1,32 +1,9 @@
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
}
}

backend "s3" {
bucket = ""
key = "states/terraform.tfstate"
region = "eu-west-2"
encrypt = true
dynamodb_table = ""
}
}

provider "aws" {
region = "eu-west-2"
}

#locals {
# web_url = var.environment == "production" ? var.domain_name : "${var.environment}.${var.domain_name}"
# bucket_name = var.environment == "production" ? var.bucket_name : "${var.environment}.${var.bucket_name}"
#}

locals {
common_tags = {
COST_CENTRE = var.COST_CENTRE
PRODUCT = var.product
COMPONENT = var.component
COST_CENTRE = var.tags.COST_CENTRE
PRODUCT = var.tags.product
COMPONENT = var.tags.component
}
}
2 changes: 1 addition & 1 deletion modules/products/static-site/storage.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
resource "aws_s3_bucket" "static_site" {
bucket = "cc-static-site-${var.product}-${var.component}"
bucket = "cc-static-site-${var.tags.product}-${var.tags.component}"

tags = local.common_tags
}
Expand Down
45 changes: 7 additions & 38 deletions modules/products/static-site/variables.tf
Original file line number Diff line number Diff line change
@@ -1,42 +1,11 @@
#Global
variable "product" {
description = "The name of the product"
type = string
variable "tags" {
type = any
}

variable "component" {
description = "The name of the component"
type = string
variable "cloud_front_vars" {
type = any
}

variable "COST_CENTRE" {
description = "The cost code of the project"
type = string
}


#Cloudfront

variable "cloudfront_aliases" {
description = "CloudFront aliases to apply using custom DNS record"
type = list(string)
default = []
}

variable "cloudfront_price_class" {
description = "Price class for the CloudFront distribution"
type = string
default = "PriceClass_100"
}


#IAM

variable "repository" {
description = "The repository containing the files for the static site"
type = string
validation {
condition = startswith(var.repository, "UKHomeOffice/")
error_message = "Should be in the UKHomeOffice organisation"
}
}
variable "aws_region" {
type = string
}

0 comments on commit 643b9fd

Please sign in to comment.