forked from hashicorp-education/learn-terraform-circleci
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
72 lines (57 loc) · 1.38 KB
/
main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
}
}
}
provider "aws" {
region = var.region
}
provider "template" {
}
resource "random_uuid" "randomid" {}
resource "aws_iam_user" "circleci" {
name = var.user
path = "/system/"
}
resource "aws_iam_access_key" "circleci" {
user = aws_iam_user.circleci.name
}
data "template_file" "circleci_policy" {
template = file("circleci_s3_access.tpl.json")
vars = {
s3_bucket_arn = aws_s3_bucket.app.arn
}
}
resource "local_file" "circle_credentials" {
filename = "tmp/circleci_credentials"
content = "${aws_iam_access_key.circleci.id}\n${aws_iam_access_key.circleci.secret}"
}
resource "aws_iam_user_policy" "circleci" {
name = "AllowCircleCI"
user = aws_iam_user.circleci.name
policy = data.template_file.circleci_policy.rendered
}
resource "aws_s3_bucket" "app" {
tags = {
Name = "App Bucket"
}
bucket = "${var.app}.${var.label}.${random_uuid.randomid.result}"
acl = "public-read"
website {
index_document = "index.html"
error_document = "error.html"
}
force_destroy = true
}
resource "aws_s3_bucket_object" "app" {
acl = "public-read"
key = "index.html"
bucket = aws_s3_bucket.app.id
content = file("./assets/index.html")
content_type = "text/html"
}
output "Endpoint" {
value = aws_s3_bucket.app.website_endpoint
}