Skip to content

Commit deae213

Browse files
committed
OCPBUGS-32174: save correct bootstrap public IP
When the BYOIPv4 feature was introduced to the terraform provisioning in 50c0a9d, a new EIP resource was created unconditionally. The bootstrap VM was first getting a public IP from the `associate_public_ip_address` config in the instance and that IP was then discarded when the EIP was created and associated with the instance. However, a "race" could happen in which, at the end of the bootstrap stage, we saved the first (and now dead) IP address: ``` DEBUG Outputs: DEBUG DEBUG bootstrap_ip = "18.222.119.149" DEBUG [INFO] running Terraform command: /c/terraform/bin/terraform output -no-color -json DEBUG { DEBUG "bootstrap_ip": { DEBUG "sensitive": false, DEBUG "type": "string", DEBUG "value": "18.222.119.149" DEBUG } DEBUG } ``` In case of bootstrap failure, the `gather bootstrap` would use the stale IP address and fail to connect: ``` time="2024-04-12T15:08:49Z" level=info msg="Failed to gather bootstrap logs: failed to connect to the bootstrap machine: dial tcp 18.222.119.149:22: connect: connection timed out" ``` instead of using the actual EIP address "18.225.29.102". This changes proposes the following fixes: 1. Only create an EIP if a public IPv4 pool has been specified. 2. Only `associate_public_ip_address` to the bootstrap instance if public IPv4 pools have *not* been specified. 3. At the end of the bootstrap stage, save the correct IP address by considering whether the bootstrap EIP was created or not.
1 parent d8c7872 commit deae213

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

data/data/aws/bootstrap/main.tf

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ resource "aws_instance" "bootstrap" {
161161
subnet_id = var.aws_publish_strategy == "External" ? var.public_subnet_ids[0] : var.private_subnet_ids[0]
162162
user_data = var.aws_bootstrap_stub_ignition
163163
vpc_security_group_ids = [var.master_sg_id, aws_security_group.bootstrap.id]
164-
associate_public_ip_address = local.public_endpoints
164+
associate_public_ip_address = local.public_endpoints && var.aws_public_ipv4_pool == ""
165165

166166
lifecycle {
167167
# Ignore changes in the AMI which force recreation of the resource. This
@@ -251,9 +251,10 @@ resource "aws_security_group_rule" "bootstrap_journald_gateway" {
251251
}
252252

253253
resource "aws_eip" "bootstrap" {
254+
count = var.aws_public_ipv4_pool == "" ? 0 : 1
254255
domain = "vpc"
255256
instance = aws_instance.bootstrap.id
256-
public_ipv4_pool = var.aws_public_ipv4_pool == "" ? null : var.aws_public_ipv4_pool
257+
public_ipv4_pool = var.aws_public_ipv4_pool
257258

258259
depends_on = [aws_instance.bootstrap]
259-
}
260+
}

data/data/aws/bootstrap/outputs.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
output "bootstrap_ip" {
2-
value = local.public_endpoints ? aws_instance.bootstrap.public_ip : aws_instance.bootstrap.private_ip
2+
value = var.aws_public_ipv4_pool != "" ? aws_eip.bootstrap[0].public_ip : local.public_endpoints ? aws_instance.bootstrap.public_ip : aws_instance.bootstrap.private_ip
33
}

0 commit comments

Comments
 (0)