-
-
Notifications
You must be signed in to change notification settings - Fork 223
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
Conversation
main.tf
Outdated
@@ -28,14 +28,18 @@ module "label" { | |||
tags = "${var.tags}" | |||
} | |||
|
|||
locals { | |||
instance_count = "${var.instance_enabled == true ? 1 : 0}" |
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.
It can be simplified to var.instance_enabled ? 1 : 0
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.
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}" |
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.
var.associate_public_ip_address && local.instance_count
means bool && int
.
Should be replaced with corresponding locals
too.
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.
We shouldn't mix bool
and int
into a single expression. Use bool
instead of int
.
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.
Nevermind, Booleans says, that int
1
will be interpolated as true
and int
0
as false
.
ddaa2dc
to
ab7e8cb
Compare
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.
This count should be updated too.
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}" |
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.
security_group_count
would be more precise.
124c385
to
1b25790
Compare
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}" |
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.
typo
1b25790
to
7c88d1f
Compare
locals
for instance_count
locals
feature in order to implement instance switch option
What
locals
feature in order to implement instance switch optionWhy
boolean
value withcount
attribute. TF interpolates"true"/"false"
strings as booleans, but can't interpolatestring
->boolean
->int
terraform-aws-ec2-instance
in order to create replicas, we might be interested inswitch
for those replicas, or replica groupsPlan