Skip to content

Commit

Permalink
Merge pull request #73 from vdice/feat/common-tag-all-resources
Browse files Browse the repository at this point in the history
feat(aws): apply common tags to all resources
  • Loading branch information
vdice authored Jun 27, 2022
2 parents 56c7945 + 164fc40 commit c111106
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 9 deletions.
6 changes: 6 additions & 0 deletions aws/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ This example creates the following resources in the provided AWS account:
- Name: `${var.instance_name}_ssh_key_pair`
- see `var.allowed_ssh_cidr_blocks` for allowed origin IP addresses

> All resources are tagged with a common set of tags, in addition to any
resource-specific tags that might be defined. This enables
[searching for resources based on tags](https://docs.aws.amazon.com/ARG/latest/userguide/tag-editor.html)
and can be helpful if manual cleanup is necessary.
To see these applied tags, run `terraform output common_tags`.

# Security disclaimer

By default, the allowed inbound and SSH CIDR block is `0.0.0.0/0` aka The Entire Internet.
Expand Down
33 changes: 24 additions & 9 deletions aws/terraform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ locals {

hippo_version = "v0.17.0"
hippo_checksum = "2a9690cd8546108fbd27a9f0c4898d1c2c171a76219803290b526e40da1c3211"

common_tags = {
FermyonInstallation = var.instance_name
}
}

# -----------------------------------------------------------------------------
Expand Down Expand Up @@ -61,9 +65,12 @@ data "aws_vpc" "default" {
resource "aws_eip" "lb" {
vpc = true

tags = {
Name = "${var.instance_name}-eip"
}
tags = merge(
local.common_tags,
{
Name = "${var.instance_name}-eip"
}
)
}

resource "aws_eip_association" "lb" {
Expand Down Expand Up @@ -134,9 +141,12 @@ resource "aws_instance" "ec2" {

vpc_security_group_ids = [aws_security_group.ec2.id]

tags = {
Name = var.instance_name
}
tags = merge(
local.common_tags,
{
Name = var.instance_name
}
)
}

# -----------------------------------------------------------------------------
Expand All @@ -147,9 +157,12 @@ resource "aws_security_group" "ec2" {
name_prefix = var.instance_name
vpc_id = data.aws_vpc.default.id

tags = {
Name = "${var.instance_name}-security-group"
}
tags = merge(
local.common_tags,
{
Name = "${var.instance_name}-security-group"
}
)

lifecycle {
create_before_destroy = true
Expand Down Expand Up @@ -233,6 +246,8 @@ resource "tls_private_key" "ec2_ssh_key" {
resource "aws_key_pair" "ec2_ssh_key_pair" {
key_name = "${var.instance_name}_ssh_key_pair"
public_key = tls_private_key.ec2_ssh_key.public_key_openssh

tags = local.common_tags
}

# -----------------------------------------------------------------------------
Expand Down
5 changes: 5 additions & 0 deletions aws/terraform/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ output "hippo_admin_password" {
sensitive = true
}

output "common_tags" {
description = "All applicable AWS resources are tagged with these values"
value = local.common_tags
}

output "environment" {
description = "Get environment config by running: $(terraform output -raw environment)"
sensitive = true
Expand Down

0 comments on commit c111106

Please sign in to comment.