Skip to content

Commit

Permalink
Allow S3 object modules to be disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven Nemetz committed Jul 9, 2018
1 parent ea0787e commit d781284
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 3 deletions.
6 changes: 6 additions & 0 deletions examples/pagerduty-disabled/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module "service" {
source = "../../modules/pagerduty"
service_key = ""
service_name = "testing_disable_tf"
s3_bucket = "wiser-infra-automation"
}
10 changes: 10 additions & 0 deletions examples/pagerduty-disabled/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
provider "aws" {
region = "us-west-2"

# Make it faster by skipping something
skip_get_ec2_platforms = true
skip_metadata_api_check = true
skip_region_validation = true
skip_credentials_validation = true
skip_requesting_account_id = true
}
2 changes: 1 addition & 1 deletion examples/pagerduty-svc2/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ module "service" {
source = "../../modules/pagerduty"
service_key = "123456789012"
service_name = "test-srv-2"
s3_bucket = "wiser-one-ci"
s3_bucket = "wiser-infra-automation"
}
2 changes: 1 addition & 1 deletion examples/slack-ch1/main.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module "channel" {
source = "../../modules/slack"
channel_name = "test-srv-1a"
s3_bucket = "wiser-one-ci"
s3_bucket = "wiser-infra-automation"
}
2 changes: 1 addition & 1 deletion examples/slack-ch2/main.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module "channel" {
source = "../../modules/slack"
channel_name = "test-srv-2"
s3_bucket = "wiser-one-ci"
s3_bucket = "wiser-infra-automation"
}
5 changes: 5 additions & 0 deletions examples/slack-disabled/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module "channel" {
source = "../../modules/slack"
channel_name = ""
s3_bucket = "wiser-infra-automation"
}
10 changes: 10 additions & 0 deletions examples/slack-disabled/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
provider "aws" {
region = "us-west-2"

# Make it faster by skipping something
skip_get_ec2_platforms = true
skip_metadata_api_check = true
skip_region_validation = true
skip_credentials_validation = true
skip_requesting_account_id = true
}
6 changes: 6 additions & 0 deletions modules/pagerduty/main.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
locals {
enabled = "${length(var.service_key) > 0 ? 1 : 0}"
}

data "template_file" "pagerduty_service" {
count = "${local.enabled}"
template = "${file("${path.module}/templates/pagerduty.json")}"

vars {
Expand All @@ -9,6 +14,7 @@ data "template_file" "pagerduty_service" {
}

resource "aws_s3_bucket_object" "object" {
count = "${local.enabled}"
bucket = "${var.s3_bucket}"
acl = "bucket-owner-full-control"

Expand Down
1 change: 1 addition & 0 deletions modules/pagerduty/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ variable "datadog_default" {

variable "service_key" {
description = "PagerDuty service integration key"
default = ""
}

variable "service_name" {
Expand Down
11 changes: 11 additions & 0 deletions modules/slack/main.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
# Expect Slack channel name to be of format: mon-<env>-<service short name>
# Auto disable if:
# Channel name is empty
# Channel name has format mon-<env>-<service short name> but nothing after second -

locals {
enabled = "${length(replace(var.channel_name, "/(mon-\\w+-)(.*)$/", "$2")) > 0 ? 1 : 0}"
}

data "template_file" "slack_channel" {
count = "${local.enabled}"
template = "${file("${path.module}/templates/slack.json")}"

vars {
Expand All @@ -7,6 +17,7 @@ data "template_file" "slack_channel" {
}

resource "aws_s3_bucket_object" "object" {
count = "${local.enabled}"
bucket = "${var.s3_bucket}"
acl = "bucket-owner-full-control"

Expand Down
1 change: 1 addition & 0 deletions modules/slack/variables.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
variable "channel_name" {
description = "Slack channel name"
default = ""
}

variable "s3_base" {
Expand Down

0 comments on commit d781284

Please sign in to comment.