Skip to content

Commit

Permalink
QPPSE-629: Added tf code for terraform state bucket.
Browse files Browse the repository at this point in the history
  • Loading branch information
korrapati-kris committed Jun 15, 2023
1 parent 73c56f9 commit b1f203e
Show file tree
Hide file tree
Showing 4 changed files with 164 additions and 0 deletions.

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

22 changes: 22 additions & 0 deletions infrastructure/terraform/terraform-state-bucket/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "=4.67.0"
}
}
required_version = "1.0.0"
}

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

terraform {
backend "s3" {
bucket = "qppsf-conversion-tool-tf-state"
key = "qppsf/conversion-tool-tf-state-bucket.tfstate"
region = "us-east-1"
encrypt = "true"
}
}
73 changes: 73 additions & 0 deletions infrastructure/terraform/terraform-state-bucket/state-bucket.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
resource "aws_s3_bucket" "terraform-state-bucket" {
bucket = "qppsf-conversion-tool-tf-state"

tags = {
"Name" = "qppsf-conversion-tool-tf-state"
"qpp:owner" = var.owner
"qpp:environment" = var.environment
"qpp:Name" = "qppsf-ct"
"qpp:pagerduty-email" = var.pagerduty_email
"qpp:sensitivity" = var.sensitivity
"qpp:application" = "qppsf-ct"
"qpp:description" = "Conversion-Tools Terraform State Bucket"
"qpp-cross-acc-s3-replication" = "us-east-1"
}
}

resource "aws_s3_bucket_public_access_block" "terraform-state-bucket_public_block" {
bucket = aws_s3_bucket.terraform-state-bucket.id

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

resource "aws_s3_bucket_server_side_encryption_configuration" "terraform-state-bucket_encryption" {
bucket = aws_s3_bucket.terraform-state-bucket.id

rule {
apply_server_side_encryption_by_default {
sse_algorithm = "AES256"
}
bucket_key_enabled = false
}
}

resource "aws_s3_bucket_versioning" "terraform-state-bucket_versioning" {
bucket = aws_s3_bucket.terraform-state-bucket.id
versioning_configuration {
status = "Enabled"
}
}

resource "aws_s3_bucket_policy" "terraform-state-bucket_bucket_policy" {
bucket = aws_s3_bucket.terraform-state-bucket.id
policy = data.aws_iam_policy_document.terraform-state-bucket_bucket_policy.json
}

data "aws_iam_policy_document" "terraform-state-bucket_bucket_policy" {
statement {
sid = "AllowSSLRequestsOnly"
effect = "Deny"
principals {
type = "*"
identifiers = ["*"]
}

actions = [
"s3:*",
]

resources = [
aws_s3_bucket.terraform-state-bucket.arn,
"${aws_s3_bucket.terraform-state-bucket.arn}/*",
]

condition {
test = "Bool"
variable = "aws:SecureTransport"
values = ["false"]
}
}
}
44 changes: 44 additions & 0 deletions infrastructure/terraform/terraform-state-bucket/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
variable "region" {
description = "The AWS region to use"
type = string
default = "us-east-1"
}

variable "project_name" {
description = "Team or Project"
type = string
default = "qppsf-ct"
}

variable "environment" {
description = "Name of the Environment"
type = string
default = "common"
}

variable "owner" {
description = "Resource Owner"
type = string
default = "qpp-final-scoring-devops@semanticbits.com"
}

variable "pagerduty_email" {
description = "Team pagerduty notifications email endpoint"
type = string
default = "qpp-final-scoring-devops@semanticbits.com"
}

variable "application" {
type = string
default = "qpp-conversion-tools"
}

variable "sensitivity" {
type = string
default = "confidential"
}

variable "git-origin" {
type = string
default = "https://https://github.com/CMSgov/qpp-conversion-tool.git"
}

0 comments on commit b1f203e

Please sign in to comment.