Skip to content

Commit

Permalink
feat: ASG rolling deploy モジュール内のパラメータを変数にする
Browse files Browse the repository at this point in the history
  • Loading branch information
tkdn committed Mar 9, 2024
1 parent 2a480c4 commit 69be867
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,7 @@ resource "aws_launch_configuration" "example" {
image_id = var.ami
instance_type = var.instance_type
security_groups = [aws_security_group.instance.id]

user_data = templatefile("${path.module}/user-data.sh", {
server_text = var.server_text
server_port = var.server_port
db_address = data.terraform_remote_state.db.outputs.address
db_port = data.terraform_remote_state.db.outputs.port
})
user_data = var.user_data

# ASG がある起動設定を使う場合は必須
lifecycle {
Expand All @@ -31,10 +25,10 @@ resource "aws_autoscaling_group" "example" {
name = var.cluster_name

launch_configuration = aws_launch_configuration.example.name
vpc_zone_identifier = data.aws_subnets.default.ids
vpc_zone_identifier = var.subnet_ids

target_group_arns = [aws_lb_target_group.asg.arn]
health_check_type = "ELB"
target_group_arns = var.target_group_arns
health_check_type = var.health_check_type

min_size = var.min_size
max_size = var.max_size
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,26 @@ variable "server_text" {
type = string
default = "Hello, World"
}

variable "subnet_ids" {
description = "Subnet IDs to deploy to"
type = list(string)
}

variable "target_group_arns" {
description = "ARNs of ALB target groups in which to register Instances"
type = list(string)
default = []
}

variable "health_check_type" {
description = "health check to perform. Must be one of: EC2, ELB"
type = string
default = "EC2"
}

variable "user_data" {
description = "User Data script to run in instance at boot"
type = string
default = null
}

0 comments on commit 69be867

Please sign in to comment.