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

Add volume type var #7

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
107 changes: 59 additions & 48 deletions compute.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ resource "aws_launch_configuration" "main" {
iam_instance_profile = aws_iam_instance_profile.ec2.name

root_block_device {
volume_type = "gp2"
volume_type = var.storage_class
volume_size = var.attached_volume_size
delete_on_termination = true
}
Expand All @@ -26,6 +26,44 @@ resource "aws_launch_configuration" "main" {
}
}

locals { common_tags = [
{
key = "OwnerList"
value = var.owner
propagate_at_launch = true
},
{
key = "EndDate"
value = var.end_date
propagate_at_launch = true
},
{
key = "EnvironmentList"
value = var.env
propagate_at_launch = true
},
{
key = "ProjectList"
value = var.project
propagate_at_launch = true
},
{
key = "DeploymentType"
value = var.deployment_type
propagate_at_launch = true
},
{
key = "App"
value = var.deployed_app
propagate_at_launch = true
},
{
key = "SoftwareVersion"
value = var.software_version
propagate_at_launch = true
},
] }

resource "aws_autoscaling_group" "main" {
count = var.deployed ? 1 : 0
name = "asg-${var.project_id}-${var.env}-${var.deployed_app}-${var.deployment}"
Expand All @@ -39,53 +77,26 @@ resource "aws_autoscaling_group" "main" {
create_before_destroy = true
}

tags = [
{
key = "Name"
value = "${var.deployed_app}-${var.project}-${var.env}-${var.deployment}-${count.index}"
propagate_at_launch = true
},
{
key = "Group"
value = "${var.deployed_app}-${var.project}-${var.env}-${var.deployment}"
propagate_at_launch = true
},
{
key = "OwnerList"
value = var.owner
propagate_at_launch = true
},
{
key = "EndDate"
value = var.end_date
propagate_at_launch = true
},
{
key = "EnvironmentList"
value = var.env
propagate_at_launch = true
},
{
key = "ProjectList"
value = var.project
propagate_at_launch = true
},
{
key = "DeploymentType"
value = var.deployment_type
propagate_at_launch = true
},
{
key = "App"
value = var.deployed_app
propagate_at_launch = true
},
{
key = "SoftwareVersion"
value = var.software_version
propagate_at_launch = true
},
]
tag {
key = "Name"
value = "${var.deployed_app}-${var.project}-${var.env}-${var.deployment}-${count.index}"
propagate_at_launch = true
}
tag {
key = "Group"
value = "${var.deployed_app}-${var.project}-${var.env}-${var.deployment}"
propagate_at_launch = true
}

dynamic "tag" {
for_each = local.common_tags
content {
key = tag.value.key
propagate_at_launch = tag.value.propagate_at_launch
value = tag.value.value
}
}

}

resource "aws_cloudwatch_metric_alarm" "cpu_utilization" {
Expand Down
4 changes: 4 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
variable "deployment" {}
variable "env" {}
variable "storage_class" {
description = "storage class"
default = "gp2"
}
variable "project" {}
variable "project_id" {}
variable "deployment_type" {
Expand Down
Loading