Skip to content

Commit

Permalink
add terraform resources
Browse files Browse the repository at this point in the history
  • Loading branch information
shubhamv108 committed Feb 1, 2024
1 parent 391a8fb commit 04016d7
Show file tree
Hide file tree
Showing 19 changed files with 335 additions and 4 deletions.
26 changes: 22 additions & 4 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,16 +1,34 @@
.idea/
*.iml
*.iws
.target/
target/
.sonar/
.sonarlint/

.github/
.gradle/
.build/
build/
fluentbit/
grafana/
infra/
k8s/
log/
logs/
prometheus/
scripts/
sonarqube/
telegraf/

.github/

log/
logs/
CHANGELOG.md
CODEOWNERS.md
compose.yaml
CONTRIBUTING.md
HELP.md
Jenkinsfile
LICENSE
Makefile
README.md
sonar-compose.yaml
template-service-java-springboot.postman_collection.json
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,9 @@ out/
## logs
log/
logs/

# terraform
*.tfstate
**/*.tfstate
.terraform/
**/.terraform/
65 changes: 65 additions & 0 deletions infra/.terraform.lock.hcl

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

Empty file added infra/LICENSE
Empty file.
Empty file added infra/README.md
Empty file.
7 changes: 7 additions & 0 deletions infra/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module "project_aws_s3_buckets" {
source = "./modules/aws/s3/buckets"
}

#module "project_aws_cloudfront_distribution" {
# source = "./modules/aws/cloudfront/distribution"
#}
100 changes: 100 additions & 0 deletions infra/modules/aws/cloudfront/distribution/documentssstore.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#resource "aws_cloudfront_distribution" "s3_distribution" {
# origin {
# domain_name = aws_s3_bucket.b.bucket_regional_domain_name
# origin_access_control_id = aws_cloudfront_origin_access_control.default.id
# origin_id = local.s3_origin_id
# }
#
# enabled = true
# is_ipv6_enabled = true
# comment = "Some comment"
#
# logging_config {
# include_cookies = false
# bucket = "mylogs.s3.amazonaws.com"
# prefix = "myprefix"
# }
#
# aliases = ["mysite.example.com", "yoursite.example.com"]
#
# default_cache_behavior {
# allowed_methods = ["DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT"]
# cached_methods = ["GET", "HEAD"]
# target_origin_id = local.s3_origin_id
#
# forwarded_values {
# query_string = false
#
# cookies {
# forward = "none"
# }
# }
#
# viewer_protocol_policy = "allow-all"
# min_ttl = 0
# default_ttl = 3600
# max_ttl = 86400
# }
#
# # Cache behavior with precedence 0
# ordered_cache_behavior {
# path_pattern = "/content/immutable/*"
# allowed_methods = ["GET", "HEAD", "OPTIONS"]
# cached_methods = ["GET", "HEAD", "OPTIONS"]
# target_origin_id = local.s3_origin_id
#
# forwarded_values {
# query_string = false
# headers = ["Origin"]
#
# cookies {
# forward = "none"
# }
# }
#
# min_ttl = 0
# default_ttl = 86400
# max_ttl = 31536000
# compress = true
# viewer_protocol_policy = "redirect-to-https"
# }
#
# # Cache behavior with precedence 1
# ordered_cache_behavior {
# path_pattern = "/content/*"
# allowed_methods = ["GET", "HEAD", "OPTIONS"]
# cached_methods = ["GET", "HEAD"]
# target_origin_id = local.s3_origin_id
#
# forwarded_values {
# query_string = false
#
# cookies {
# forward = "none"
# }
# }
#
# min_ttl = 0
# default_ttl = 3600
# max_ttl = 86400
# compress = true
# viewer_protocol_policy = "redirect-to-https"
# }
#
# price_class = "PriceClass_200"
#
# restrictions {
# geo_restriction {
# restriction_type = "whitelist"
# locations = ["US", "CA", "GB", "DE"]
# }
# }
#
# tags = {
# Environment = "${var.environment}"
# }
#
# viewer_certificate {
# cloudfront_default_certificate = true
# }
#}
Empty file.
Empty file.
20 changes: 20 additions & 0 deletions infra/modules/aws/cloudfront/distribution/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
variable "region" {
type = string
description = "AWS region for all resources."

default = "ap-south-1"
}

variable "project_name" {
type = string
description = "Template service in java, spring-boot project."

default = "template-service-java-spring-boot"
}

variable "environment" {
type = string
description = "Template service in java, spring-boot project."

default = "test"
}
39 changes: 39 additions & 0 deletions infra/modules/aws/s3/buckets/documentssstore.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
resource "aws_s3_bucket" "documentssstore" {
bucket = "documentssstore"

tags = {
Name = "documentssstore"
Owner = "${var.project_name}"
Environment = "${var.environment}"
Region = "${var.region}"
}
}

resource "aws_s3_bucket_policy" "documentssstore_allow_access_from_cloudfront" {
bucket = aws_s3_bucket.documentssstore.id
policy = data.aws_iam_policy_document.documentssstore_allow_access_from_cloudfront.json
}

data "aws_iam_policy_document" "documentssstore_allow_access_from_cloudfront" {
statement {
principals {
type = "AWS"
identifiers = ["cloudfront.amazonaws.com"]
}

actions = [
"s3:GetObject",
]

resources = [
aws_s3_bucket.documentssstore.arn,
"${aws_s3_bucket.documentssstore.arn}/*",
]

condition {
test = "StringEquals"
values = ["arn:aws:cloudfront::430689894701:distribution/E2ZI5IWQWTVER"]
variable = "AWS:SourceArn"
}
}
}
Empty file.
Empty file.
20 changes: 20 additions & 0 deletions infra/modules/aws/s3/buckets/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
variable "region" {
type = string
description = "AWS region for all resources."

default = "ap-south-1"
}

variable "project_name" {
type = string
description = "Template service in java, spring-boot project."

default = "template-service-java-spring-boot"
}

variable "environment" {
type = string
description = "Template service in java, spring-boot project."

default = "test"
}
Empty file added infra/outputs.tf
Empty file.
7 changes: 7 additions & 0 deletions infra/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
provider "aws" {
region = var.region
}

provider "random" {}

provider "time" {}
28 changes: 28 additions & 0 deletions infra/terraform.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: MPL-2.0

terraform {
required_version = "~> 1.6"
required_providers {
aws = {
source = "hashicorp/aws"
version = "5.7.0"
}
random = {
source = "hashicorp/random"
version = "3.5.1"
}
time = {
source = "hashicorp/time"
version = "0.9.1"
}
}
/* Uncomment this block to use Terraform Cloud for this tutorial
cloud {
organization = "organization-name"
workspaces {
name = "learn-terraform-apply"
}
}
*/
}
20 changes: 20 additions & 0 deletions infra/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
variable "region" {
type = string
description = "AWS region for all resources."

default = "ap-south-1"
}

variable "project_name" {
type = string
description = "Template service in java, spring-boot project."

default = "template-service-java-spring-boot"
}

variable "environment" {
type = string
description = "Template service in java, spring-boot project."

default = "test"
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,5 @@ public ResponseEntity<?> save(@RequestBody final SaveDocumentRequest request) {
public ResponseEntity<?> getDownloadURL(@PathVariable("id") final Long id) throws URISyntaxException {
return ResponseUtils.redirect(this.service.getDownloadURL(id));
}

}

0 comments on commit 04016d7

Please sign in to comment.