Commit 5f0c2643 by Edward Zarecor

Merge pull request #2418 from edx/e0d/terraform

simple example to introduce terraform
parents fb4a58ac b243a009
This probably makes the most sense in a private repository, but I'm adding it here toyp kick-off the Jenkins site-speed integration. We can move it later.
Note that I've included the tfvars file intentionally as an example, but this would typically be git ignored.
Start by downloading and installing the terraform go binaries. Run
> terraform plan
from the sitespeed directory to see what would happen if this was run against and AWS account.
# Configure the AWS Provider
provider "aws" {
access_key = "${var.aws_access_key}"
secret_key = "${var.aws_secret_key}"
region = "us-east-1"
}
# pipeline-provision infrastructure
resource "aws_sqs_queue" "edx-pipeline-provision-queue" {
name = "${var.queue_name_pipeline}"
delay_seconds = "${var.queue_delay_seconds}"
max_message_size = "${var.queue_max_message_size}"
message_retention_seconds = "${var.queue_message_retention_seconds}"
receive_wait_time_seconds = "${var.queue_receive_wait_time_seconds}"
}
resource "aws_sns_topic" "edx-pipeline-provision" {
name = "edx-pipeline-provision-topic"
}
resource "aws_sns_topic_subscription" "edx-pipeline-provision_sqs_target" {
topic_arn = "${aws_sns_topic.edx-pipeline-provision.arn}"
protocol = "sqs"
endpoint = "${aws_sqs_queue.edx-pipeline-provision-queue.arn}"
}
# pipeline-sitespeed infrastructure
resource "aws_sqs_queue" "edx-pipeline-sitespeed-queue" {
name = "${var.queue_name_sitespeed}"
delay_seconds = "${var.queue_delay_seconds}"
max_message_size = "${var.queue_max_message_size}"
message_retention_seconds = "${var.queue_message_retention_seconds}"
receive_wait_time_seconds = "${var.queue_receive_wait_time_seconds}"
}
resource "aws_sns_topic" "edx-pipeline-sitespeed" {
name = "edx-pipeline-sitespeed-topic"
}
resource "aws_sns_topic_subscription" "edx-pipeline-sitespeed_sqs_target" {
topic_arn = "${aws_sns_topic.edx-pipeline-sitespeed.arn}"
protocol = "sqs"
endpoint = "${aws_sqs_queue.edx-pipeline-sitespeed-queue.arn}"
}
# Create IAM policy, user
resource "aws_iam_user" "build_pipeline_user" {
name = "build_pipeline_user"
}
resource "aws_iam_access_key" "build_pipeline_user_key" {
user = "${aws_iam_user.build_pipeline_user.name}"
}
resource "aws_iam_user_policy" "sns_publish_policy" {
name = "${var.environment}-${var.deployment}-${var.service}-sender"
user = "${aws_iam_user.build_pipeline_user.name}"
policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"sns:Publish"
],
"Effect": "Allow",
"Resource": "${aws_sns_topic.edx-pipeline-provision.arn}"
},
{
"Action": [
"sns:Publish"
],
"Effect": "Allow",
"Resource": "${aws_sns_topic.edx-pipeline-sitespeed.arn}"
}
]
}
EOF
}
#### Copy this file and remove the '.example' extension in order to
#### use it in a terraform execution
environment = "env_foo"
deployment = "my_deployment"
service = "my_ci_service"
# AWS variables
aws_access_key = "FOOBARAIAIAIA"
aws_secret_key = "FOOBAT01010101"
# SQS variables
queue_name_pipeline = "my-pipeline-queue"
queue_name_pipeline = "my-sitespeed-queue"
queue_delay_seconds = 90
queue_max_message_size = 2048
queue_message_retention_seconds = 86400
queue_receive_wait_time_seconds = 10
variable "environment" {}
variable "deployment" {}
variable "service" {}
variable "queue_name_pipeline" {
default = "default-queue"
}
variable "queue_name_sitespeed" {
default = "default-queue"
}
variable "queue_delay_seconds" {}
variable "queue_max_message_size" {}
variable "queue_message_retention_seconds" {}
variable "queue_receive_wait_time_seconds" {}
variable "aws_access_key" {}
variable "aws_secret_key" {}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment