-
-
Notifications
You must be signed in to change notification settings - Fork 353
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
fix: FQDN detection when using an existing ALB #379
fix: FQDN detection when using an existing ALB #379
Conversation
@@ -2,8 +2,8 @@ locals { | |||
# Atlantis | |||
atlantis_url = "https://${try(coalesce( |
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 think this all can be re-written and simplified to:
atlantis_url = "https://${try(
var.atlantis.fqdn,
module.alb.route53_records["A"].fqdn,
module.alb.dns_name,
"",
)}"
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 tried that, but I got this error:
╷
│ Error: Invalid template interpolation value
│
│ on ../../main.tf line 3, in locals:
│ 3: atlantis_url = "https://${try(
│ 4: var.atlantis.fqdn,
│ 5: module.alb.route53_records["A"].fqdn,
│ 6: module.alb.dns_name,
│ 7: ""
│ 8: )}"
│ ├────────────────
│ │ module.alb.dns_name is null
│ │ module.alb.route53_records is object with no attributes
│ │ var.atlantis is object with no attributes
│
│ The expression result is null. Cannot include a null value in a string template.
╵
I think the problem is that module.alb.dns_name
is always defined, even if it is null
. Therefore, it doesn't throw an error, and try
returns null
.
I tried wrapping the try
call in a call to coalesce
, but that didn't fix the error, since coalesce
raises an error when the final result is an empty string.
So I think we need the call to coalesce
to drop the load balancer DNS name if it is null, and we need the try
outside the coalesce
to handle the case when there is no valid name. I removed the try
around module.alb.dns_name
, as it doesn't seem to be needed.
601dad8
to
4a4a0f7
Compare
main.tf
Outdated
@@ -2,7 +2,7 @@ locals { | |||
# Atlantis | |||
atlantis_url = "https://${try(coalesce( | |||
try(var.atlantis.fqdn, null), |
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.
hmm, ok. well we can at least save one try()
for now with the following. I believe this should work if what you are proposing works:
atlantis_url = "https://${try(coalesce(
try(var.atlantis.fqdn, module.alb.route53_records["A"].fqdn, null),
module.alb.dns_name,
), "")}"
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.
That's a good point. Just updated the commit - seems to work!
When using an existing ALB, module.alb isn't fully populated, and referencing the Route 53 records fails. The error is caught by the top-level try, leaving atlantis_url empty. With this change, wrapping the reference to module.alb.route53_records in a try, var.atlantis.fqdn is used even when using an existing ALB. Fixes terraform-aws-modules#377.
4a4a0f7
to
5aba967
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.
Thank you!
### [4.0.6](v4.0.5...v4.0.6) (2023-12-11) ### Bug Fixes * FQDN detection when using an existing ALB ([#379](#379)) ([50ee855](50ee855))
This PR is included in version 4.0.6 🎉 |
I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
Description
In the definition of the local variable
atlantis_url
, currently attributes ofmodule.alb
are referenced within acoalesce
function call.coalesce
isn't short-circuiting, so even ifvar.atlantis.fqdn
was provided, it won't be used in the case when an existing ALB is used: the reference tomodule.alb.route53_records["A"]
will fail, and the error will be caught by the top-leveltry
, leavingatlantis_url
ashttps://
.In this change, the individual references to
module.alb
are wrapped intry
calls, meaning thatvar.atlantis.fqdn
will be respected if provided.Motivation and Context
This change fixes this issue: #377
With this change, links in the "Checks" section of a Github pull request point to the correct URL.
Breaking Changes
This change can force replacement of the ECS task definition in the case where an existing ALB was used and
var.atlantis.fqdn
was specified (but ignored). If this is not desirable, this can be avoided by removing that variable from the configuration. I believe this is unlikely to happen.How Has This Been Tested?
examples/*
to demonstrate and validate my change(s)examples/*
projectsI added the
fqdn
variable togithub-separate
, and deployed it without this change. That resulted inATLANTIS_ATLANTIS_URL
being set tohttps://
. Then I ranterraform apply
with this change. That resulted inmodule.atlantis.module.ecs_service.aws_ecs_task_definition.this[0]
being recreated andATLANTIS_ATLANTIS_URL
being set to the URL of the load balancer.pre-commit run -a
on my pull request