Skip to content

Commit b86ea9b

Browse files
author
Dominic Dumrauf (MacBook Pro 2017)
committed
Adding TF module files
1 parent 3038226 commit b86ea9b

File tree

4 files changed

+145
-0
lines changed

4 files changed

+145
-0
lines changed

main.tf

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
locals {
2+
full_bucket_name = "${var.repository_name}-${var.bucket_name}"
3+
}
4+
5+
resource "aws_s3_bucket" "helm-chart-repository" {
6+
bucket = "${local.full_bucket_name}"
7+
8+
# Allows read access to objects not uploaded by the bucket owner; see <https://docs.aws.amazon.com/AmazonS3/latest/dev/WebsiteAccessPermissionsReqd.html> for details
9+
acl = "public-read"
10+
11+
force_destroy = "${var.is_forcing_destroy}"
12+
13+
logging {
14+
target_bucket = "${var.log_bucket_id}"
15+
target_prefix = "${var.repository_name}/${local.full_bucket_name}/"
16+
}
17+
18+
versioning {
19+
enabled = "${var.is_versioning_enabled}"
20+
}
21+
22+
website {
23+
index_document = "index.html"
24+
}
25+
26+
tags {
27+
Terraform = true
28+
Helm-Chart-Repository = true
29+
}
30+
}
31+
32+
data "aws_iam_policy_document" "helm-chart-repository-policy-document" {
33+
# Minimum permission required for website access; see <https://docs.aws.amazon.com/AmazonS3/latest/dev/WebsiteAccessPermissionsReqd.html> for details
34+
statement {
35+
sid = "PublicReadGetObject"
36+
effect = "Allow"
37+
38+
principals {
39+
type = "*"
40+
identifiers = ["*"]
41+
}
42+
43+
actions = ["s3:GetObject"]
44+
resources = ["${aws_s3_bucket.helm-chart-repository.arn}/*"]
45+
}
46+
}
47+
48+
resource "aws_s3_bucket_policy" "helm-chart-repository-bucket-policy" {
49+
bucket = "${aws_s3_bucket.helm-chart-repository.id}"
50+
policy = "${data.aws_iam_policy_document.helm-chart-repository-policy-document.json}"
51+
}
52+
53+
resource "aws_s3_bucket_object" "helm-chart-repository-index-html" {
54+
bucket = "${local.full_bucket_name}"
55+
key = "index.html"
56+
content = "${data.template_file.helm-chart-repository-index-html.rendered}"
57+
etag = "${md5("${data.template_file.helm-chart-repository-index-html.rendered}")}"
58+
content_type = "text/html"
59+
}

outputs.tf

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
locals {
2+
index_md_file_name = "${local.full_bucket_name}.index.md"
3+
index_md_path = "${path.module}/${local.index_md_file_name}"
4+
index_html_file_name = "${local.full_bucket_name}.index.html"
5+
index_html_path = "${path.module}/${local.index_html_file_name}"
6+
}
7+
8+
data "template_file" "helm-chart-repository-index-md" {
9+
template = "${file("${path.module}/templates/index.md.tpl")}"
10+
11+
vars {
12+
helm_repo_bucket_domain_name = "${aws_s3_bucket.helm-chart-repository.bucket_domain_name}"
13+
helm_repo_website_endpoint = "${aws_s3_bucket.helm-chart-repository.website_endpoint}"
14+
full_bucket_name = "${local.full_bucket_name}"
15+
repository_name = "${var.repository_name}"
16+
index_html_file_name = "${local.index_html_file_name}"
17+
}
18+
}
19+
20+
data "template_file" "helm-chart-repository-index-html" {
21+
template = "${file("${path.module}/templates/index.html.tpl")}"
22+
23+
vars {
24+
rendered_markdown = "${data.template_file.helm-chart-repository-index-md.rendered}"
25+
repository_name = "${var.repository_name}"
26+
}
27+
}
28+
29+
resource "local_file" "helm-chart-repository-index-md" {
30+
content = "${data.template_file.helm-chart-repository-index-md.rendered}"
31+
filename = "${local.index_md_path}"
32+
}
33+
34+
resource "local_file" "helm-chart-repository-index-html" {
35+
content = "${data.template_file.helm-chart-repository-index-html.rendered}"
36+
filename = "${local.index_html_path}"
37+
}
38+
39+
output "helm_chart_repository_bucket_domain_name" {
40+
value = "${aws_s3_bucket.helm-chart-repository.bucket_domain_name}"
41+
}
42+
43+
output "helm_chart_repository_website_endpoint" {
44+
value = "${aws_s3_bucket.helm-chart-repository.website_endpoint}"
45+
}

providers.tf

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
provider "aws" {
2+
region = "${var.region}"
3+
shared_credentials_file = "${var.shared_credentials_file}"
4+
profile = "${var.profile}"
5+
}

variables.tf

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
variable "region" {
2+
description = "The AWS region to use"
3+
}
4+
5+
variable "shared_credentials_file" {
6+
description = "The location of the AWS shared credentials file (e.g. ~dominic/.aws/credentials)"
7+
}
8+
9+
variable "profile" {
10+
description = "The AWS profile to use"
11+
}
12+
13+
variable "bucket_name" {
14+
description = "The name of the S3 bucket to create that will eventually host the Helm chart repository"
15+
}
16+
17+
variable "repository_name" {
18+
description = "The name of the Helm chart repository"
19+
}
20+
21+
variable "log_bucket_id" {
22+
description = "The ID of the S3 bucket to use for storing S3 access logs"
23+
}
24+
25+
variable "is_versioning_enabled" {
26+
description = "Enable versioning?"
27+
default = true
28+
}
29+
30+
variable "is_forcing_destroy" {
31+
description = "Force the bucket to be emptied before deletion when running 'terraform destroy'?"
32+
33+
# Warning: USE AT YOUR OWN RISK!
34+
# Set to 'true' if you want the bucket to be emptied before deletion when running 'terraform destroy'
35+
default = false
36+
}

0 commit comments

Comments
 (0)