Skip to content

Utilize TF locals feature in order to implement instance switch option #11

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

Merged
merged 4 commits into from
Oct 12, 2017

Conversation

s2504s
Copy link
Contributor

@s2504s s2504s commented Oct 3, 2017

What

  • Utilize TF locals feature in order to implement instance switch option

Why

  • We shouldn't use boolean value with count attribute. TF interpolates "true"/"false" strings as booleans, but can't interpolate string -> boolean -> int
  • When we use terraform-aws-ec2-instance in order to create replicas, we might be interested in switch for those replicas, or replica groups

Plan

image

@s2504s s2504s self-assigned this Oct 3, 2017
@s2504s s2504s requested review from osterman and const-bon October 3, 2017 12:19
main.tf Outdated
@@ -28,14 +28,18 @@ module "label" {
tags = "${var.tags}"
}

locals {
instance_count = "${var.instance_enabled == true ? 1 : 0}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can be simplified to var.instance_enabled ? 1 : 0

Copy link
Contributor

@const-bon const-bon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Provided terraform plan doesn't show anything.
Is that deliberate?

main.tf Outdated
@@ -113,7 +117,7 @@ resource "aws_instance" "default" {
}

resource "aws_eip" "default" {
count = "${var.associate_public_ip_address && var.instance_enabled ? 1 : 0}"
count = "${var.associate_public_ip_address && local.instance_count ? 1 : 0}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var.associate_public_ip_address && local.instance_count means bool && int.
Should be replaced with corresponding locals too.

Copy link
Contributor

@const-bon const-bon Oct 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't mix bool and int into a single expression. Use bool instead of int.

Copy link
Contributor

@const-bon const-bon Oct 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind, Booleans says, that int 1 will be interpolated as true and int 0 as false.

@s2504s
Copy link
Contributor Author

s2504s commented Oct 10, 2017

image

@s2504s s2504s force-pushed the change_var_to_locals branch from ddaa2dc to ab7e8cb Compare October 10, 2017 15:41
Copy link
Contributor

@const-bon const-bon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

main.tf Outdated
@@ -28,22 +28,27 @@ module "label" {
tags = "${var.tags}"
}

locals {
instance_count = "${var.instance_enabled ? 1 : 0}"
create_security_group = "${var.create_default_security_group ? 1 : 0}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security_group_count would be more precise.

@s2504s s2504s force-pushed the change_var_to_locals branch from 124c385 to 1b25790 Compare October 11, 2017 09:59
main.tf Outdated
@@ -28,22 +28,27 @@ module "label" {
tags = "${var.tags}"
}

locals {
instance_count = "${var.instance_enabled ? 1 : 0}"
security_grou_count = "${var.create_default_security_group ? 1 : 0}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo

@s2504s s2504s force-pushed the change_var_to_locals branch from 1b25790 to 7c88d1f Compare October 11, 2017 10:07
@s2504s
Copy link
Contributor Author

s2504s commented Oct 12, 2017

image

@const-bon const-bon changed the title Update the module with locals for instance_count Utilize TF locals feature in order to implement instance switch option Oct 12, 2017
@const-bon const-bon merged commit f41e429 into master Oct 12, 2017
@const-bon const-bon deleted the change_var_to_locals branch October 12, 2017 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants