├── module ├── .DS_Store ├── cloudfront │ ├── variables.tf │ ├── outputs.tf │ └── main.tf ├── s3 │ ├── HNG-first │ │ ├── IMG20210204072904.jpg │ │ ├── script.js │ │ ├── index.html │ │ └── styles.css │ ├── outputs.tf │ ├── variables.tf │ └── main.tf ├── route53 │ ├── output.tf │ ├── variables.tf │ └── main.tf └── acm │ ├── output.tf │ ├── variables.tf │ └── main.tf ├── variables.tf └── main.tf /module/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tonnero234/conrad-assignment/HEAD/module/.DS_Store -------------------------------------------------------------------------------- /module/cloudfront/variables.tf: -------------------------------------------------------------------------------- 1 | variable "bucket_name" { 2 | description = "The name of the S3 bucket." 3 | type = string 4 | } 5 | -------------------------------------------------------------------------------- /module/s3/HNG-first/IMG20210204072904.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tonnero234/conrad-assignment/HEAD/module/s3/HNG-first/IMG20210204072904.jpg -------------------------------------------------------------------------------- /module/s3/HNG-first/script.js: -------------------------------------------------------------------------------- 1 | document.addEventListener('DOMContentLoaded', function() { 2 | console.log('Welcome to Noah Anthony Imanche\'s portfolio!'); 3 | 4 | }); 5 | -------------------------------------------------------------------------------- /module/route53/output.tf: -------------------------------------------------------------------------------- 1 | output "main_domain_zone_id" { 2 | description = "The Zone ID of the main domain in Route 53." 3 | value = aws_route53_zone.main_domain.zone_id 4 | } 5 | 6 | -------------------------------------------------------------------------------- /module/s3/outputs.tf: -------------------------------------------------------------------------------- 1 | output "bucket_name" { 2 | description = "The name of the S3 bucket." 3 | value = aws_s3_bucket.this.bucket 4 | } 5 | 6 | output "bucket_arn" { 7 | description = "The ARN of the S3 bucket." 8 | value = aws_s3_bucket.this.arn 9 | } 10 | -------------------------------------------------------------------------------- /module/s3/variables.tf: -------------------------------------------------------------------------------- 1 | variable "bucket_name" { 2 | description = "The name of the S3 bucket." 3 | type = string 4 | } 5 | 6 | variable "origin_access_identity_id" { 7 | description = "The ID of the CloudFront origin access identity." 8 | type = string 9 | } 10 | -------------------------------------------------------------------------------- /variables.tf: -------------------------------------------------------------------------------- 1 | variable "aws_region" { 2 | description = "The AWS region to deploy the resources." 3 | type = string 4 | default = "us-west-2" 5 | } 6 | 7 | variable "bucket_name" { 8 | description = "The name of the S3 bucket." 9 | type = string 10 | default = "tony-altschool" 11 | } 12 | -------------------------------------------------------------------------------- /module/acm/output.tf: -------------------------------------------------------------------------------- 1 | output "certificate_arn" { 2 | description = "The ARN of the ACM certificate." 3 | value = aws_acm_certificate.this.arn 4 | } 5 | 6 | output "certificate_domain_name" { 7 | description = "The domain name associated with the ACM certificate." 8 | value = aws_acm_certificate.this.domain_name 9 | } 10 | -------------------------------------------------------------------------------- /module/route53/variables.tf: -------------------------------------------------------------------------------- 1 | variable "aws_region" { 2 | description = "us-east-1" 3 | type = string 4 | } 5 | 6 | variable "main_domain" { 7 | description = "tonynoah.me" 8 | type = string 9 | } 10 | 11 | 12 | 13 | variable "alias_target_domain_name" { 14 | description = "d26xp1i2yvoxpw.cloudfront.net" 15 | type = string 16 | } 17 | 18 | variable "alias_target_zone_id" { 19 | description = "Z0273290C20QSK62JJJ2" 20 | type = string 21 | } 22 | -------------------------------------------------------------------------------- /module/acm/variables.tf: -------------------------------------------------------------------------------- 1 | variable "domain_name" { 2 | description = "tonynoah.me" 3 | type = string 4 | } 5 | 6 | variable "validation_method" { 7 | description = "The method to use for validation. DNS or EMAIL." 8 | type = string 9 | default = "DNS" 10 | } 11 | 12 | variable "environment" { 13 | description = "The environment name for tagging purposes." 14 | type = string 15 | } 16 | 17 | variable "aws_region" { 18 | description = "us-east-1" 19 | type = string 20 | } 21 | -------------------------------------------------------------------------------- /module/acm/main.tf: -------------------------------------------------------------------------------- 1 | resource "aws_acm_certificate" "this" { 2 | domain_name = var.domain_name 3 | validation_method = var.validation_method 4 | 5 | lifecycle { 6 | create_before_destroy = true 7 | } 8 | 9 | tags = { 10 | Environment = var.environment 11 | } 12 | } 13 | 14 | resource "aws_acm_certificate_validation" "this" { 15 | certificate_arn = aws_acm_certificate.this.arn 16 | validation_record_fqdns = [for option in aws_acm_certificate.this.domain_validation_options : option.resource_record_name] 17 | } 18 | -------------------------------------------------------------------------------- /module/route53/main.tf: -------------------------------------------------------------------------------- 1 | resource "aws_route53_zone" "main_domain" { 2 | name = var.main_domain 3 | } 4 | 5 | resource "aws_route53_record" "main_domain_record" { 6 | zone_id = "Z0273290C20QSK62JJJ2" # Replace with the correct hosted zone ID 7 | name = var.main_domain 8 | type = "A" 9 | 10 | alias { 11 | name = "d26xp1i2yvoxpw.cloudfront.net" 12 | zone_id = "Z0273290C20QSK62JJJ2" # Replace with the correct hosted zone ID 13 | evaluate_target_health = false 14 | } 15 | } -------------------------------------------------------------------------------- /module/cloudfront/outputs.tf: -------------------------------------------------------------------------------- 1 | output "distribution_id" { 2 | description = "The ID of the CloudFront distribution." 3 | value = aws_cloudfront_distribution.this.id 4 | } 5 | 6 | output "distribution_domain_name" { 7 | description = "The domain name of the CloudFront distribution." 8 | value = aws_cloudfront_distribution.this.domain_name 9 | } 10 | 11 | output "origin_access_identity_id" { 12 | description = "The ID of the CloudFront origin access identity." 13 | value = aws_cloudfront_origin_access_identity.this.id 14 | } 15 | -------------------------------------------------------------------------------- /main.tf: -------------------------------------------------------------------------------- 1 | provider "aws" { 2 | region = var.aws_region 3 | } 4 | 5 | module "s3_bucket" { 6 | source = "./module/s3" 7 | bucket_name = var.bucket_name 8 | origin_access_identity_id = module.cloudfront_distribution.origin_access_identity_id 9 | } 10 | 11 | module "cloudfront_distribution" { 12 | source = "./module/cloudfront" 13 | 14 | bucket_name = var.bucket_name 15 | } 16 | 17 | module "aws_route53" { 18 | source = "./module/route53" 19 | aws_region = "us-east-1" 20 | main_domain = "tonynoah.me" 21 | alias_target_domain_name = module.cloudfront_distribution.distribution_domain_name 22 | alias_target_zone_id = module.cloudfront_distribution.distribution_id 23 | 24 | } 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /module/s3/main.tf: -------------------------------------------------------------------------------- 1 | resource "aws_s3_bucket" "this" { 2 | bucket = var.bucket_name 3 | 4 | 5 | 6 | tags = { 7 | Name = var.bucket_name 8 | Environment = "Production" 9 | } 10 | } 11 | 12 | resource "aws_s3_bucket_policy" "this" { 13 | bucket = aws_s3_bucket.this.id 14 | 15 | policy = jsonencode({ 16 | Version = "2012-10-17" 17 | Statement = [ 18 | { 19 | Effect = "Allow" 20 | Principal = { 21 | AWS = "arn:aws:iam::cloudfront:user/CloudFront Origin Access Identity ${var.origin_access_identity_id}" 22 | } 23 | Action = "s3:GetObject" 24 | Resource = "arn:aws:s3:::${aws_s3_bucket.this.id}/*" 25 | } 26 | ] 27 | }) 28 | } 29 | 30 | resource "aws_s3_bucket_public_access_block" "this" { 31 | bucket = aws_s3_bucket.this.id 32 | 33 | block_public_acls = true 34 | block_public_policy = true 35 | ignore_public_acls = true 36 | restrict_public_buckets = true 37 | } 38 | 39 | 40 | resource "aws_s3_object" "files_upload" { 41 | for_each = fileset("module/s3/HNG-first/", "**/*.*") 42 | bucket = var.bucket_name 43 | key = each.value 44 | source = "module/s3/HNG-first/${each.value}" 45 | content_type = "text/html" 46 | } 47 | 48 | -------------------------------------------------------------------------------- /module/cloudfront/main.tf: -------------------------------------------------------------------------------- 1 | resource "aws_cloudfront_origin_access_identity" "this" { 2 | comment = "Access to S3 bucket ${var.bucket_name}" 3 | } 4 | 5 | resource "aws_cloudfront_distribution" "this" { 6 | origin { 7 | domain_name = "${var.bucket_name}.s3.amazonaws.com" 8 | origin_id = "S3-${var.bucket_name}" 9 | 10 | s3_origin_config { 11 | origin_access_identity = aws_cloudfront_origin_access_identity.this.cloudfront_access_identity_path 12 | } 13 | } 14 | 15 | enabled = true 16 | is_ipv6_enabled = true 17 | comment = "CloudFront distribution for ${var.bucket_name}" 18 | default_root_object = "index.html" 19 | 20 | default_cache_behavior { 21 | allowed_methods = ["GET", "HEAD"] 22 | cached_methods = ["GET", "HEAD"] 23 | target_origin_id = "S3-${var.bucket_name}" 24 | 25 | forwarded_values { 26 | query_string = false 27 | cookies { 28 | forward = "none" 29 | } 30 | } 31 | 32 | viewer_protocol_policy = "redirect-to-https" 33 | 34 | min_ttl = 0 35 | default_ttl = 3600 36 | max_ttl = 86400 37 | } 38 | 39 | restrictions { 40 | geo_restriction { 41 | restriction_type = "none" 42 | } 43 | } 44 | 45 | viewer_certificate { 46 | cloudfront_default_certificate = true 47 | } 48 | 49 | tags = { 50 | Name = "cloudfront-${var.bucket_name}" 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /module/s3/HNG-first/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 6 |Cloud Engineering Trainee at HNG
13 |
18 | Hello! my name is Noah Anthony Imanche, I am passionate about cloud engineering and constantly upskilling my tech skills. I am currently an intern with HNG
19 |