-
Notifications
You must be signed in to change notification settings - Fork 9.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conditional processing on resources #12125
Comments
related to #10857 ? |
Hi @cemo! Sorry for the issue here. Would I be correct to assume that this resource is in a child module and the Unfortunately if that's true then there's no good short-term fix for this other than to use the The proper fix for this issue would be something like what I proposed in #4149, which gives Terraform the ability to detect situations where multiple steps are required and essentially do the |
@apparentlymart It helped a lot. Should I leave this ticket open? |
@apparentlymart Is terraform aware that which resources exactly will be created at the beginning of its lifecycle? I mean is it not possible to delegate some decision of some resource creation to runtime? PS: Sorry for asking on a closed issue but I think this is better than opening a new one. |
There are some subtleties to this which are difficult to quickly summarize, but the high-level idea is that Terraform wants to know the full set of resources early on so that the dependency graph can be constructed, but defers the attribute values of the resources until runtime. The key effect of this approach is that Terraform can describe in plan exactly which resources of which types will be created, updated and destroyed, even if it can't yet tell you what some of the attributes of those resources will be. This is considered to be a fundamental goal of Terraform, since it reduces uncertainty about what a given plan could affect, both from the perspective of avoiding unwanted downtime and of avoiding surprising cost. |
I'm not sure I see why that would leave out the possibility of having a While I can see the difficulty in applying this to the exported attributes of resources, it could still see many other use cases being able to act on the attributes of A quick example that I just came across was when I have my "environment" variable set to "prd" instead of a lower environment, I wanted additional routing policies applied to an Application Load Balancer in AWS. I'm sure I could accomplish this with lists, or maps, and some fancy |
# ----------d-------------- >8 ------------------------ # Do not touch the line above. # Everything below will be removed. # Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit. # # On branch development # Your branch is up to date with 'origin/development'. # # Changes to be committed: # # modified: .gitignore # modified: create-infra.tf # modified: modules/terraform-aws-ec2-autoscale-group-master/.gitignore # modified: modules/terraform-aws-ec2-autoscale-group-master/main.tf # new file: modules/terraform-aws-ec2-cloudwatch-sns-alarms-master/.gitignore # new file: modules/terraform-aws-ec2-cloudwatch-sns-alarms-master/.travis.yml # new file: modules/terraform-aws-ec2-cloudwatch-sns-alarms-master/Makefile # new file: modules/terraform-aws-ec2-cloudwatch-sns-alarms-master/README.md # new file: modules/terraform-aws-ec2-cloudwatch-sns-alarms-master/README.yaml # new file: modules/terraform-aws-ec2-cloudwatch-sns-alarms-master/alarms.tf # new file: modules/terraform-aws-ec2-cloudwatch-sns-alarms-master/docs/targets.md # new file: modules/terraform-aws-ec2-cloudwatch-sns-alarms-master/docs/terraform.md # new file: modules/terraform-aws-ec2-cloudwatch-sns-alarms-master/example/README.md # new file: modules/terraform-aws-ec2-cloudwatch-sns-alarms-master/example/main.tf # new file: modules/terraform-aws-ec2-cloudwatch-sns-alarms-master/main.tf # new file: modules/terraform-aws-ec2-cloudwatch-sns-alarms-master/outputs.tf # new file: modules/terraform-aws-ec2-cloudwatch-sns-alarms-master/variables.tf # modified: modules/terraform-aws-key-pair-master/.gitignore # modified: modules/terraform-aws-key-pair-master/main.tf # new file: modules/terraform-aws-multi-az-subnets-master/multi-az-subnets.tfvars # modified: modules/terraform-aws-multi-az-subnets-master/private.tf # modified: modules/terraform-aws-multi-az-subnets-master/public.tf # new file: modules/terraform-aws-notify-slack-master/.editorconfig # new file: modules/terraform-aws-notify-slack-master/.gitignore # new file: modules/terraform-aws-notify-slack-master/.pre-commit-config.yaml # new file: modules/terraform-aws-notify-slack-master/LICENSE # new file: modules/terraform-aws-notify-slack-master/README.md # new file: modules/terraform-aws-notify-slack-master/examples/cloudwatch-alerts-to-slack/README.md # new file: modules/terraform-aws-notify-slack-master/examples/cloudwatch-alerts-to-slack/main.tf # new file: modules/terraform-aws-notify-slack-master/examples/cloudwatch-alerts-to-slack/outputs.tf # new file: modules/terraform-aws-notify-slack-master/examples/notify-slack-kms/README.md # new file: modules/terraform-aws-notify-slack-master/examples/notify-slack-kms/main.tf # new file: modules/terraform-aws-notify-slack-master/examples/notify-slack-kms/outputs.tf # new file: modules/terraform-aws-notify-slack-master/examples/notify-slack-simple/README.md # new file: modules/terraform-aws-notify-slack-master/examples/notify-slack-simple/main.tf # new file: modules/terraform-aws-notify-slack-master/examples/notify-slack-simple/outputs.tf # new file: modules/terraform-aws-notify-slack-master/functions/notify_slack.py # new file: modules/terraform-aws-notify-slack-master/iam.tf # new file: modules/terraform-aws-notify-slack-master/main.tf # new file: modules/terraform-aws-notify-slack-master/outputs.tf # new file: modules/terraform-aws-notify-slack-master/variables.tf # new file: modules/terraform-aws-security-group-master/.editorconfig # new file: modules/terraform-aws-security-group-master/.gitignore # new file: modules/terraform-aws-security-group-master/.pre-commit-config.yaml # new file: modules/terraform-aws-security-group-master/LICENSE # new file: modules/terraform-aws-security-group-master/README.md # new file: modules/terraform-aws-security-group-master/examples/complete/README.md # new file: modules/terraform-aws-security-group-master/examples/complete/main.tf # new file: modules/terraform-aws-security-group-master/examples/complete/outputs.tf # new file: modules/terraform-aws-security-group-master/examples/computed/README.md # new file: modules/terraform-aws-security-group-master/examples/computed/main.tf # new file: modules/terraform-aws-security-group-master/examples/computed/outputs.tf # new file: modules/terraform-aws-security-group-master/examples/disabled/README.md # new file: modules/terraform-aws-security-group-master/examples/disabled/main.tf # new file: modules/terraform-aws-security-group-master/examples/disabled/outputs.tf # new file: modules/terraform-aws-security-group-master/examples/dynamic/README.md # new file: modules/terraform-aws-security-group-master/examples/dynamic/main.tf # new file: modules/terraform-aws-security-group-master/examples/dynamic/outputs.tf # new file: modules/terraform-aws-security-group-master/examples/http/README.md # new file: modules/terraform-aws-security-group-master/examples/http/main.tf # new file: modules/terraform-aws-security-group-master/examples/http/outputs.tf # new file: modules/terraform-aws-security-group-master/main.tf # new file: modules/terraform-aws-security-group-master/modules/README.md # new file: modules/terraform-aws-security-group-master/modules/_templates/main.tf # new file: modules/terraform-aws-security-group-master/modules/_templates/outputs.tf # new file: modules/terraform-aws-security-group-master/modules/_templates/variables.tf # new file: modules/terraform-aws-security-group-master/modules/carbon-relay-ng/README.md # new file: modules/terraform-aws-security-group-master/modules/carbon-relay-ng/auto_values.tf # new file: modules/terraform-aws-security-group-master/modules/carbon-relay-ng/main.tf # new file: modules/terraform-aws-security-group-master/modules/carbon-relay-ng/outputs.tf # new file: modules/terraform-aws-security-group-master/modules/carbon-relay-ng/variables.tf # new file: modules/terraform-aws-security-group-master/modules/cassandra/README.md # new file: modules/terraform-aws-security-group-master/modules/cassandra/auto_values.tf # new file: modules/terraform-aws-security-group-master/modules/cassandra/main.tf # new file: modules/terraform-aws-security-group-master/modules/cassandra/outputs.tf # new file: modules/terraform-aws-security-group-master/modules/cassandra/variables.tf # new file: modules/terraform-aws-security-group-master/modules/consul/README.md # new file: modules/terraform-aws-security-group-master/modules/consul/auto_values.tf # new file: modules/terraform-aws-security-group-master/modules/consul/main.tf # new file: modules/terraform-aws-security-group-master/modules/consul/outputs.tf # new file: modules/terraform-aws-security-group-master/modules/consul/variables.tf # new file: modules/terraform-aws-security-group-master/modules/docker-swarm/README.md # new file: modules/terraform-aws-security-group-master/modules/docker-swarm/auto_values.tf # new file: modules/terraform-aws-security-group-master/modules/docker-swarm/main.tf # new file: modules/terraform-aws-security-group-master/modules/docker-swarm/outputs.tf # new file: modules/terraform-aws-security-group-master/modules/docker-swarm/variables.tf # new file: modules/terraform-aws-security-group-master/modules/elasticsearch/README.md # new file: modules/terraform-aws-security-group-master/modules/elasticsearch/auto_values.tf # new file: modules/terraform-aws-security-group-master/modules/elasticsearch/main.tf # new file: modules/terraform-aws-security-group-master/modules/elasticsearch/outputs.tf # new file: modules/terraform-aws-security-group-master/modules/elasticsearch/variables.tf # new file: modules/terraform-aws-security-group-master/modules/http-80/README.md # new file: modules/terraform-aws-security-group-master/modules/http-80/auto_values.tf # new file: modules/terraform-aws-security-group-master/modules/http-80/main.tf # new file: modules/terraform-aws-security-group-master/modules/http-80/outputs.tf # new file: modules/terraform-aws-security-group-master/modules/http-80/variables.tf # new file: modules/terraform-aws-security-group-master/modules/http-8080/README.md # new file: modules/terraform-aws-security-group-master/modules/http-8080/auto_values.tf # new file: modules/terraform-aws-security-group-master/modules/http-8080/main.tf # new file: modules/terraform-aws-security-group-master/modules/http-8080/outputs.tf # new file: modules/terraform-aws-security-group-master/modules/http-8080/variables.tf # new file: modules/terraform-aws-security-group-master/modules/https-443/README.md # new file: modules/terraform-aws-security-group-master/modules/https-443/auto_values.tf # new file: modules/terraform-aws-security-group-master/modules/https-443/main.tf # new file: modules/terraform-aws-security-group-master/modules/https-443/outputs.tf # new file: modules/terraform-aws-security-group-master/modules/https-443/variables.tf # new file: modules/terraform-aws-security-group-master/modules/https-8443/README.md # new file: modules/terraform-aws-security-group-master/modules/https-8443/auto_values.tf # new file: modules/terraform-aws-security-group-master/modules/https-8443/main.tf # new file: modules/terraform-aws-security-group-master/modules/https-8443/outputs.tf # new file: modules/terraform-aws-security-group-master/modules/https-8443/variables.tf # new file: modules/terraform-aws-security-group-master/modules/ipsec-4500/README.md # new file: modules/terraform-aws-security-group-master/modules/ipsec-4500/auto_values.tf # new file: modules/terraform-aws-security-group-master/modules/ipsec-4500/main.tf # new file: modules/terraform-aws-security-group-master/modules/ipsec-4500/outputs.tf # new file: modules/terraform-aws-security-group-master/modules/ipsec-4500/variables.tf # new file: modules/terraform-aws-security-group-master/modules/ipsec-500/README.md # new file: modules/terraform-aws-security-group-master/modules/ipsec-500/auto_values.tf # new file: modules/terraform-aws-security-group-master/modules/ipsec-500/main.tf # new file: modules/terraform-aws-security-group-master/modules/ipsec-500/outputs.tf # new file: modules/terraform-aws-security-group-master/modules/ipsec-500/variables.tf # new file: modules/terraform-aws-security-group-master/modules/kafka/README.md # new file: modules/terraform-aws-security-group-master/modules/kafka/auto_values.tf # new file: modules/terraform-aws-security-group-master/modules/kafka/main.tf # new file: modules/terraform-aws-security-group-master/modules/kafka/outputs.tf # new file: modules/terraform-aws-security-group-master/modules/kafka/variables.tf # new file: modules/terraform-aws-security-group-master/modules/ldaps/README.md # new file: modules/terraform-aws-security-group-master/modules/ldaps/auto_values.tf # new file: modules/terraform-aws-security-group-master/modules/ldaps/main.tf # new file: modules/terraform-aws-security-group-master/modules/ldaps/outputs.tf # new file: modules/terraform-aws-security-group-master/modules/ldaps/variables.tf # new file: modules/terraform-aws-security-group-master/modules/memcached/README.md # new file: modules/terraform-aws-security-group-master/modules/memcached/auto_values.tf # new file: modules/terraform-aws-security-group-master/modules/memcached/main.tf # new file: modules/terraform-aws-security-group-master/modules/memcached/outputs.tf # new file: modules/terraform-aws-security-group-master/modules/memcached/variables.tf # new file: modules/terraform-aws-security-group-master/modules/mongodb/README.md # new file: modules/terraform-aws-security-group-master/modules/mongodb/auto_values.tf # new file: modules/terraform-aws-security-group-master/modules/mongodb/main.tf # new file: modules/terraform-aws-security-group-master/modules/mongodb/outputs.tf # new file: modules/terraform-aws-security-group-master/modules/mongodb/variables.tf # new file: modules/terraform-aws-security-group-master/modules/mssql/README.md # new file: modules/terraform-aws-security-group-master/modules/mssql/auto_values.tf # new file: modules/terraform-aws-security-group-master/modules/mssql/main.tf # new file: modules/terraform-aws-security-group-master/modules/mssql/outputs.tf # new file: modules/terraform-aws-security-group-master/modules/mssql/variables.tf # new file: modules/terraform-aws-security-group-master/modules/mysql/README.md # new file: modules/terraform-aws-security-group-master/modules/mysql/auto_values.tf # new file: modules/terraform-aws-security-group-master/modules/mysql/main.tf # new file: modules/terraform-aws-security-group-master/modules/mysql/outputs.tf # new file: modules/terraform-aws-security-group-master/modules/mysql/variables.tf # new file: modules/terraform-aws-security-group-master/modules/nfs/README.md # new file: modules/terraform-aws-security-group-master/modules/nfs/auto_values.tf # new file: modules/terraform-aws-security-group-master/modules/nfs/main.tf # new file: modules/terraform-aws-security-group-master/modules/nfs/outputs.tf # new file: modules/terraform-aws-security-group-master/modules/nfs/variables.tf # new file: modules/terraform-aws-security-group-master/modules/nomad/README.md # new file: modules/terraform-aws-security-group-master/modules/nomad/auto_values.tf # new file: modules/terraform-aws-security-group-master/modules/nomad/main.tf # new file: modules/terraform-aws-security-group-master/modules/nomad/outputs.tf # new file: modules/terraform-aws-security-group-master/modules/nomad/variables.tf # new file: modules/terraform-aws-security-group-master/modules/ntp/README.md # new file: modules/terraform-aws-security-group-master/modules/ntp/auto_values.tf # new file: modules/terraform-aws-security-group-master/modules/ntp/main.tf # new file: modules/terraform-aws-security-group-master/modules/ntp/outputs.tf # new file: modules/terraform-aws-security-group-master/modules/ntp/variables.tf # new file: modules/terraform-aws-security-group-master/modules/openvpn/README.md # new file: modules/terraform-aws-security-group-master/modules/openvpn/auto_values.tf # new file: modules/terraform-aws-security-group-master/modules/openvpn/main.tf # new file: modules/terraform-aws-security-group-master/modules/openvpn/outputs.tf # new file: modules/terraform-aws-security-group-master/modules/openvpn/variables.tf # new file: modules/terraform-aws-security-group-master/modules/oracle-db/README.md # new file: modules/terraform-aws-security-group-master/modules/oracle-db/auto_values.tf # new file: modules/terraform-aws-security-group-master/modules/oracle-db/main.tf # new file: modules/terraform-aws-security-group-master/modules/oracle-db/outputs.tf # new file: modules/terraform-aws-security-group-master/modules/oracle-db/variables.tf # new file: modules/terraform-aws-security-group-master/modules/postgresql/README.md # new file: modules/terraform-aws-security-group-master/modules/postgresql/auto_values.tf # new file: modules/terraform-aws-security-group-master/modules/postgresql/main.tf # new file: modules/terraform-aws-security-group-master/modules/postgresql/outputs.tf # new file: modules/terraform-aws-security-group-master/modules/postgresql/variables.tf # new file: modules/terraform-aws-security-group-master/modules/rabbitmq/README.md # new file: modules/terraform-aws-security-group-master/modules/rabbitmq/auto_values.tf # new file: modules/terraform-aws-security-group-master/modules/rabbitmq/main.tf # new file: modules/terraform-aws-security-group-master/modules/rabbitmq/outputs.tf # new file: modules/terraform-aws-security-group-master/modules/rabbitmq/variables.tf # new file: modules/terraform-aws-security-group-master/modules/rdp/README.md # new file: modules/terraform-aws-security-group-master/modules/rdp/auto_values.tf # new file: modules/terraform-aws-security-group-master/modules/rdp/main.tf # new file: modules/terraform-aws-security-group-master/modules/rdp/outputs.tf # new file: modules/terraform-aws-security-group-master/modules/rdp/variables.tf # new file: modules/terraform-aws-security-group-master/modules/redis/README.md # new file: modules/terraform-aws-security-group-master/modules/redis/auto_values.tf # new file: modules/terraform-aws-security-group-master/modules/redis/main.tf # new file: modules/terraform-aws-security-group-master/modules/redis/outputs.tf # new file: modules/terraform-aws-security-group-master/modules/redis/variables.tf # new file: modules/terraform-aws-security-group-master/modules/redshift/README.md # new file: modules/terraform-aws-security-group-master/modules/redshift/auto_values.tf # new file: modules/terraform-aws-security-group-master/modules/redshift/main.tf # new file: modules/terraform-aws-security-group-master/modules/redshift/outputs.tf # new file: modules/terraform-aws-security-group-master/modules/redshift/variables.tf # new file: modules/terraform-aws-security-group-master/modules/splunk/README.md # new file: modules/terraform-aws-security-group-master/modules/splunk/auto_values.tf # new file: modules/terraform-aws-security-group-master/modules/splunk/main.tf # new file: modules/terraform-aws-security-group-master/modules/splunk/outputs.tf # new file: modules/terraform-aws-security-group-master/modules/splunk/variables.tf # new file: modules/terraform-aws-security-group-master/modules/squid/README.md # new file: modules/terraform-aws-security-group-master/modules/squid/auto_values.tf # new file: modules/terraform-aws-security-group-master/modules/squid/main.tf # new file: modules/terraform-aws-security-group-master/modules/squid/outputs.tf # new file: modules/terraform-aws-security-group-master/modules/squid/variables.tf # new file: modules/terraform-aws-security-group-master/modules/ssh/README.md # new file: modules/terraform-aws-security-group-master/modules/ssh/auto_values.tf # new file: modules/terraform-aws-security-group-master/modules/ssh/main.tf # new file: modules/terraform-aws-security-group-master/modules/ssh/outputs.tf # new file: modules/terraform-aws-security-group-master/modules/ssh/variables.tf # new file: modules/terraform-aws-security-group-master/modules/storm/README.md # new file: modules/terraform-aws-security-group-master/modules/storm/auto_values.tf # new file: modules/terraform-aws-security-group-master/modules/storm/main.tf # new file: modules/terraform-aws-security-group-master/modules/storm/outputs.tf # new file: modules/terraform-aws-security-group-master/modules/storm/variables.tf # new file: modules/terraform-aws-security-group-master/modules/web/README.md # new file: modules/terraform-aws-security-group-master/modules/web/auto_values.tf # new file: modules/terraform-aws-security-group-master/modules/web/main.tf # new file: modules/terraform-aws-security-group-master/modules/web/outputs.tf # new file: modules/terraform-aws-security-group-master/modules/web/variables.tf # new file: modules/terraform-aws-security-group-master/modules/winrm/README.md # new file: modules/terraform-aws-security-group-master/modules/winrm/auto_values.tf # new file: modules/terraform-aws-security-group-master/modules/winrm/main.tf # new file: modules/terraform-aws-security-group-master/modules/winrm/outputs.tf # new file: modules/terraform-aws-security-group-master/modules/winrm/variables.tf # new file: modules/terraform-aws-security-group-master/modules/zipkin/README.md # new file: modules/terraform-aws-security-group-master/modules/zipkin/auto_values.tf # new file: modules/terraform-aws-security-group-master/modules/zipkin/main.tf # new file: modules/terraform-aws-security-group-master/modules/zipkin/outputs.tf # new file: modules/terraform-aws-security-group-master/modules/zipkin/variables.tf # new file: modules/terraform-aws-security-group-master/modules/zookeeper/README.md # new file: modules/terraform-aws-security-group-master/modules/zookeeper/auto_values.tf # new file: modules/terraform-aws-security-group-master/modules/zookeeper/main.tf # new file: modules/terraform-aws-security-group-master/modules/zookeeper/outputs.tf # new file: modules/terraform-aws-security-group-master/modules/zookeeper/variables.tf # new file: modules/terraform-aws-security-group-master/outputs.tf # new file: modules/terraform-aws-security-group-master/rules.tf # new file: modules/terraform-aws-security-group-master/update_groups.sh # new file: modules/terraform-aws-security-group-master/variables.tf # new file: modules/terraform-aws-sns-master/.editorconfig # new file: modules/terraform-aws-sns-master/.gitignore # new file: modules/terraform-aws-sns-master/.pre-commit-config.yaml # new file: modules/terraform-aws-sns-master/LICENSE # new file: modules/terraform-aws-sns-master/README.md # new file: modules/terraform-aws-sns-master/main.tf # new file: modules/terraform-aws-sns-master/output.tf # new file: modules/terraform-aws-sns-master/variables.tf # modified: modules/terraform-aws-vpc-master/main.tf # deleted: modules/vpc/main.tf # deleted: modules/vpc/outputs.tf # deleted: modules/vpc/variables.tf # modified: terraform.tfvars # modified: variables.tf # diff --git a/.gitignore b/.gitignore index e4fd2d2..ed1d3a9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *.tfstate* .terraform *tfplan* +*secrets* diff --git a/create-infra.tf b/create-infra.tf index aaa7f73..86e4e32 100644 --- a/create-infra.tf +++ b/create-infra.tf @@ -27,6 +27,31 @@ module "vpc" { cidr_block = "${var.cidr_block}" } +module "web_server_sg" { + source = "modules/terraform-aws-security-group-master/modules/http-80" + + name = "web-server" + description = "Security group for web-server with HTTP ports open within VPC" + vpc_id = "${module.vpc.vpc_id}" + # namespace = "${var.namespace}" + # stage = "${var.stage}" + # name = "${var.name}" + ingress_cidr_blocks = ["${module.vpc.vpc_cidr_block}"] +} + +module "ssh_sg" { + source = "modules/terraform-aws-security-group-master/modules/ssh" + + name = "ssh" + description = "Security group for SSH ports open within VPC" + vpc_id = "${module.vpc.vpc_id}" + # namespace = "${var.namespace}" + # stage = "${var.stage}" + # name = "${var.name}" + ingress_cidr_blocks = ["${module.vpc.vpc_cidr_block}"] +} + + locals { public_cidr_block = "${cidrsubnet(module.vpc.vpc_cidr_block, 1, 0)}" private_cidr_block = "${cidrsubnet(module.vpc.vpc_cidr_block, 1, 1)}" @@ -64,7 +89,29 @@ module "private_subnets" { # https://github.com/hashicorp/terraform/issues/12125 # https://github.com/hashicorp/terraform/issues/4149 # az_ngw_count = "${length(var.pri_az)}" - az_ngw_count = 2 + az_ngw_count = 1 +} + + + +# +# module "sns_topic" { +# source = "modules/terraform-aws-sns-master" +# name = "${var.name}" +# namespace = "${var.namespace}" +# stage = "${var.stage}" +# +# } + +module "notify_slack" { + source = "modules/terraform-aws-notify-slack-master" + slack_webhook_url = "https://hooks.slack.com/services/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" + slack_channel = "michael-tests" + slack_username = "reporter" + sns_topic_name = "${var.name}" + namespace = "${var.namespace}" + stage = "${var.stage}" + name = "${var.name}" } @@ -73,7 +120,7 @@ module "ssh_key_pair" { namespace = "${var.namespace}" stage = "${var.stage}" name = "${var.name}" - ssh_public_key_path = "/secrets" + ssh_public_key_path = "./secrets" generate_ssh_key = "true" private_key_extension = ".pem" public_key_extension = ".pub" @@ -96,20 +143,23 @@ USERDATA -data "aws_ami" "amazon_linux" { - most_recent = true +data "aws_ami" "centos" { +owners = ["679593333241"] +most_recent = true + + filter { + name = "name" + values = ["CentOS Linux 7 x86_64 HVM EBS *"] + } + filter { - name = "name" - values = [ - "amzn-ami-hvm-*-x86_64-gp2", - ] + name = "architecture" + values = ["x86_64"] } filter { - name = "owner-alias" - values = [ - "amazon", - ] + name = "root-device-type" + values = ["ebs"] } } @@ -119,9 +169,9 @@ module "autoscale_group" { stage = "${var.stage}" name = "${var.name}" - image_id = "${data.aws_ami.amazon_linux.id}" + image_id = "${data.aws_ami.centos.id}" instance_type = "${var.amazon_linux_instance_type}" - security_group_ids = ["sg-xxxxxxxx"] + security_group_ids = ["${module.vpc.vpc_default_security_group_id}"] subnet_ids = [] health_check_type = "${var.health_check_type}" min_size = "${var.min_size}" @@ -129,6 +179,7 @@ module "autoscale_group" { wait_for_capacity_timeout = "${var.wait_for_capacity_timeout}" associate_public_ip_address = true user_data_base64 = "${base64encode(local.userdata)}" + key_name = "${module.ssh_key_pair.key_name}" # Auto-scaling policies and CloudWatch metric alarms @@ -137,3 +188,24 @@ module "autoscale_group" { cpu_utilization_low_threshold_percent = "${var.cpu_utilization_high_threshold_percent}" } + + +module "ec2_service_alarms" { + source = "modules/terraform-aws-ec2-cloudwatch-sns-alarms-master" + namespace = "${var.namespace}" + stage = "${var.stage}" + name = "${var.name}" + + cpu_utilization_high_threshold = "${var.cpu_utilization_high_threshold_percent}" + cpu_utilization_high_ok_actions = "${module.notify_slack.this_slack_topic_arn}" + + cpu_utilization_low_threshold = "${var.cpu_utilization_high_threshold_percent}" + cpu_utilization_low_alarm_actions = "${module.notify_slack.this_slack_topic_arn}" + + # cpu_utilization_high_alarm_actions = "${module.notify_slack.this_slack_topic_arn}" + + memory_utilization_high_threshold = "${var.memory_utilization_high_threshold}" + memory_utilization_low_threshold = "${var.memory_utilization_low_threshold}" + + +} diff --git a/modules/terraform-aws-ec2-autoscale-group-master/.gitignore b/modules/terraform-aws-ec2-autoscale-group-master/.gitignore index 10db001..40b0feb 100755 --- a/modules/terraform-aws-ec2-autoscale-group-master/.gitignore +++ b/modules/terraform-aws-ec2-autoscale-group-master/.gitignore @@ -4,10 +4,10 @@ # .tfstate files *.tfstate *.tfstate.* - # .tfvars files *.tfvars + **/.idea **/*.iml diff --git a/modules/terraform-aws-ec2-autoscale-group-master/main.tf b/modules/terraform-aws-ec2-autoscale-group-master/main.tf index c5773ab..1b86186 100755 --- a/modules/terraform-aws-ec2-autoscale-group-master/main.tf +++ b/modules/terraform-aws-ec2-autoscale-group-master/main.tf @@ -1,7 +1,7 @@ module "label" { source = "../../modules/terraform-null-label-master" namespace = "${var.namespace}" - name = "${var.name}" + name = "asg" stage = "${var.stage}" delimiter = "${var.delimiter}" attributes = "${var.attributes}" @@ -13,6 +13,7 @@ resource "aws_launch_template" "default" { count = "${var.enabled == "true" ? 1 : 0}" name_prefix = "${format("%s%s", module.label.id, var.delimiter)}" + # name = "${module.label.id}" block_device_mappings = ["${var.block_device_mappings}"] credit_specification = ["${var.credit_specification}"] disable_api_termination = "${var.disable_api_termination}" diff --git a/modules/terraform-aws-ec2-cloudwatch-sns-alarms-master/.gitignore b/modules/terraform-aws-ec2-cloudwatch-sns-alarms-master/.gitignore new file mode 100755 index 0000000..10db001 --- /dev/null +++ b/modules/terraform-aws-ec2-cloudwatch-sns-alarms-master/.gitignore @@ -0,0 +1,15 @@ +# Local .terraform directories +**/.terraform/* + +# .tfstate files +*.tfstate +*.tfstate.* + +# .tfvars files +*.tfvars + +**/.idea +**/*.iml + +**/.build-harness +**/build-harness diff --git a/modules/terraform-aws-ec2-cloudwatch-sns-alarms-master/.travis.yml b/modules/terraform-aws-ec2-cloudwatch-sns-alarms-master/.travis.yml new file mode 100755 index 0000000..241026e --- /dev/null +++ b/modules/terraform-aws-ec2-cloudwatch-sns-alarms-master/.travis.yml @@ -0,0 +1,16 @@ +addons: + apt: + packages: + - git + - make + - curl + +install: + - make init + +script: + - make terraform/install + - make terraform/get-plugins + - make terraform/get-modules + - make terraform/lint + - make terraform/validate diff --git a/modules/terraform-aws-ec2-cloudwatch-sns-alarms-master/Makefile b/modules/terraform-aws-ec2-cloudwatch-sns-alarms-master/Makefile new file mode 100755 index 0000000..655f630 --- /dev/null +++ b/modules/terraform-aws-ec2-cloudwatch-sns-alarms-master/Makefile @@ -0,0 +1,10 @@ +SHELL := /bin/bash + +# List of targets the `readme` target should call before generating the readme +export README_DEPS ?= docs/targets.md docs/terraform.md + +-include $(shell curl -sSL -o .build-harness "https://git.io/build-harness"; echo .build-harness) + +## Lint terraform code +lint: + $(SELF) terraform/install terraform/get-modules terraform/get-plugins terraform/lint terraform/validate \ No newline at end of file diff --git a/modules/terraform-aws-ec2-cloudwatch-sns-alarms-master/README.md b/modules/terraform-aws-ec2-cloudwatch-sns-alarms-master/README.md new file mode 100755 index 0000000..51fc764 --- /dev/null +++ b/modules/terraform-aws-ec2-cloudwatch-sns-alarms-master/README.md @@ -0,0 +1,225 @@ +<!-- This file was automatically generated by the `build-harness`. Make all changes to `README.yaml` and run `make readme` to rebuild this file. --> + +[![Cloud Posse](https://cloudposse.com/logo-300x69.svg)](https://cloudposse.com) + +# terraform-aws-ecs-cloudwatch-sns-alarms + + [![Build Status](https://travis-ci.org/cloudposse/terraform-aws-ecs-cloudwatch-sns-alarms.svg?branch=master)](https://travis-ci.org/cloudposse/terraform-aws-ecs-cloudwatch-sns-alarms) [![Latest Release](https://img.shields.io/github/release/cloudposse/terraform-aws-ecs-cloudwatch-sns-alarms.svg)](https://github.com/cloudposse/terraform-aws-ecs-cloudwatch-sns-alarms/releases/latest) [![Slack Community](https://slack.cloudposse.com/badge.svg)](https://slack.cloudposse.com) + + +Terraform module for creating alarms for tracking important changes and occurrences from ECS Services. + + +--- + +This project is part of our comprehensive ["SweetOps"](https://docs.cloudposse.com) approach towards DevOps. + + +It's 100% Open Source and licensed under the [APACHE2](LICENSE). + + + + + + + + + + +## Usage + +```hcl +module "ecs_service_alarms" { + source = "git::https://github.com/cloudposse/terraform-aws-ecs-cloudwatch-sns-alarms.git?ref=tags/0.1.0" + namespace = "cp" + stage = "prod" + name = "app" + cluster_name = "example" + service_name = "app" +} +``` + + + + + + + +## Inputs + +| Name | Description | Type | Default | Required | +|------|-------------|:----:|:-----:|:-----:| +| alarm_description | The string to format and use as the alarm description. | string | `Average service %v utilization %v last %d minute(s) over %v period(s)` | no | +| attributes | List of attributes to add to label. | list | `<list>` | no | +| cluster_name | The name of the ECS cluster to monitor. | string | - | yes | +| cpu_utilization_high_alarm_actions | A list of ARNs (i.e. SNS Topic ARN) to notify on CPU Utilization High Alarm action. | list | `<list>` | no | +| cpu_utilization_high_evaluation_periods | Number of periods to evaluate for the alarm. | string | `1` | no | +| cpu_utilization_high_ok_actions | A list of ARNs (i.e. SNS Topic ARN) to notify on CPU Utilization High OK action. | list | `<list>` | no | +| cpu_utilization_high_period | Duration in seconds to evaluate for the alarm. | string | `300` | no | +| cpu_utilization_high_threshold | The maximum percentage of CPU utilization average. | string | `80` | no | +| cpu_utilization_low_alarm_actions | A list of ARNs (i.e. SNS Topic ARN) to notify on CPU Utilization Low Alarm action. | list | `<list>` | no | +| cpu_utilization_low_evaluation_periods | Number of periods to evaluate for the alarm. | string | `1` | no | +| cpu_utilization_low_ok_actions | A list of ARNs (i.e. SNS Topic ARN) to notify on CPU Utilization Low OK action. | list | `<list>` | no | +| cpu_utilization_low_period | Duration in seconds to evaluate for the alarm. | string | `300` | no | +| cpu_utilization_low_threshold | The minimum percentage of CPU utilization average. | string | `20` | no | +| delimiter | The delimiter to be used in labels. | string | `-` | no | +| enabled | Whether to create all resources | string | `true` | no | +| memory_utilization_high_alarm_actions | A list of ARNs (i.e. SNS Topic ARN) to notify on Memory Utilization High Alarm action. | list | `<list>` | no | +| memory_utilization_high_evaluation_periods | Number of periods to evaluate for the alarm. | string | `1` | no | +| memory_utilization_high_ok_actions | A list of ARNs (i.e. SNS Topic ARN) to notify on Memory Utilization High OK action. | list | `<list>` | no | +| memory_utilization_high_period | Duration in seconds to evaluate for the alarm. | string | `300` | no | +| memory_utilization_high_threshold | The maximum percentage of Memory utilization average. | string | `80` | no | +| memory_utilization_low_alarm_actions | A list of ARNs (i.e. SNS Topic ARN) to notify on Memory Utilization Low Alarm action. | list | `<list>` | no | +| memory_utilization_low_evaluation_periods | Number of periods to evaluate for the alarm. | string | `1` | no | +| memory_utilization_low_ok_actions | A list of ARNs (i.e. SNS Topic ARN) to notify on Memory Utilization Low OK action. | list | `<list>` | no | +| memory_utilization_low_period | Duration in seconds to evaluate for the alarm. | string | `300` | no | +| memory_utilization_low_threshold | The minimum percentage of Memory utilization average. | string | `20` | no | +| name | Name (unique identifier for app or service) | string | - | yes | +| namespace | Namespace (e.g. `cp` or `cloudposse`) | string | - | yes | +| service_name | The name of the ECS Service in the ECS cluster to monitor. | string | `` | no | +| stage | Stage (e.g. `prod`, `dev`, `staging`) | string | - | yes | +| tags | Map of key-value pairs to use for tags. | map | `<map>` | no | + + + + +## Related Projects + +Check out these related projects. + +- [terraform-aws-cloudwatch-logs](https://github.com/cloudposse/terraform-aws-cloudwatch-logs) - Terraform Module to Provide a CloudWatch Logs Endpoint +- [terraform-aws-cloudwatch-flow-logs](https://github.com/cloudposse/terraform-aws-cloudwatch-flow-logs) - Terraform module for enabling flow logs for vpc and subnets. +- [terraform-aws-efs-cloudwatch-sns-alarms](https://github.com/cloudposse/terraform-aws-efs-cloudwatch-sns-alarms) - Terraform module that configures CloudWatch SNS alerts for EFS +- [terrform-aws-elasticache-cloudwatch-sns-alarms](https://github.com/cloudposse/terraform-aws-elasticache-cloudwatch-sns-alarms) - Terraform module that configures CloudWatch SNS alerts for ElastiCache +- [terraform-aws-lambda-cloudwatch-sns-alarms](https://github.com/cloudposse/terraform-aws-lambda-cloudwatch-sns-alarms) - Terraform module for creating a set of Lambda alarms and outputting to an endpoint +- [terraform-aws-rds-cloudwatch-sns-alarms](https://github.com/cloudposse/terraform-aws-rds-cloudwatch-sns-alarms) - Terraform module that configures important RDS alerts using CloudWatch and sends them to an SNS topic +- [terraform-aws-sqs-cloudwatch-sns-alarms](https://github.com/cloudposse/terraform-aws-sqs-cloudwatch-sns-alarms) - Terraform module for creating alarms for SQS and notifying endpoints + + + +## Help + +**Got a question?** + +File a GitHub [issue](https://github.com/cloudposse/terraform-aws-ecs-cloudwatch-sns-alarms/issues), send us an [email][email] or join our [Slack Community][slack]. + +## Commercial Support + +Work directly with our team of DevOps experts via email, slack, and video conferencing. + +We provide [*commercial support*][commercial_support] for all of our [Open Source][github] projects. As a *Dedicated Support* customer, you have access to our team of subject matter experts at a fraction of the cost of a full-time engineer. + +[![E-Mail](https://img.shields.io/badge/[email protected])](mailto:[email protected]) + +- **Questions.** We'll use a Shared Slack channel between your team and ours. +- **Troubleshooting.** We'll help you triage why things aren't working. +- **Code Reviews.** We'll review your Pull Requests and provide constructive feedback. +- **Bug Fixes.** We'll rapidly work to fix any bugs in our projects. +- **Build New Terraform Modules.** We'll develop original modules to provision infrastructure. +- **Cloud Architecture.** We'll assist with your cloud strategy and design. +- **Implementation.** We'll provide hands-on support to implement our reference architectures. + + +## Community Forum + +Get access to our [Open Source Community Forum][slack] on Slack. It's **FREE** to join for everyone! Our "SweetOps" community is where you get to talk with others who share a similar vision for how to rollout and manage infrastructure. This is the best place to talk shop, ask questions, solicit feedback, and work together as a community to build *sweet* infrastructure. + +## Contributing + +### Bug Reports & Feature Requests + +Please use the [issue tracker](https://github.com/cloudposse/terraform-aws-ecs-cloudwatch-sns-alarms/issues) to report any bugs or file feature requests. + +### Developing + +If you are interested in being a contributor and want to get involved in developing this project or [help out](https://github.com/orgs/cloudposse/projects/3) with our other projects, we would love to hear from you! Shoot us an [email](mailto:[email protected]). + +In general, PRs are welcome. We follow the typical "fork-and-pull" Git workflow. + + 1. **Fork** the repo on GitHub + 2. **Clone** the project to your own machine + 3. **Commit** changes to your own branch + 4. **Push** your work back up to your fork + 5. Submit a **Pull Request** so that we can review your changes + +**NOTE:** Be sure to merge the latest changes from "upstream" before making a pull request! + + +## Copyright + +Copyright � 2017-2018 [Cloud Posse, LLC](https://cloudposse.com) + + + +## License + +[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) + +See [LICENSE](LICENSE) for full details. + + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you 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 + + https://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. + + + + + + + + + +## Trademarks + +All other trademarks referenced herein are the property of their respective owners. + +## About + +This project is maintained and funded by [Cloud Posse, LLC][website]. Like it? Please let us know at <[email protected]> + +[![Cloud Posse](https://cloudposse.com/logo-300x69.svg)](https://cloudposse.com) + +We're a [DevOps Professional Services][hire] company based in Los Angeles, CA. We love [Open Source Software](https://github.com/cloudposse/)! + +We offer paid support on all of our projects. + +Check out [our other projects][github], [apply for a job][jobs], or [hire us][hire] to help with your cloud strategy and implementation. + + [docs]: https://docs.cloudposse.com/ + [website]: https://cloudposse.com/ + [github]: https://github.com/cloudposse/ + [commercial_support]: https://github.com/orgs/cloudposse/projects + [jobs]: https://cloudposse.com/jobs/ + [hire]: https://cloudposse.com/contact/ + [slack]: https://slack.cloudposse.com/ + [linkedin]: https://www.linkedin.com/company/cloudposse + [twitter]: https://twitter.com/cloudposse/ + [email]: mailto:[email protected] + + +### Contributors + +| [![Erik Osterman][osterman_avatar]][osterman_homepage]<br/>[Erik Osterman][osterman_homepage] | [![Jamie Nelson][Jamie-BitFlight_avatar]][Jamie-BitFlight_homepage]<br/>[Jamie Nelson][Jamie-BitFlight_homepage] | [![Sarkis Varozian][sarkis_avatar]][sarkis_homepage]<br/>[Sarkis Varozian][sarkis_homepage] | +|---|---|---| + + [osterman_homepage]: https://github.com/osterman + [osterman_avatar]: https://github.com/osterman.png?size=150 + [Jamie-BitFlight_homepage]: https://github.com/Jamie-BitFlight + [Jamie-BitFlight_avatar]: https://github.com/Jamie-BitFlight.png?size=150 + [sarkis_homepage]: https://github.com/sarkis + [sarkis_avatar]: https://github.com/sarkis.png?size=150 + + diff --git a/modules/terraform-aws-ec2-cloudwatch-sns-alarms-master/README.yaml b/modules/terraform-aws-ec2-cloudwatch-sns-alarms-master/README.yaml new file mode 100755 index 0000000..1273f40 --- /dev/null +++ b/modules/terraform-aws-ec2-cloudwatch-sns-alarms-master/README.yaml @@ -0,0 +1,95 @@ +--- +# +# This is the canonical configuration for the `README.md` +# Run `make readme` to rebuild the `README.md` +# + +# Name of this project +name: terraform-aws-ecs-cloudwatch-sns-alarms + +# Logo for this project +#logo: docs/logo.png + +# License of this project +license: "APACHE2" + +# Canonical GitHub repo +github_repo: cloudposse/terraform-aws-ecs-cloudwatch-sns-alarms + +# Badges to display +badges: + - name: "Build Status" + image: "https://travis-ci.org/cloudposse/terraform-aws-ecs-cloudwatch-sns-alarms.svg?branch=master" + url: "https://travis-ci.org/cloudposse/terraform-aws-ecs-cloudwatch-sns-alarms" + - name: "Latest Release" + image: "https://img.shields.io/github/release/cloudposse/terraform-aws-ecs-cloudwatch-sns-alarms.svg" + url: "https://github.com/cloudposse/terraform-aws-ecs-cloudwatch-sns-alarms/releases/latest" + - name: "Slack Community" + image: "https://slack.cloudposse.com/badge.svg" + url: "https://slack.cloudposse.com" + +related: + - name: "terraform-aws-cloudwatch-logs" + description: "Terraform Module to Provide a CloudWatch Logs Endpoint" + url: "https://github.com/cloudposse/terraform-aws-cloudwatch-logs" + + - name: "terraform-aws-cloudwatch-flow-logs" + description: "Terraform module for enabling flow logs for vpc and subnets." + url: "https://github.com/cloudposse/terraform-aws-cloudwatch-flow-logs" + + - name: "terraform-aws-efs-cloudwatch-sns-alarms" + description: "Terraform module that configures CloudWatch SNS alerts for EFS" + url: "https://github.com/cloudposse/terraform-aws-efs-cloudwatch-sns-alarms" + + - name: "terrform-aws-elasticache-cloudwatch-sns-alarms" + description: "Terraform module that configures CloudWatch SNS alerts for ElastiCache" + url: "https://github.com/cloudposse/terraform-aws-elasticache-cloudwatch-sns-alarms" + + - name: "terraform-aws-lambda-cloudwatch-sns-alarms" + description: "Terraform module for creating a set of Lambda alarms and outputting to an endpoint" + url: "https://github.com/cloudposse/terraform-aws-lambda-cloudwatch-sns-alarms" + + - name: "terraform-aws-rds-cloudwatch-sns-alarms" + description: "Terraform module that configures important RDS alerts using CloudWatch and sends them to an SNS topic" + url: "https://github.com/cloudposse/terraform-aws-rds-cloudwatch-sns-alarms" + + - name: "terraform-aws-sqs-cloudwatch-sns-alarms" + description: "Terraform module for creating alarms for SQS and notifying endpoints" + url: "https://github.com/cloudposse/terraform-aws-sqs-cloudwatch-sns-alarms" + +# Short description of this project +description: |- + Terraform module for creating alarms for tracking important changes and occurrences from ECS Services. + +# How to use this project +usage: |- + ```hcl + module "ecs_service_alarms" { + source = "git::https://github.com/cloudposse/terraform-aws-ecs-cloudwatch-sns-alarms.git?ref=tags/0.1.0" + namespace = "cp" + stage = "prod" + name = "app" + cluster_name = "example" + service_name = "app" + } + ``` + +# Example usage +#examples: |- + +# How to get started quickly +#quickstart: |- +# Here's how to get started... + +# Other files to include in this README from the project folder +include: + - "docs/terraform.md" + +# Contributors to this project +contributors: + - name: "Erik Osterman" + github: "osterman" + - name: "Jamie Nelson" + github: "Jamie-BitFlight" + - name: "Sarkis Varozian" + github: "sarkis" diff --git a/modules/terraform-aws-ec2-cloudwatch-sns-alarms-master/alarms.tf b/modules/terraform-aws-ec2-cloudwatch-sns-alarms-master/alarms.tf new file mode 100755 index 0000000..c648a64 --- /dev/null +++ b/modules/terraform-aws-ec2-cloudwatch-sns-alarms-master/alarms.tf @@ -0,0 +1,105 @@ +module "cpu_utilization_high_alarm_label" { + source = "../../modules/terraform-null-label-master" + name = "alarm" + namespace = "${var.namespace}" + stage = "${var.stage}" + attributes = "${compact(concat(var.attributes, list("cpu", "utilization", "high")))}" +} + +module "cpu_utilization_low_alarm_label" { + source = "../../modules/terraform-null-label-master" + name = "alarm" + namespace = "${var.namespace}" + stage = "${var.stage}" + attributes = "${compact(concat(var.attributes, list("cpu", "utilization", "low")))}" +} + +module "memory_utilization_high_alarm_label" { + source = "../../modules/terraform-null-label-master" + name = "alarm" + namespace = "${var.namespace}" + stage = "${var.stage}" + attributes = "${compact(concat(var.attributes, list("memory", "utilization", "high")))}" +} + +module "memory_utilization_low_alarm_label" { + source = "../../modules/terraform-null-label-master" + name = "alarm" + namespace = "${var.namespace}" + stage = "${var.stage}" + attributes = "${compact(concat(var.attributes, list("memory", "utilization", "low")))}" +} + +locals { + thresholds = { + CPUUtilizationHighThreshold = "${min(max(var.cpu_utilization_high_threshold, 0), 100)}" + CPUUtilizationLowThreshold = "${min(max(var.cpu_utilization_low_threshold, 0), 100)}" + MemoryUtilizationHighThreshold = "${min(max(var.memory_utilization_high_threshold, 0), 100)}" + MemoryUtilizationLowThreshold = "${min(max(var.memory_utilization_low_threshold, 0), 100)}" + } + +} + +resource "aws_cloudwatch_metric_alarm" "cpu_utilization_high" { + count = "${local.enabled}" + alarm_name = "${module.cpu_utilization_high_alarm_label.id}" + comparison_operator = "GreaterThanThreshold" + evaluation_periods = "${var.cpu_utilization_high_evaluation_periods}" + metric_name = "CPUUtilization" + namespace = "AWS/EC2" + period = "${var.cpu_utilization_high_period}" + statistic = "Average" + threshold = "${local.thresholds["CPUUtilizationHighThreshold"]}" + alarm_description = "${format(var.alarm_description, "CPU", "High", var.cpu_utilization_high_period/60, var.cpu_utilization_high_evaluation_periods)}" + alarm_actions = ["${compact(var.cpu_utilization_high_alarm_actions)}"] + ok_actions = ["${compact(var.cpu_utilization_high_ok_actions)}"] + +} + +resource "aws_cloudwatch_metric_alarm" "cpu_utilization_low" { + count = "${local.enabled}" + alarm_name = "${module.cpu_utilization_low_alarm_label.id}" + comparison_operator = "LessThanThreshold" + evaluation_periods = "${var.cpu_utilization_low_evaluation_periods}" + metric_name = "CPUUtilization" + namespace = "AWS/EC2" + period = "${var.cpu_utilization_low_period}" + statistic = "Average" + threshold = "${local.thresholds["CPUUtilizationLowThreshold"]}" + alarm_description = "${format(var.alarm_description, "CPU", "Low", var.cpu_utilization_low_period/60, var.cpu_utilization_low_evaluation_periods)}" + alarm_actions = ["${compact(var.cpu_utilization_low_alarm_actions)}"] + ok_actions = ["${compact(var.cpu_utilization_low_ok_actions)}"] + +} + +resource "aws_cloudwatch_metric_alarm" "memory_utilization_high" { + count = "${local.enabled}" + alarm_name = "${module.memory_utilization_high_alarm_label.id}" + comparison_operator = "GreaterThanThreshold" + evaluation_periods = "${var.memory_utilization_high_evaluation_periods}" + metric_name = "MemoryUtilization" + namespace = "AWS/EC2" + period = "${var.memory_utilization_high_period}" + statistic = "Average" + threshold = "${local.thresholds["MemoryUtilizationHighThreshold"]}" + alarm_description = "${format(var.alarm_description, "Memory", "Hight", var.memory_utilization_high_period/60, var.memory_utilization_high_evaluation_periods)}" + alarm_actions = ["${compact(var.memory_utilization_high_alarm_actions)}"] + ok_actions = ["${compact(var.memory_utilization_high_ok_actions)}"] + +} + +resource "aws_cloudwatch_metric_alarm" "memory_utilization_low" { + count = "${local.enabled}" + alarm_name = "${module.memory_utilization_low_alarm_label.id}" + comparison_operator = "LessThanThreshold" + evaluation_periods = "${var.memory_utilization_low_evaluation_periods}" + metric_name = "MemoryUtilization" + namespace = "AWS/EC2" + period = "${var.memory_utilization_low_period}" + statistic = "Average" + threshold = "${local.thresholds["MemoryUtilizationLowThreshold"]}" + alarm_description = "${format(var.alarm_description, "Memory", "Low", var.memory_utilization_low_period/60, var.memory_utilization_low_evaluation_periods)}" + alarm_actions = ["${compact(var.memory_utilization_low_alarm_actions)}"] + ok_actions = ["${compact(var.memory_utilization_low_ok_actions)}"] + +} diff --git a/modules/terraform-aws-ec2-cloudwatch-sns-alarms-master/docs/targets.md b/modules/terraform-aws-ec2-cloudwatch-sns-alarms-master/docs/targets.md new file mode 100755 index 0000000..09c39cd --- /dev/null +++ b/modules/terraform-aws-ec2-cloudwatch-sns-alarms-master/docs/targets.md @@ -0,0 +1,9 @@ +## Makefile Targets +``` +Available targets: + + help This help screen + help/all Display help for all targets + lint Lint terraform code + +``` diff --git a/modules/terraform-aws-ec2-cloudwatch-sns-alarms-master/docs/terraform.md b/modules/terraform-aws-ec2-cloudwatch-sns-alarms-master/docs/terraform.md new file mode 100755 index 0000000..a9b7d8b --- /dev/null +++ b/modules/terraform-aws-ec2-cloudwatch-sns-alarms-master/docs/terraform.md @@ -0,0 +1,36 @@ + +## Inputs + +| Name | Description | Type | Default | Required | +|------|-------------|:----:|:-----:|:-----:| +| alarm_description | The string to format and use as the alarm description. | string | `Average service %v utilization %v last %d minute(s) over %v period(s)` | no | +| attributes | List of attributes to add to label. | list | `<list>` | no | +| cluster_name | The name of the ECS cluster to monitor. | string | - | yes | +| cpu_utilization_high_alarm_actions | A list of ARNs (i.e. SNS Topic ARN) to notify on CPU Utilization High Alarm action. | list | `<list>` | no | +| cpu_utilization_high_evaluation_periods | Number of periods to evaluate for the alarm. | string | `1` | no | +| cpu_utilization_high_ok_actions | A list of ARNs (i.e. SNS Topic ARN) to notify on CPU Utilization High OK action. | list | `<list>` | no | +| cpu_utilization_high_period | Duration in seconds to evaluate for the alarm. | string | `300` | no | +| cpu_utilization_high_threshold | The maximum percentage of CPU utilization average. | string | `80` | no | +| cpu_utilization_low_alarm_actions | A list of ARNs (i.e. SNS Topic ARN) to notify on CPU Utilization Low Alarm action. | list | `<list>` | no | +| cpu_utilization_low_evaluation_periods | Number of periods to evaluate for the alarm. | string | `1` | no | +| cpu_utilization_low_ok_actions | A list of ARNs (i.e. SNS Topic ARN) to notify on CPU Utilization Low OK action. | list | `<list>` | no | +| cpu_utilization_low_period | Duration in seconds to evaluate for the alarm. | string | `300` | no | +| cpu_utilization_low_threshold | The minimum percentage of CPU utilization average. | string | `20` | no | +| delimiter | The delimiter to be used in labels. | string | `-` | no | +| enabled | Whether to create all resources | string | `true` | no | +| memory_utilization_high_alarm_actions | A list of ARNs (i.e. SNS Topic ARN) to notify on Memory Utilization High Alarm action. | list | `<list>` | no | +| memory_utilization_high_evaluation_periods | Number of periods to evaluate for the alarm. | string | `1` | no | +| memory_utilization_high_ok_actions | A list of ARNs (i.e. SNS Topic ARN) to notify on Memory Utilization High OK action. | list | `<list>` | no | +| memory_utilization_high_period | Duration in seconds to evaluate for the alarm. | string | `300` | no | +| memory_utilization_high_threshold | The maximum percentage of Memory utilization average. | string | `80` | no | +| memory_utilization_low_alarm_actions | A list of ARNs (i.e. SNS Topic ARN) to notify on Memory Utilization Low Alarm action. | list | `<list>` | no | +| memory_utilization_low_evaluation_periods | Number of periods to evaluate for the alarm. | string | `1` | no | +| memory_utilization_low_ok_actions | A list of ARNs (i.e. SNS Topic ARN) to notify on Memory Utilization Low OK action. | list | `<list>` | no | +| memory_utilization_low_period | Duration in seconds to evaluate for the alarm. | string | `300` | no | +| memory_utilization_low_threshold | The minimum percentage of Memory utilization average. | string | `20` | no | +| name | Name (unique identifier for app or service) | string | - | yes | +| namespace | Namespace (e.g. `cp` or `cloudposse`) | string | - | yes | +| service_name | The name of the ECS Service in the ECS cluster to monitor. | string | `` | no | +| stage | Stage (e.g. `prod`, `dev`, `staging`) | string | - | yes | +| tags | Map of key-value pairs to use for tags. | map | `<map>` | no | + diff --git a/modules/terraform-aws-ec2-cloudwatch-sns-alarms-master/example/README.md b/modules/terraform-aws-ec2-cloudwatch-sns-alarms-master/example/README.md new file mode 100755 index 0000000..2253e58 --- /dev/null +++ b/modules/terraform-aws-ec2-cloudwatch-sns-alarms-master/example/README.md @@ -0,0 +1,29 @@ +# Example usage of the Alarm for monitoring the ECR cluster metric alone. + +To test this example, clone the repoistry, cd into this example directory and run: +```bash +terraform init +terraform apply +``` +A new empty cluster will be created in London region, and two metric alarms will be created for memory and cpu usage. + +```hcl +provider "aws" { + region = "eu-west-2" +} + +module "alarms" { + source = "../" + namespace = "cp" + stage = "prod" + name = "app" + cluster_name = "${aws_ecs_cluster.default.name}" + service_name = "" + enabled = "true" +} + +resource "aws_ecs_cluster" "default" { + name = "cp-prod-app" +} + +``` \ No newline at end of file diff --git a/modules/terraform-aws-ec2-cloudwatch-sns-alarms-master/example/main.tf b/modules/terraform-aws-ec2-cloudwatch-sns-alarms-master/example/main.tf new file mode 100755 index 0000000..f54b9fd --- /dev/null +++ b/modules/terraform-aws-ec2-cloudwatch-sns-alarms-master/example/main.tf @@ -0,0 +1,17 @@ +provider "aws" { + region = "eu-west-2" +} + +module "alarms" { + source = "../" + namespace = "cp" + stage = "prod" + name = "app" + cluster_name = "${aws_ecs_cluster.default.name}" + service_name = "" + enabled = "true" +} + +resource "aws_ecs_cluster" "default" { + name = "cp-prod-app" +} diff --git a/modules/terraform-aws-ec2-cloudwatch-sns-alarms-master/main.tf b/modules/terraform-aws-ec2-cloudwatch-sns-alarms-master/main.tf new file mode 100755 index 0000000..7f8d372 --- /dev/null +++ b/modules/terraform-aws-ec2-cloudwatch-sns-alarms-master/main.tf @@ -0,0 +1,5 @@ +data "aws_caller_identity" "default" {} + +locals { + enabled = "${var.enabled == "true" ? 1 : 0}" +} diff --git a/modules/terraform-aws-ec2-cloudwatch-sns-alarms-master/outputs.tf b/modules/terraform-aws-ec2-cloudwatch-sns-alarms-master/outputs.tf new file mode 100755 index 0000000..8b13789 --- /dev/null +++ b/modules/terraform-aws-ec2-cloudwatch-sns-alarms-master/outputs.tf @@ -0,0 +1 @@ + diff --git a/modules/terraform-aws-ec2-cloudwatch-sns-alarms-master/variables.tf b/modules/terraform-aws-ec2-cloudwatch-sns-alarms-master/variables.tf new file mode 100755 index 0000000..81e0da9 --- /dev/null +++ b/modules/terraform-aws-ec2-cloudwatch-sns-alarms-master/variables.tf @@ -0,0 +1,165 @@ +variable "name" { + type = "string" + description = "Name (unique identifier for app or service)" +} + +variable "namespace" { + type = "string" + description = "Namespace (e.g. `cp` or `cloudposse`)" +} + +variable "delimiter" { + type = "string" + description = "The delimiter to be used in labels." + default = "-" +} + +variable "stage" { + type = "string" + description = "Stage (e.g. `prod`, `dev`, `staging`)" +} + +variable "attributes" { + type = "list" + description = "List of attributes to add to label." + default = [] +} + +variable "tags" { + type = "map" + description = "Map of key-value pairs to use for tags." + default = {} +} + +variable "enabled" { + type = "string" + description = "Whether to create all resources" + default = "true" +} + + +variable "alarm_description" { + type = "string" + description = "The string to format and use as the alarm description." + default = "Average service %v utilization %v last %d minute(s) over %v period(s)" +} + +variable "cpu_utilization_high_threshold" { + type = "string" + description = "The maximum percentage of CPU utilization average." + default = "80" +} + +variable "cpu_utilization_high_evaluation_periods" { + type = "string" + description = "Number of periods to evaluate for the alarm." + default = "1" +} + +variable "cpu_utilization_high_period" { + type = "string" + description = "Duration in seconds to evaluate for the alarm." + default = "300" +} + +variable "cpu_utilization_high_alarm_actions" { + type = "list" + description = "A list of ARNs (i.e. SNS Topic ARN) to notify on CPU Utilization High Alarm action." + default = [] +} + +variable "cpu_utilization_high_ok_actions" { + type = "list" + description = "A list of ARNs (i.e. SNS Topic ARN) to notify on CPU Utilization High OK action." + default = [] +} + +variable "cpu_utilization_low_threshold" { + type = "string" + description = "The minimum percentage of CPU utilization average." + default = "20" +} + +variable "cpu_utilization_low_evaluation_periods" { + type = "string" + description = "Number of periods to evaluate for the alarm." + default = "1" +} + +variable "cpu_utilization_low_period" { + type = "string" + description = "Duration in seconds to evaluate for the alarm." + default = "300" +} + +variable "cpu_utilization_low_alarm_actions" { + type = "list" + description = "A list of ARNs (i.e. SNS Topic ARN) to notify on CPU Utilization Low Alarm action." + default = [] +} + +variable "cpu_utilization_low_ok_actions" { + type = "list" + description = "A list of ARNs (i.e. SNS Topic ARN) to notify on CPU Utilization Low OK action." + default = [] +} + +variable "memory_utilization_high_threshold" { + type = "string" + description = "The maximum percentage of Memory utilization average." + default = "80" +} + +variable "memory_utilization_high_evaluation_periods" { + type = "string" + description = "Number of periods to evaluate for the alarm." + default = "1" +} + +variable "memory_utilization_high_period" { + type = "string" + description = "Duration in seconds to evaluate for the alarm." + default = "300" +} + +variable "memory_utilization_high_alarm_actions" { + type = "list" + description = "A list of ARNs (i.e. SNS Topic ARN) to notify on Memory Utilization High Alarm action." + default = [] +} + +variable "memory_utilization_high_ok_actions" { + type = "list" + description = "A list of ARNs (i.e. SNS Topic ARN) to notify on Memory Utilization High OK action." + default = [] +} + +variable "memory_utilization_low_threshold" { + type = "string" + description = "The minimum percentage of Memory utilization average." + default = "20" +} + +variable "memory_utilization_low_evaluation_periods" { + type = "string" + description = "Number of periods to evaluate for the alarm." + default = "1" +} + +variable "memory_utilization_low_period" { + type = "string" + description = "Duration in seconds to evaluate for the alarm." + default = "300" +} + +variable "memory_utilization_low_alarm_actions" { + type = "list" + description = "A list of ARNs (i.e. SNS Topic ARN) to notify on Memory Utilization Low Alarm action." + default = [] +} + +variable "memory_utilization_low_ok_actions" { + type = "list" + description = "A list of ARNs (i.e. SNS Topic ARN) to notify on Memory Utilization Low OK action." + default = [] +} diff --git a/modules/terraform-aws-key-pair-master/.gitignore b/modules/terraform-aws-key-pair-master/.gitignore index bf42b9f..a57087d 100755 --- a/modules/terraform-aws-key-pair-master/.gitignore +++ b/modules/terraform-aws-key-pair-master/.gitignore @@ -2,10 +2,13 @@ *.tfstate *.tfstate.backup +# .tfvars files +*.tfvars + # Module directory .terraform/ .idea *.iml .build-harness -build-harness \ No newline at end of file +build-harness diff --git a/modules/terraform-aws-key-pair-master/main.tf b/modules/terraform-aws-key-pair-master/main.tf index 4ca8c97..f49f09e 100755 --- a/modules/terraform-aws-key-pair-master/main.tf +++ b/modules/terraform-aws-key-pair-master/main.tf @@ -2,7 +2,7 @@ module "label" { source = "../../modules/terraform-null-label-master" namespace = "${var.namespace}" stage = "${var.stage}" - name = "${var.name}" + name = "key_pair" attributes = "${var.attributes}" delimiter = "${var.delimiter}" tags = "${var.tags}" diff --git a/modules/terraform-aws-multi-az-subnets-master/multi-az-subnets.tfvars b/modules/terraform-aws-multi-az-subnets-master/multi-az-subnets.tfvars new file mode 100644 index 0000000..b6088e0 --- /dev/null +++ b/modules/terraform-aws-multi-az-subnets-master/multi-az-subnets.tfvars @@ -0,0 +1 @@ +name = "multi-az-subnets" diff --git a/modules/terraform-aws-multi-az-subnets-master/private.tf b/modules/terraform-aws-multi-az-subnets-master/private.tf index 2bdb9cb..3d956c5 100755 --- a/modules/terraform-aws-multi-az-subnets-master/private.tf +++ b/modules/terraform-aws-multi-az-subnets-master/private.tf @@ -6,7 +6,7 @@ locals { module "private_label" { source = "../../modules/terraform-null-label-master" namespace = "${var.namespace}" - name = "${var.name}" + name = "subnet" stage = "${var.stage}" delimiter = "${var.delimiter}" tags = "${var.tags}" diff --git a/modules/terraform-aws-multi-az-subnets-master/public.tf b/modules/terraform-aws-multi-az-subnets-master/public.tf index 5ce1b7b..3253a29 100755 --- a/modules/terraform-aws-multi-az-subnets-master/public.tf +++ b/modules/terraform-aws-multi-az-subnets-master/public.tf @@ -6,7 +6,7 @@ locals { module "public_label" { source = "../../modules/terraform-null-label-master" namespace…
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
I would like to use conditional processing which was introduced in 0.8.x but seems having something wrong. Here is the relevant part
And the error message is:
I saw some examples in that #1604 and this is something very similar to them. Why is this causing an error?
The text was updated successfully, but these errors were encountered: