Skip to content
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

use default tags on an aws provider level #336

Merged
merged 5 commits into from
Jun 10, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
197 changes: 99 additions & 98 deletions terraform/layer1-aws/README.md

Large diffs are not rendered by default.

5 changes: 0 additions & 5 deletions terraform/layer1-aws/aws-cloudtrail.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ resource "aws_s3_bucket" "cloudtrail" {
tags = local.tags
}

resource "aws_s3_bucket_acl" "cloudtrail" {
bucket = aws_s3_bucket.cloudtrail.id
acl = "private"
}

resource "aws_s3_bucket_lifecycle_configuration" "cloudtrail" {
bucket = aws_s3_bucket.cloudtrail.id

Expand Down
6 changes: 1 addition & 5 deletions terraform/layer1-aws/aws-eks.tf
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,6 @@ module "eks" {
cluster_enabled_log_types = var.eks_cluster_enabled_log_types
cloudwatch_log_group_retention_in_days = var.eks_cloudwatch_log_group_retention_in_days

tags = {
ClusterName = local.name
Environment = local.env
}

vpc_id = module.vpc.vpc_id

cluster_endpoint_public_access = var.eks_cluster_endpoint_public_access
Expand Down Expand Up @@ -185,6 +180,7 @@ module "eks" {
}
}

tags = { "ClusterName" = local.name }
}

module "vpc_cni_irsa" {
Expand Down
23 changes: 22 additions & 1 deletion terraform/layer1-aws/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "4.62.0"
version = "5.1.0"
}
kubernetes = {
source = "hashicorp/kubernetes"
Expand Down Expand Up @@ -33,3 +33,24 @@ resource "aws_iam_account_password_policy" "default" {
allow_users_to_change_password = var.aws_account_password_policy.allow_users_to_change_password
max_password_age = var.aws_account_password_policy.max_password_age
}


module "aws-cost-allocation-tags" {
mglotov marked this conversation as resolved.
Show resolved Hide resolved
count = var.is_this_payment_account ? 1 : 0

source = "../modules/aws-cost-allocation-tags"
tags = [
{
tag_key = "Environment"
status = "Active"
},
{
tag_key = "Terraform"
status = "Active"
},
{
tag_key = "aws:autoscaling:groupName"
status = "Active"
}
]
}
7 changes: 7 additions & 0 deletions terraform/layer1-aws/providers.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
provider "aws" {
region = var.region
allowed_account_ids = var.allowed_account_ids
default_tags {
tags = {
Name = local.name
Environment = local.env
Terraform = "true"
}
}
}

provider "kubernetes" {
Expand Down
5 changes: 5 additions & 0 deletions terraform/layer1-aws/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ variable "aws_account_password_policy" {
}
}

variable "is_this_payment_account" {
default = true
description = "Set it to false if target account is under AWS Organization. This variable is used to enable apply configuration for cost allocation tags"
}

variable "name" {
description = "Project name, required to create unique resource names"
}
Expand Down
6 changes: 6 additions & 0 deletions terraform/modules/aws-cost-allocation-tags/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
resource "aws_ce_cost_allocation_tag" "this" {
for_each = { for item in var.tags : item.tag_key => item }

tag_key = each.value.tag_key
status = each.value.status
}
6 changes: 6 additions & 0 deletions terraform/modules/aws-cost-allocation-tags/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
variable "tags" {
mglotov marked this conversation as resolved.
Show resolved Hide resolved
type = list(object({
tag_key = string
status = string
}))
}
2 changes: 1 addition & 1 deletion terraform/modules/aws-pritunl/main.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
data "aws_region" "current" {}
resource "aws_eip" "this" {
vpc = true
domain = "vpc"
tags = {
Name = var.name
Environment = var.environment
Expand Down