forked from terraform-aws-modules/terraform-aws-autoscaling
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
185 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Auto Scaling Group without ELB example | ||
|
||
Configuration in this directory creates Launch Configuration and Auto Scaling Group. | ||
|
||
Data sources are used to discover existing VPC resources (VPC, subnet and security group) as well as AMI details. | ||
|
||
## Usage | ||
|
||
To run this example you need to execute: | ||
|
||
```bash | ||
$ terraform init | ||
$ terraform plan | ||
$ terraform apply | ||
``` | ||
|
||
Note that this example may create resources which cost money. Run `terraform destroy` when you don't need these resources. | ||
|
||
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK --> | ||
## Outputs | ||
|
||
| Name | Description | | ||
|------|-------------| | ||
| this\_autoscaling\_group\_availability\_zones | The availability zones of the autoscale group | | ||
| this\_autoscaling\_group\_id | The autoscaling group id | | ||
| this\_autoscaling\_group\_load\_balancers | The load balancer names associated with the autoscaling group | | ||
| this\_autoscaling\_group\_target\_group\_arns | List of Target Group ARNs that apply to this AutoScaling Group | | ||
| this\_autoscaling\_group\_vpc\_zone\_identifier | The VPC zone identifier | | ||
| this\_launch\_configuration\_id | The ID of the launch configuration | | ||
|
||
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
provider "aws" { | ||
region = "eu-west-1" | ||
|
||
# Make it faster by skipping something | ||
skip_get_ec2_platforms = true | ||
skip_metadata_api_check = true | ||
skip_region_validation = true | ||
skip_credentials_validation = true | ||
skip_requesting_account_id = true | ||
} | ||
|
||
############################################################## | ||
# Data sources to get VPC, subnets and security group details | ||
############################################################## | ||
data "aws_vpc" "default" { | ||
default = true | ||
} | ||
|
||
data "aws_subnet_ids" "all" { | ||
vpc_id = data.aws_vpc.default.id | ||
} | ||
|
||
data "aws_security_group" "default" { | ||
vpc_id = data.aws_vpc.default.id | ||
name = "default" | ||
} | ||
|
||
data "aws_ami" "amazon_linux" { | ||
most_recent = true | ||
owners = ["137112412989"] # Amazon | ||
|
||
filter { | ||
name = "name" | ||
|
||
values = [ | ||
"amzn-ami-hvm-*-x86_64-gp2", | ||
] | ||
} | ||
|
||
filter { | ||
name = "owner-alias" | ||
|
||
values = [ | ||
"amazon", | ||
] | ||
} | ||
} | ||
|
||
resource "aws_iam_service_linked_role" "autoscaling" { | ||
aws_service_name = "autoscaling.amazonaws.com" | ||
description = "A service linked role for autoscaling" | ||
custom_suffix = "something" | ||
|
||
# Sometimes good sleep is required to have some IAM resources created before they can be used | ||
provisioner "local-exec" { | ||
command = "sleep 10" | ||
} | ||
} | ||
|
||
###### | ||
# Launch configuration and autoscaling group | ||
###### | ||
module "example" { | ||
source = "../../" | ||
|
||
name = "example-with-ec2" | ||
|
||
# Launch configuration | ||
# | ||
# launch_configuration = "my-existing-launch-configuration" # Use the existing launch configuration | ||
# create_lc = false # disables creation of launch configuration | ||
lc_name = "example-lc" | ||
|
||
image_id = data.aws_ami.amazon_linux.id | ||
instance_type = "t2.micro" | ||
security_groups = [data.aws_security_group.default.id] | ||
associate_public_ip_address = true | ||
recreate_asg_when_lc_changes = true | ||
|
||
ebs_block_device = [ | ||
{ | ||
device_name = "/dev/xvdz" | ||
volume_type = "gp2" | ||
volume_size = "50" | ||
delete_on_termination = true | ||
}, | ||
] | ||
|
||
root_block_device = [ | ||
{ | ||
volume_size = "50" | ||
volume_type = "gp2" | ||
delete_on_termination = true | ||
}, | ||
] | ||
|
||
# Auto scaling group | ||
asg_name = "example-asg" | ||
vpc_zone_identifier = data.aws_subnet_ids.all.ids | ||
health_check_type = "EC2" | ||
min_size = 0 | ||
max_size = 1 | ||
desired_capacity = 0 | ||
wait_for_capacity_timeout = 0 | ||
service_linked_role_arn = aws_iam_service_linked_role.autoscaling.arn | ||
|
||
tags = [ | ||
{ | ||
key = "Environment" | ||
value = "dev" | ||
propagate_at_launch = true | ||
}, | ||
{ | ||
key = "Project" | ||
value = "megasecret" | ||
propagate_at_launch = true | ||
}, | ||
] | ||
|
||
tags_as_map = { | ||
extra_tag1 = "extra_value1" | ||
extra_tag2 = "extra_value2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
output "this_launch_configuration_id" { | ||
description = "The ID of the launch configuration" | ||
value = module.example.this_launch_configuration_id | ||
} | ||
|
||
output "this_autoscaling_group_id" { | ||
description = "The autoscaling group id" | ||
value = module.example.this_autoscaling_group_id | ||
} | ||
|
||
output "this_autoscaling_group_availability_zones" { | ||
description = "The availability zones of the autoscale group" | ||
value = module.example.this_autoscaling_group_availability_zones | ||
} | ||
|
||
output "this_autoscaling_group_vpc_zone_identifier" { | ||
description = "The VPC zone identifier" | ||
value = module.example.this_autoscaling_group_vpc_zone_identifier | ||
} | ||
|
||
output "this_autoscaling_group_load_balancers" { | ||
description = "The load balancer names associated with the autoscaling group" | ||
value = module.example.this_autoscaling_group_load_balancers | ||
} | ||
|
||
output "this_autoscaling_group_target_group_arns" { | ||
description = "List of Target Group ARNs that apply to this AutoScaling Group" | ||
value = module.example.this_autoscaling_group_target_group_arns | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters