-
Notifications
You must be signed in to change notification settings - Fork 5
Init #1
Changes from 4 commits
8302840
6be76a9
11d14ea
27ad1a8
2626f58
c06dde1
96cd74a
c60c3e9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| # Define composite variables for resources | ||
| module "label" { | ||
| source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.2.1" | ||
| namespace = "${var.namespace}" | ||
| name = "${var.name}" | ||
| stage = "${var.stage}" | ||
| attributes = ["s3", "stored"] | ||
| } | ||
|
|
||
| data "template_file" "default" { | ||
| template = "${file("${path.module}/user_data.sh")}" | ||
|
|
||
| vars { | ||
| s3_path = "${aws_s3_bucket_object.default.bucket}${aws_s3_bucket_object.default.key}" | ||
|
||
| } | ||
| } | ||
|
|
||
| resource "aws_s3_bucket_object" "default" { | ||
| bucket = "${var.bucket}" | ||
| key = "${var.path}/user_data.sh" | ||
| content = "${join("\n", var.user_data)}" | ||
|
||
| etag = "${md5(join("\n", var.user_data))}" | ||
| } | ||
|
|
||
| ## IAM Role Policy that allows access to S3 | ||
| resource "aws_iam_policy" "default" { | ||
| name = "${module.label.id}" | ||
|
|
||
| lifecycle { | ||
| create_before_destroy = true | ||
| } | ||
|
|
||
| policy = "${data.aws_iam_policy_document.default.json}" | ||
| } | ||
|
|
||
| data "aws_iam_policy_document" "default" { | ||
| statement { | ||
| actions = [ | ||
| "s3:ListAllMyBuckets", | ||
| ] | ||
|
|
||
| effect = "Allow" | ||
|
|
||
| resources = [ | ||
| "arn:aws:s3:::*", | ||
|
||
| ] | ||
| } | ||
|
|
||
| statement { | ||
| actions = [ "s3:ListBucket" ] | ||
|
|
||
| effect = "Allow" | ||
|
|
||
| resources = [ | ||
| "${format("arn:aws:s3:::%v", aws_s3_bucket_object.default.bucket)}" | ||
| ] | ||
| } | ||
|
|
||
| statement { | ||
| actions = [ "s3:*" ] | ||
|
||
|
|
||
| effect = "Allow" | ||
|
|
||
| resources = [ | ||
| "${format("arn:aws:s3:::%v%v", aws_s3_bucket_object.default.bucket, aws_s3_bucket_object.default.key)}" | ||
| ] | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| output "user_data" { | ||
| value = "${data.template_file.default.rendered}" | ||
| } | ||
|
|
||
| output "policy_arn" { | ||
| value = "${aws_iam_policy.default.arn}" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
|
|
||
| ############## | ||
| # Install deps | ||
| ############## | ||
|
||
|
|
||
| apt-get -y install python-pip | ||
|
|
||
| # Install AWS Client | ||
| pip install --upgrade awscli | ||
|
|
||
| aws s3 cp s3://${s3_path} /tmp/user_data.sh | ||
|
||
|
|
||
| eval "$(cat /tmp/user_data.sh)" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. because user data does not contains |
||
|
|
||
| rm -rf /tmp/user_data.sh | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| variable "namespace" { | ||
| default = "global" | ||
| } | ||
|
|
||
| variable "stage" { | ||
| default = "default" | ||
| } | ||
|
|
||
| variable "name" {} | ||
|
|
||
| variable "bucket" {} | ||
|
|
||
| variable "path" { | ||
| default = "/" | ||
| } | ||
|
|
||
| variable "user_data" { | ||
| type = "list" | ||
| default = [] | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/stored/user-data/Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
drops3since I don't think we need that in the bucket name (it's implied)Aha, I see. I thought it would be used for the bucket name, but it's used for a policy. We can keep it.