Refactor Ansible actions to improve host inventory handling
This commit is contained in:
@@ -0,0 +1 @@
|
||||
../../repository.vault
|
||||
@@ -0,0 +1,7 @@
|
||||
terraform {
|
||||
backend "s3" {
|
||||
bucket = "a13labs.infra"
|
||||
key = "aws-alarms.tfstate"
|
||||
region = "us-east-1"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
resource "aws_cloudwatch_metric_alarm" "billing_alarm" {
|
||||
|
||||
alarm_name = "billing_alarm"
|
||||
comparison_operator = "GreaterThanThreshold"
|
||||
metric_name = "EstimatedCharges"
|
||||
namespace = "AWS/Billing"
|
||||
evaluation_periods = "1"
|
||||
period = "21600"
|
||||
statistic = "Maximum"
|
||||
threshold = local.billing_alarm_limit
|
||||
alarm_description = "Billing alarm"
|
||||
|
||||
alarm_actions = [aws_sns_topic.billing_alarm_topic.arn]
|
||||
|
||||
tags = {
|
||||
Name = "billing_alarm_topic_cf"
|
||||
CreatedBy = "terraform"
|
||||
Environment = "aws-alarms"
|
||||
}
|
||||
}
|
||||
|
||||
# The SNS topic with email subscriptions
|
||||
# https://medium.com/@raghuram.arumalla153/aws-sns-topic-subscription-with-email-protocol-using-terraform-ed05f4f19b73
|
||||
resource "aws_sns_topic" "billing_alarm_topic" {
|
||||
name = "billing_alarm_topic"
|
||||
provisioner "local-exec" {
|
||||
command = "sh ${path.module}/scripts/sns_subscription.sh"
|
||||
environment = {
|
||||
AWS_DEFAULT_REGION = var.region
|
||||
sns_arn = self.arn
|
||||
sns_emails = local.billing_alarm_emails
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
locals {
|
||||
region = "us-east-1"
|
||||
billing_alarm_limit = 40
|
||||
billing_alarm_emails = "c.alexandre.pires@gmail.com"
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
#
|
||||
# Copyright 2019 Alexandre Pires (alexandre.pires@mov.ai)
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# File: outputs.tf
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
terraform {
|
||||
required_version = ">1.9"
|
||||
required_providers {
|
||||
aws = {
|
||||
source = "hashicorp/aws"
|
||||
version = "~>5.70"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Configure the AWS Provider
|
||||
provider "aws" {
|
||||
region = var.region
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
for email in $sns_emails; do
|
||||
echo $email
|
||||
aws sns subscribe --topic-arn "$sns_arn" --protocol email --notification-endpoint "$email"
|
||||
done
|
||||
@@ -0,0 +1,2 @@
|
||||
AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY
|
||||
AWS_SECRET_ACCESS_KEY=$AWS_SECRET_KEY
|
||||
@@ -0,0 +1,4 @@
|
||||
variable "region" {
|
||||
description = "AWS Default region"
|
||||
default = "us-east-1"
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
terraform {
|
||||
required_version = ">= 0.13"
|
||||
}
|
||||
Reference in New Issue
Block a user