diff --git a/examples/pagerduty-disabled/main.tf b/examples/pagerduty-disabled/main.tf new file mode 100644 index 0000000..954859d --- /dev/null +++ b/examples/pagerduty-disabled/main.tf @@ -0,0 +1,6 @@ +module "service" { + source = "../../modules/pagerduty" + service_key = "" + service_name = "testing_disable_tf" + s3_bucket = "wiser-infra-automation" +} diff --git a/examples/pagerduty-disabled/providers.tf b/examples/pagerduty-disabled/providers.tf new file mode 100644 index 0000000..190223c --- /dev/null +++ b/examples/pagerduty-disabled/providers.tf @@ -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 +} diff --git a/examples/pagerduty-svc2/main.tf b/examples/pagerduty-svc2/main.tf index a1e3aec..136a662 100644 --- a/examples/pagerduty-svc2/main.tf +++ b/examples/pagerduty-svc2/main.tf @@ -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" } diff --git a/examples/slack-ch1/main.tf b/examples/slack-ch1/main.tf index 3e2531f..bdc5af7 100644 --- a/examples/slack-ch1/main.tf +++ b/examples/slack-ch1/main.tf @@ -1,5 +1,5 @@ module "channel" { source = "../../modules/slack" channel_name = "test-srv-1a" - s3_bucket = "wiser-one-ci" + s3_bucket = "wiser-infra-automation" } diff --git a/examples/slack-ch2/main.tf b/examples/slack-ch2/main.tf index 94b8470..23f0a5e 100644 --- a/examples/slack-ch2/main.tf +++ b/examples/slack-ch2/main.tf @@ -1,5 +1,5 @@ module "channel" { source = "../../modules/slack" channel_name = "test-srv-2" - s3_bucket = "wiser-one-ci" + s3_bucket = "wiser-infra-automation" } diff --git a/examples/slack-disabled/main.tf b/examples/slack-disabled/main.tf new file mode 100644 index 0000000..a5335c0 --- /dev/null +++ b/examples/slack-disabled/main.tf @@ -0,0 +1,5 @@ +module "channel" { + source = "../../modules/slack" + channel_name = "" + s3_bucket = "wiser-infra-automation" +} diff --git a/examples/slack-disabled/providers.tf b/examples/slack-disabled/providers.tf new file mode 100644 index 0000000..190223c --- /dev/null +++ b/examples/slack-disabled/providers.tf @@ -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 +} diff --git a/modules/pagerduty/main.tf b/modules/pagerduty/main.tf index 7937359..cf14883 100644 --- a/modules/pagerduty/main.tf +++ b/modules/pagerduty/main.tf @@ -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 { @@ -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" diff --git a/modules/pagerduty/variables.tf b/modules/pagerduty/variables.tf index 816594c..7288252 100644 --- a/modules/pagerduty/variables.tf +++ b/modules/pagerduty/variables.tf @@ -5,6 +5,7 @@ variable "datadog_default" { variable "service_key" { description = "PagerDuty service integration key" + default = "" } variable "service_name" { diff --git a/modules/slack/main.tf b/modules/slack/main.tf index b709a34..010e486 100644 --- a/modules/slack/main.tf +++ b/modules/slack/main.tf @@ -1,4 +1,14 @@ +# Expect Slack channel name to be of format: mon-- +# Auto disable if: +# Channel name is empty +# Channel name has format mon-- 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 { @@ -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" diff --git a/modules/slack/variables.tf b/modules/slack/variables.tf index 68a75ea..6310584 100644 --- a/modules/slack/variables.tf +++ b/modules/slack/variables.tf @@ -1,5 +1,6 @@ variable "channel_name" { description = "Slack channel name" + default = "" } variable "s3_base" {