Skip to content
main.tf 1.7 KiB
Newer Older
nimrod's avatar
nimrod committed
terraform {
  backend "http" {}
nimrod's avatar
nimrod committed
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 4.0"
    }
  }
nimrod's avatar
nimrod committed
}

locals {
  env    = terraform.workspace == "default" ? "prod" : terraform.workspace
  module = basename(abspath(path.root))
  common_tags = {
    Environment = local.env
    Module      = local.module
nimrod's avatar
nimrod committed
    Name        = local.name
nimrod's avatar
nimrod committed
  }
nimrod's avatar
nimrod committed
  name = "${local.module}-${local.env}"
nimrod's avatar
nimrod committed
}

nimrod's avatar
nimrod committed
output "env" {
  description = "Environment (prod/dev etc.)."
  value       = local.env
}

output "module" {
  description = "The name of the Terraform module, used to tagging resources."
  value       = local.module
}

variable "region" {
nimrod's avatar
nimrod committed
  default     = "eu-west-2"
nimrod's avatar
nimrod committed
  description = "AWS region."
  type        = string
}

output "region" {
  description = "AWS region."
  value       = var.region
}

nimrod's avatar
nimrod committed
provider "aws" {
  region = var.region
nimrod's avatar
nimrod committed
  default_tags {
    tags = local.common_tags
  }
nimrod's avatar
nimrod committed
}

nimrod's avatar
nimrod committed
resource "aws_resourcegroups_group" "group" {
nimrod's avatar
nimrod committed
  name = local.name
nimrod's avatar
nimrod committed
  resource_query {
    query = <<EOF
{
  "ResourceTypeFilters": [
    "AWS::AllSupported"
  ],
  "TagFilters": [
    {
      "Key": "Module",
      "Values": ["${local.module}"]
    },
    {
      "Key": "Environment",
      "Values": ["${local.env}"]
    }
  ]
}
EOF
  }
}

locals {
  resource_group_arn  = aws_resourcegroups_group.group.arn
  resource_group_name = aws_resourcegroups_group.group.name
}

output "resource_group_arn" {
  description = "ARN of the resource group."
  value       = local.resource_group_arn
}

output "resource_group_name" {
  description = "Name of the resource group."
  value       = local.resource_group_name
}

variable "log_retention" {
  default     = 3
  description = "Number of days to retain logs."
  type        = number
}