This repository was archived by the owner on Jan 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 459
Feature/launch template #97
Open
jcejohnson
wants to merge
9
commits into
hashicorp:master
Choose a base branch
from
EFXCIA:feature/launch-template
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ef23524
First pass at using launch_template as an alternative to launch_confi…
jcejohnson 72aee03
WIP experiment but failed due to: https://github.com/terraform-provid…
efx-jjohnson 0ee25b9
Set the cluster name tag (etc) after cluster_extra_tags (etc) so that…
efx-jjohnson 055132e
It's not pretty but it works. Though I think we should wait for https…
efx-jjohnson af10a1f
Working launch_template without any hacks.
efx-jjohnson cbd44e2
Fix default vaule and explain the choices
efx-jjohnson ed5cebe
Wrong dependency for launch_configuration based autoscaling group
jcejohnson bb7a7a6
Cleaner approach for setting the cluster_size output value
jcejohnson 234f63b
launch_configuration can also request volume encryption
jcejohnson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
WIP experiment but failed due to: hashicorp/terraform-provider-aws#4553
- Loading branch information
commit 72aee0343fc697b282f70aecca5a512fa040542d
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -13,22 +13,21 @@ terraform { | |
| resource "aws_autoscaling_group" "autoscaling_group" { | ||
| name_prefix = "${var.cluster_name}" | ||
|
|
||
| launch_configuration = "${var.use_launch_template ? 0 : aws_launch_configuration.launch_configuration.*.name[0]}" | ||
| launch_template = "${var.use_launch_template ? aws_launch_template.launch_template.*.name[0] : 0}" | ||
| # launch_configuration = "${aws_launch_configuration.launch_configuration.name}" | ||
|
|
||
| launch_template { | ||
| id = "${aws_launch_template.launch_template.id}" | ||
| } | ||
| availability_zones = ["${var.availability_zones}"] | ||
| vpc_zone_identifier = ["${var.subnet_ids}"] | ||
|
|
||
| # Use a fixed-size cluster | ||
| min_size = "${var.cluster_size}" | ||
| max_size = "${var.cluster_size}" | ||
| desired_capacity = "${var.cluster_size}" | ||
| termination_policies = ["${var.termination_policies}"] | ||
|
|
||
| min_size = "${var.cluster_size}" | ||
| max_size = "${var.cluster_size}" | ||
| desired_capacity = "${var.cluster_size}" | ||
| termination_policies = ["${var.termination_policies}"] | ||
| health_check_type = "${var.health_check_type}" | ||
| health_check_grace_period = "${var.health_check_grace_period}" | ||
| wait_for_capacity_timeout = "${var.wait_for_capacity_timeout}" | ||
|
|
||
| tags = ["${concat( | ||
| list( | ||
| map("key", var.cluster_tag_key, "value", var.cluster_name, "propagate_at_launch", true) | ||
|
|
@@ -38,11 +37,10 @@ resource "aws_autoscaling_group" "autoscaling_group" { | |
| } | ||
|
|
||
| # --------------------------------------------------------------------------------------------------------------------- | ||
| # CREATE LAUNCH CONFIGURATION TO DEFINE WHAT RUNS ON EACH INSTANCE IN THE ASG | ||
| # CREATE LAUNCH TEMPLATE TO DEFINE WHAT RUNS ON EACH INSTANCE IN THE ASG | ||
| # --------------------------------------------------------------------------------------------------------------------- | ||
|
|
||
| resource "aws_launch_configuration" "launch_configuration" { | ||
| count = "${var.use_launch_template ? 0 : 1}" | ||
| name_prefix = "${var.cluster_name}-" | ||
| image_id = "${var.ami_id}" | ||
| instance_type = "${var.instance_type}" | ||
|
|
@@ -82,11 +80,10 @@ data "aws_ami" "ami" { | |
| } | ||
|
|
||
| resource "aws_launch_template" "launch_template" { | ||
| count = "${var.use_launch_template ? 1 : 0}" | ||
| name_prefix = "${var.cluster_name}-" | ||
| image_id = "${var.ami_id}" | ||
| instance_type = "${var.instance_type}" | ||
| user_data = "${var.user_data}" | ||
| user_data = "${base64encode(var.user_data)}" | ||
|
|
||
| iam_instance_profile { | ||
| name = "${aws_iam_instance_profile.instance_profile.name}" | ||
|
|
@@ -99,29 +96,32 @@ resource "aws_launch_template" "launch_template" { | |
| tenancy = "${var.tenancy}" | ||
| } | ||
|
|
||
| network_interfaces { | ||
| associate_public_ip_address = "${var.associate_public_ip_address}" | ||
| } | ||
| # network_interfaces { | ||
| # associate_public_ip_address = "${var.associate_public_ip_address}" | ||
| # security_groups = ["${concat(list(aws_security_group.lc_security_group.id), var.additional_security_group_ids)}"] | ||
| # } | ||
|
|
||
| ebs_optimized = "${var.root_volume_ebs_optimized}" | ||
|
|
||
| block_device { | ||
| device_name = "${data.aws_ami.ami.root_device_name}" | ||
| volume_type = "${var.root_volume_type}" | ||
| volume_size = "${var.root_volume_size}" | ||
| delete_on_termination = "${var.root_volume_delete_on_termination}" | ||
| block_device_mappings { | ||
| device_name = "${data.aws_ami.ami.root_device_name}" | ||
|
|
||
| ebs { | ||
| encrypted = "${var.ebs_encryption}" | ||
| volume_type = "${var.root_volume_type}" | ||
| volume_size = "${var.root_volume_size}" | ||
| delete_on_termination = "${var.root_volume_delete_on_termination}" | ||
| } | ||
| } | ||
|
|
||
| tags = "${var.launch_template_tags}" | ||
| tag_specifications { | ||
| # Instanc tags are already handled by the autoscaling group | ||
| # Instance tags are already handled by the autoscaling group | ||
| resource_type = "volume" | ||
|
|
||
| tags = "${merge( | ||
| map("key", var.cluster_tag_key, "value", var.cluster_name), | ||
| var.volume_extra_tags) | ||
| }" | ||
| } | ||
|
|
||
| # Important note: whenever using a launch configuration with an auto scaling group, you must set | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this true with a launch template too? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To be honest, I'm not entirely sure that it is (still?) true for launch_configuration. My code is uses the vault-cluster default (true) and I haven't made any special configuration for the other resources. |
||
| # create_before_destroy = true. However, as soon as you set create_before_destroy = true in one resource, you must | ||
| # also set it in every resource that it depends on, or you'll get an error about cyclic dependencies (especially when | ||
|
|
||
This file contains hidden or 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
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I must admit that this is a lot of extra code to maintain just to be able to tag EBS volumes. Is there no other way to do it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. My hope is that others will find other reasons why launch_template is a better alternative for their usecases and can expand on what I've started here.
The reason for the long delay between my initial submission & issue and this PR was due to the aws provider issue mentioned elsewhere. In the meantime, I was able to find a workaround via user-data script which inspects the instance & applies its tags to the instance volume. Of course, that requires that the instance be able to query its own tags and apply tags to its instance.
So, yes, there is another way to do it but it's a hack. And, from what I gather, launch templates are the new hot thing and presumably the preferred option going forward.