Skip to content

Commit df36135

Browse files
authored
[aws/artifacts] Add S3 bucket for storage (#54)
* artifact storage * Update aws/artifacts/variables.tf Co-Authored-By: osterman <[email protected]> * add description * Use CDN * format * Add output descriptions * add descriptions
1 parent 0b7da15 commit df36135

File tree

4 files changed

+218
-0
lines changed

4 files changed

+218
-0
lines changed

aws/artifacts/Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
plan:
2+
@tfenv terraform $@
3+
4+
apply:
5+
@tfenv terraform $@
6+
7+
destroy:
8+
@tfenv terraform $@

aws/artifacts/main.tf

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
terraform {
2+
required_version = ">= 0.11.2"
3+
4+
backend "s3" {}
5+
}
6+
7+
provider "aws" {
8+
alias = "virginia"
9+
region = "us-east-1"
10+
11+
assume_role {
12+
role_arn = "${var.aws_assume_role_arn}"
13+
}
14+
}
15+
16+
# https://www.terraform.io/artifacts/providers/aws/d/acm_certificate.html
17+
data "aws_acm_certificate" "acm_cloudfront_certificate" {
18+
provider = "aws.virginia"
19+
domain = "${var.domain_name}"
20+
statuses = ["ISSUED"]
21+
types = ["AMAZON_ISSUED"]
22+
}
23+
24+
locals {
25+
name = "artifacts"
26+
cdn_domain = "artifacts.${var.domain_name}"
27+
artifacts_user_arn = "arn:aws:iam::${var.aws_account_id}:user/${var.namespace}-${var.stage}-${local.name}"
28+
}
29+
30+
module "artifacts_user" {
31+
source = "git::https://github.com/cloudposse/terraform-aws-iam-system-user.git?ref=tags/0.2.2"
32+
namespace = "${var.namespace}"
33+
stage = "${var.stage}"
34+
name = "${local.name}"
35+
}
36+
37+
module "origin" {
38+
source = "git::https://github.com/cloudposse/terraform-aws-s3-website.git?ref=tags/0.5.2"
39+
namespace = "${var.namespace}"
40+
stage = "${var.stage}"
41+
name = "${local.name}"
42+
hostname = "${local.cdn_domain}"
43+
parent_zone_name = "${var.domain_name}"
44+
region = "${var.region}"
45+
cors_allowed_headers = ["*"]
46+
cors_allowed_methods = ["GET"]
47+
cors_allowed_origins = ["*"]
48+
cors_max_age_seconds = "3600"
49+
cors_expose_headers = ["ETag"]
50+
index_document = "index.html"
51+
error_document = "404.html"
52+
53+
deployment_arns = {
54+
"${local.artifacts_user_arn}" = [""]
55+
}
56+
57+
deployment_actions = [
58+
"s3:PutObjectAcl",
59+
"s3:PutObject",
60+
"s3:GetObject",
61+
"s3:DeleteObject",
62+
"s3:AbortMultipartUpload",
63+
]
64+
}
65+
66+
# CloudFront CDN fronting origin
67+
module "cdn" {
68+
source = "git::https://github.com/cloudposse/terraform-aws-cloudfront-cdn.git?ref=tags/0.5.7"
69+
namespace = "${var.namespace}"
70+
stage = "${var.stage}"
71+
name = "${local.name}"
72+
aliases = ["${local.cdn_domain}", "artifacts.cloudposse.com"]
73+
origin_domain_name = "${module.origin.s3_bucket_website_endpoint}"
74+
origin_protocol_policy = "http-only"
75+
viewer_protocol_policy = "redirect-to-https"
76+
parent_zone_name = "${var.domain_name}"
77+
forward_cookies = "none"
78+
forward_headers = ["Origin", "Access-Control-Request-Headers", "Access-Control-Request-Method"]
79+
default_ttl = 60
80+
min_ttl = 0
81+
max_ttl = 86400
82+
compress = "true"
83+
cached_methods = ["GET", "HEAD"]
84+
allowed_methods = ["GET", "HEAD", "OPTIONS"]
85+
price_class = "PriceClass_All"
86+
default_root_object = "index.html"
87+
acm_certificate_arn = "${data.aws_acm_certificate.acm_cloudfront_certificate.arn}"
88+
}

aws/artifacts/outputs.tf

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
output "artifacts_user_name" {
2+
value = "${module.artifacts_user.user_name}"
3+
description = "Normalized IAM user name"
4+
}
5+
6+
output "artifacts_user_arn" {
7+
value = "${module.artifacts_user.user_arn}"
8+
description = "The ARN assigned by AWS for the user"
9+
}
10+
11+
output "artifacts_user_unique_id" {
12+
value = "${module.artifacts_user.user_unique_id}"
13+
description = "The user unique ID assigned by AWS"
14+
}
15+
16+
output "artifacts_user_access_key_id" {
17+
value = "${module.artifacts_user.access_key_id}"
18+
description = "The access key ID"
19+
}
20+
21+
output "artifacts_user_secret_access_key" {
22+
value = "${module.artifacts_user.secret_access_key}"
23+
description = "The secret access key. This will be written to the state file in plain-text"
24+
}
25+
26+
output "artifacts_s3_bucket_name" {
27+
value = "${module.origin.s3_bucket_name}"
28+
description = "The S3 bucket which serves as the origin for the CDN and S3 website"
29+
}
30+
31+
output "artifacts_s3_bucket_domain_name" {
32+
value = "${module.origin.s3_bucket_domain_name}"
33+
description = "The bucket domain name. Will be of format bucketname.s3.amazonaws.com."
34+
}
35+
36+
output "artifacts_s3_bucket_arn" {
37+
value = "${module.origin.s3_bucket_arn}"
38+
description = "The ARN of the bucket. Will be of format arn:aws:s3:::bucketname."
39+
}
40+
41+
output "artifacts_s3_bucket_website_endpoint" {
42+
value = "${module.origin.s3_bucket_website_endpoint}"
43+
description = "The website endpoint, if the bucket is configured with a website. If not, this will be an empty string."
44+
}
45+
46+
output "artifacts_s3_bucket_website_domain" {
47+
value = "${module.origin.s3_bucket_website_domain}"
48+
description = "The domain of the website endpoint, if the bucket is configured with a website. If not, this will be an empty string. This is used to create Route 53 alias records."
49+
}
50+
51+
output "artifacts_s3_bucket_hosted_zone_id" {
52+
value = "${module.origin.s3_bucket_hosted_zone_id}"
53+
description = "The Route 53 Hosted Zone ID for this bucket's region."
54+
}
55+
56+
output "artifacts_cloudfront_id" {
57+
value = "${module.cdn.cf_id}"
58+
description = "The identifier for the distribution. For example: EDFDVBD632BHDS5."
59+
}
60+
61+
output "artifacts_cloudfront_arn" {
62+
value = "${module.cdn.cf_arn}"
63+
description = "The ARN (Amazon Resource Name) for the distribution. For example: arn:aws:cloudfront::123456789012:distribution/EDFDVBD632BHDS5, where 123456789012 is your AWS account ID."
64+
}
65+
66+
output "artifacts_cloudfront_aliases" {
67+
value = "${module.cdn.cf_aliases}"
68+
description = "Extra CNAMEs (alternate domain names), if any, for this distribution."
69+
}
70+
71+
output "artifacts_cloudfront_status" {
72+
value = "${module.cdn.cf_status}"
73+
description = "The current status of the distribution. Deployed if the distribution's information is fully propagated throughout the Amazon CloudFront system."
74+
}
75+
76+
output "artifacts_cloudfront_domain_name" {
77+
value = "${module.cdn.cf_domain_name}"
78+
description = "The domain name corresponding to the distribution. For example: d604721fxaaqy9.cloudfront.net."
79+
}
80+
81+
output "artifacts_cloudfront_etag" {
82+
value = "${module.cdn.cf_etag}"
83+
description = "The current version of the distribution's information. For example: E2QWRUHAPOMQZL."
84+
}
85+
86+
output "artifacts_cloudfront_hosted_zone_id" {
87+
value = "${module.cdn.cf_hosted_zone_id}"
88+
description = "The CloudFront Route 53 zone ID that can be used to route an Alias Resource Record Set to. This attribute is simply an alias for the zone ID Z2FDTNDATAQYW2."
89+
}
90+
91+
output "artifacts_cloudfront_origin_access_identity_path" {
92+
value = "${module.cdn.cf_origin_access_identity}"
93+
description = "The CloudFront origin access identity to associate with the origin."
94+
}

aws/artifacts/variables.tf

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
variable "aws_assume_role_arn" {
2+
type = "string"
3+
description = "The ARN of the role to assume"
4+
}
5+
6+
variable "domain_name" {
7+
type = "string"
8+
}
9+
10+
variable "namespace" {
11+
type = "string"
12+
description = "Namespace (e.g. `cp` or `cloudposse`)"
13+
}
14+
15+
variable "stage" {
16+
type = "string"
17+
description = "Stage (e.g. `prod`, `dev`, `staging`)"
18+
}
19+
20+
variable "region" {
21+
type = "string"
22+
description = "AWS region"
23+
}
24+
25+
variable "aws_account_id" {
26+
type = "string"
27+
description = "AWS account ID"
28+
}

0 commit comments

Comments
 (0)