From 3d7522d318911edd5b7b5de907ee9b5c68ca7608 Mon Sep 17 00:00:00 2001 From: bertrand <bpinel@ippon.fr> Date: Fri, 1 Feb 2019 09:24:22 +0100 Subject: [PATCH] Complete Terraform script after trying a full rebuild --- cloud/terraform/bucket.tf | 117 ++++++++++++++++++++++++++++++++ cloud/terraform/cloudfront.tf | 123 ---------------------------------- 2 files changed, 117 insertions(+), 123 deletions(-) delete mode 100644 cloud/terraform/cloudfront.tf diff --git a/cloud/terraform/bucket.tf b/cloud/terraform/bucket.tf index dfd49d2..830525d 100644 --- a/cloud/terraform/bucket.tf +++ b/cloud/terraform/bucket.tf @@ -25,3 +25,120 @@ resource "aws_s3_bucket" "staging" { error_document = "index.html" } } + + +locals { + s3_origin_id = "S3Origin" +} + +resource "aws_cloudfront_distribution" "s3_distribution_production" { + origin { + domain_name = "${element(split("/","${aws_s3_bucket.production.website_endpoint}"),2)}" + origin_id = "${local.s3_origin_id}" + + custom_origin_config { + http_port = 80 + https_port = 443 + origin_protocol_policy = "http-only" + origin_ssl_protocols = ["SSLv3", "TLSv1.1", "TLSv1.2"] + } + } + + enabled = true + http_version = "http2" + is_ipv6_enabled = true + comment = "Production ehipster ClondFront" + default_root_object = "index.html" + + default_cache_behavior { + allowed_methods = ["DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT"] + compress = true + cached_methods = ["GET", "HEAD"] + target_origin_id = "${local.s3_origin_id}" + + forwarded_values { + query_string = true + + cookies { + forward = "none" + } + } + + viewer_protocol_policy = "redirect-to-https" + min_ttl = 0 + default_ttl = 3600 + max_ttl = 86400 + } + + price_class = "PriceClass_All" + + restrictions { + geo_restriction { + restriction_type = "none" + } + } + + tags = { + Environment = "production" + } + + viewer_certificate { + cloudfront_default_certificate = true + } +} + +resource "aws_cloudfront_distribution" "s3_distribution_staging" { + origin { + domain_name = "${element(split("/","${aws_s3_bucket.staging.website_endpoint}"),2)}" + origin_id = "${local.s3_origin_id}" + + custom_origin_config { + http_port = 80 + https_port = 443 + origin_protocol_policy = "http-only" + origin_ssl_protocols = ["SSLv3", "TLSv1.1", "TLSv1.2"] + } + } + + enabled = true + http_version = "http2" + is_ipv6_enabled = true + comment = "Staging ehipster ClondFront" + default_root_object = "index.html" + + default_cache_behavior { + allowed_methods = ["DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT"] + compress = true + cached_methods = ["GET", "HEAD"] + target_origin_id = "${local.s3_origin_id}" + + forwarded_values { + query_string = true + + cookies { + forward = "none" + } + } + + viewer_protocol_policy = "redirect-to-https" + min_ttl = 0 + default_ttl = 3600 + max_ttl = 86400 + } + + price_class = "PriceClass_All" + + restrictions { + geo_restriction { + restriction_type = "none" + } + } + + tags = { + Environment = "staging" + } + + viewer_certificate { + cloudfront_default_certificate = true + } +} diff --git a/cloud/terraform/cloudfront.tf b/cloud/terraform/cloudfront.tf deleted file mode 100644 index b3378b7..0000000 --- a/cloud/terraform/cloudfront.tf +++ /dev/null @@ -1,123 +0,0 @@ - -locals { - s3_origin_id = "S3Origin" -} - -data "aws_s3_bucket" "production" { - bucket = "${var.bucket_name_production}" -} - -data "aws_s3_bucket" "staging" { - bucket = "${var.bucket_name_staging}" -} -resource "aws_cloudfront_distribution" "s3_distribution_production" { - origin { - domain_name = "${element(split("/","${data.aws_s3_bucket.production.website_endpoint}"),2)}" - origin_id = "${local.s3_origin_id}" - - custom_origin_config { - http_port = 80 - https_port = 443 - origin_protocol_policy = "http-only" - origin_ssl_protocols = ["SSLv3", "TLSv1.1", "TLSv1.2"] - } - } - - enabled = true - http_version = "http2" - is_ipv6_enabled = true - comment = "Production ehipster ClondFront" - default_root_object = "index.html" - - default_cache_behavior { - allowed_methods = ["DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT"] - compress = true - cached_methods = ["GET", "HEAD"] - target_origin_id = "${local.s3_origin_id}" - - forwarded_values { - query_string = true - - cookies { - forward = "none" - } - } - - viewer_protocol_policy = "redirect-to-https" - min_ttl = 0 - default_ttl = 3600 - max_ttl = 86400 - } - - price_class = "PriceClass_All" - - restrictions { - geo_restriction { - restriction_type = "none" - } - } - - tags = { - Environment = "production" - } - - viewer_certificate { - cloudfront_default_certificate = true - } -} - -resource "aws_cloudfront_distribution" "s3_distribution_staging" { - origin { - domain_name = "${element(split("/","${data.aws_s3_bucket.staging.website_endpoint}"),2)}" - origin_id = "${local.s3_origin_id}" - - custom_origin_config { - http_port = 80 - https_port = 443 - origin_protocol_policy = "http-only" - origin_ssl_protocols = ["SSLv3", "TLSv1.1", "TLSv1.2"] - } - } - - enabled = true - http_version = "http2" - is_ipv6_enabled = true - comment = "Staging ehipster ClondFront" - default_root_object = "index.html" - - default_cache_behavior { - allowed_methods = ["DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT"] - compress = true - cached_methods = ["GET", "HEAD"] - target_origin_id = "${local.s3_origin_id}" - - forwarded_values { - query_string = true - - cookies { - forward = "none" - } - } - - viewer_protocol_policy = "redirect-to-https" - min_ttl = 0 - default_ttl = 3600 - max_ttl = 86400 - } - - price_class = "PriceClass_All" - - restrictions { - geo_restriction { - restriction_type = "none" - } - } - - tags = { - Environment = "staging" - } - - viewer_certificate { - cloudfront_default_certificate = true - } -} \ No newline at end of file -- GitLab