Skip to content

Instantly share code, notes, and snippets.

@k1LoW
Last active Sep 1, 2017
Embed
What would you like to do?
Test environment for Roadworker `eval $(terraform output | sed 's/ //g' | sed 's/^/export /')`
variable "region" {
default = "ap-northeast-1"
}
variable "availability_zones" {
type = "list"
default = ["ap-northeast-1a", "ap-northeast-1c"]
}
provider "aws" {
region = "${var.region}"
}
data "aws_caller_identity" "current" {}
resource "aws_iam_user" "test-iam-user" {
name = "roadworker-test-iam-user"
path = "/"
}
resource "aws_iam_access_key" "test-iam-key" {
user = "${aws_iam_user.test-iam-user.name}"
}
resource "aws_iam_user_policy" "test-iam-user-policy" {
name = "roadworker-test-iam-user-policy"
user = "${aws_iam_user.test-iam-user.name}"
policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"cloudfront:*",
"ec2:*",
"elasticloadbalancing:*",
"route53:*"
],
"Effect": "Allow",
"Resource": "*"
}
]
}
EOF
}
resource "aws_elb" "test_elb" {
name = "roadworker-test"
availability_zones = "${var.availability_zones}"
listener {
instance_port = 80
instance_protocol = "http"
lb_port = 80
lb_protocol = "http"
}
}
resource "aws_vpc" "test_vpc1" {
cidr_block = "10.0.0.0/16"
tags {
Name = "roadworker test vpc1"
}
}
resource "aws_vpc" "test_vpc2" {
cidr_block = "10.0.0.0/16"
tags {
Name = "roadworker test vpc2"
}
}
resource "aws_cloudfront_origin_access_identity" "test_cf_origin_access_identity" {
comment = "roadworker test"
}
resource "aws_s3_bucket" "test_cf_s3_bucket" {
bucket = "roadworker-test-${md5(data.aws_caller_identity.current.user_id)}"
acl = "public-read"
force_destroy = true
versioning {
enabled = false
}
website {
index_document = "index.html"
error_document = "error.html"
}
}
resource "aws_cloudfront_distribution" "test-cf" {
enabled = true
comment = "roadworker test"
default_root_object = "${aws_s3_bucket.test_cf_s3_bucket.website.0.index_document}"
price_class = "PriceClass_100"
retain_on_delete = false
origin {
domain_name = "${format("%s%s", aws_s3_bucket.test_cf_s3_bucket.id, ".s3.amazonaws.com")}"
origin_id = "roadworker-test-${md5(data.aws_caller_identity.current.user_id)}"
s3_origin_config {
origin_access_identity = "${aws_cloudfront_origin_access_identity.test_cf_origin_access_identity.cloudfront_access_identity_path}"
}
}
default_cache_behavior {
allowed_methods = ["GET", "HEAD"]
cached_methods = ["GET", "HEAD"]
target_origin_id = "roadworker-test-${md5(data.aws_caller_identity.current.user_id)}"
forwarded_values {
query_string = false
cookies {
forward = "none"
}
}
viewer_protocol_policy = "redirect-to-https"
min_ttl = 0
default_ttl = 3600
max_ttl = 86400
}
restrictions {
geo_restriction {
restriction_type = "none"
}
}
viewer_certificate {
cloudfront_default_certificate = true
}
}
output "TEST_AWS_ACCESS_KEY_ID" {
value = "${aws_iam_access_key.test-iam-key.id}"
}
output "TEST_AWS_SECRET_ACCESS_KEY" {
value = "${aws_iam_access_key.test-iam-key.secret}"
}
output "TEST_ELB" {
value = "${aws_elb.test_elb.dns_name}."
}
output "TEST_CF" {
value = "${aws_cloudfront_distribution.test-cf.domain_name}."
}
output "TEST_VPC_REGION" {
value = "${var.region}"
}
output "TEST_VPC1" {
value = "${aws_vpc.test_vpc1.id}"
}
output "TEST_VPC2" {
value = "${aws_vpc.test_vpc2.id}"
}
output "AWS_REGION" {
value = "${var.region}"
}
output "TEST_DELAY" {
value = "0.3"
}
output "TEST_INTERVAL" {
value = "3"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment