Skip to content

Commit

Permalink
Feat: create QED isolated AWS deployments using terraform workspaces
Browse files Browse the repository at this point in the history
  • Loading branch information
Jose Luis Lucas committed Apr 2, 2019
1 parent 218289f commit e563f63
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 17 deletions.
4 changes: 2 additions & 2 deletions deploy/aws/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ data "aws_iam_policy_document" "CloudWatchLogsFullAccess-assume-role-policy" {
}

resource "aws_iam_role" "CloudWatchLogsFullAccess" {
name = "CloudWatchLogsFullAccess"
name = "CloudWatchLogsFullAccess-${terraform.workspace}"
assume_role_policy = "${data.aws_iam_policy_document.CloudWatchLogsFullAccess-assume-role-policy.json}"
}

Expand All @@ -34,7 +34,7 @@ resource "aws_iam_role_policy_attachment" "CloudWatchLogsFullAccess-attach" {
}

resource "aws_iam_instance_profile" "qed-profile" {
name = "qed-profile"
name = "qed-profile-${terraform.workspace}"
role = "${aws_iam_role.CloudWatchLogsFullAccess.name}"
}

Expand Down
1 change: 1 addition & 0 deletions deploy/aws/modules/agent/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,6 @@ resource "aws_instance" "qed-agent" {
Name = "${format("${var.name}-%01d", count.index)}"
Role = "${var.role}"
DAM_OnOff = "NO"
Workspace = "${terraform.workspace}"
}
}
1 change: 1 addition & 0 deletions deploy/aws/modules/inmemory_storage/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,6 @@ resource "aws_instance" "inmemory-storage" {
Name = "qed-${var.name}"
Role = "${var.role}"
DAM_OnOff = "NO"
Workspace = "${terraform.workspace}"
}
}
1 change: 1 addition & 0 deletions deploy/aws/modules/prometheus/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,6 @@ resource "aws_instance" "prometheus" {
Name = "qed-prometheus"
Role = "${var.role}"
DAM_OnOff = "NO"
Workspace = "${terraform.workspace}"
}
}
1 change: 1 addition & 0 deletions deploy/aws/modules/qed/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,6 @@ resource "aws_instance" "qed-server" {
Name = "${format("${var.name}-%01d", count.index)}"
Role = "${var.role}"
DAM_OnOff = "NO"
Workspace = "${terraform.workspace}"
}
}
3 changes: 2 additions & 1 deletion deploy/aws/modules/riot/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ resource "aws_instance" "riot" {
tags {
Name = "qed-riot"
Role = "${var.role}"
DAM_OnOff = "NO"
DAM_OnOff = "NO"
Workspace = "${terraform.workspace}"
}
}
22 changes: 11 additions & 11 deletions deploy/aws/network.tf
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ resource "aws_vpc" "qed" {
cidr_block = "${var.vpc_cidr}"

tags = {
Name = "QED"
Name = "QED-${terraform.workspace}"
}
}

Expand All @@ -33,15 +33,15 @@ resource "aws_subnet" "qed" {
map_public_ip_on_launch = true

tags = {
Name = "QED"
Name = "QED-${terraform.workspace}"
}
}

resource "aws_internet_gateway" "qed" {
vpc_id = "${aws_vpc.qed.id}"

tags = {
Name = "QED"
Name = "QED-${terraform.workspace}"
}
}

Expand All @@ -56,7 +56,7 @@ resource "aws_vpc_dhcp_options" "qed" {
domain_name_servers = ["AmazonProvidedDNS"]

tags = {
Name = "QED"
Name = "QED-${terraform.workspace}"
}
}

Expand All @@ -65,12 +65,12 @@ resource "aws_vpc_dhcp_options_association" "qed" {
dhcp_options_id = "${aws_vpc_dhcp_options.qed.id}"
}

data "aws_cloudwatch_log_group" "qed" {
name = "qed"
resource "aws_cloudwatch_log_group" "qed" {
name = "qed-${terraform.workspace}"
}

resource "aws_iam_role" "qed" {
name = "qed"
name = "qed-${terraform.workspace}"

assume_role_policy = <<EOF
{
Expand All @@ -95,22 +95,22 @@ resource "aws_iam_role_policy_attachment" "qed" {
}

resource "aws_flow_log" "qed" {
log_destination = "${data.aws_cloudwatch_log_group.qed.arn}"
log_destination = "${aws_cloudwatch_log_group.qed.arn}"
iam_role_arn = "${aws_iam_role.qed.arn}"
vpc_id = "${aws_vpc.qed.id}"
traffic_type = "ALL"
}

resource "aws_key_pair" "qed" {
key_name = "qed"
key_name = "qed-${terraform.workspace}"
public_key = "${file("${var.keypath}.pub")}"
}

module "security_group" {
source = "terraform-aws-modules/security-group/aws"
version = "2.11.0"

name = "qed"
name = "qed-${terraform.workspace}"
description = "Security group for QED usage"
vpc_id = "${aws_vpc.qed.id}"

Expand Down Expand Up @@ -180,7 +180,7 @@ module "prometheus_security_group" {
source = "terraform-aws-modules/security-group/aws"
version = "2.11.0"

name = "prometheus"
name = "prometheus-${terraform.workspace}"
description = "Security group for Prometheus/Grafana usage"
vpc_id = "${aws_vpc.qed.id}"

Expand Down
16 changes: 15 additions & 1 deletion deploy/aws/pre-build/bucket.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
Copyright 2018-2019 Banco Bilbao Vizcaya Argentaria, S.A.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
terraform {
required_version = ">= 0.11.11"
}
Expand All @@ -15,7 +30,6 @@ resource "aws_kms_key" "bucket-key" {

resource "aws_s3_bucket" "terraform-qed-cluster" {
bucket = "terraform-qed-cluster"

versioning {
enabled = true
}
Expand Down
8 changes: 6 additions & 2 deletions deploy/aws/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@
* Terraform (go get github.com/hashicorp/terraform)

## Init

```
$ export GO111MODULE=on
$ terraform init -backend-config "profile=${your_aws_profile}"
```

## Bandaid
Expand All @@ -20,6 +18,12 @@ If terraform misbehaves, give it a gentle nudge like this:
$ terraform init -backend-config "profile=${your_aws_profile} -reconfigure"
```

## Testing purposes: create an isolated workspace
```
$ terraform workspace new <workspace_name>
$ terraform select <workspace_name>
```

## Deploy
```
$ terraform apply -auto-approve
Expand Down
15 changes: 15 additions & 0 deletions deploy/aws/variables.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
Copyright 2018-2019 Banco Bilbao Vizcaya Argentaria, S.A.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
variable "aws_profile" {
default = "bbva-labs"
}
Expand Down

0 comments on commit e563f63

Please sign in to comment.