Skip to content

Commit

Permalink
Add IPs tag to AWS single+xaz cluster members
Browse files Browse the repository at this point in the history
  • Loading branch information
chkp-nimrodgab committed Mar 4, 2024
1 parent 9b07a90 commit 4a11799
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 10 deletions.
18 changes: 18 additions & 0 deletions aws/templates/cluster/cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,15 @@ Resources:
Tags:
- Key: Name
Value: !Join ['-', [!Ref GatewayName, Member-A]]
- Key: IPs
Value: !Join
- ':'
- - !Join [ '=', [ public-ip, !If [ AllocateAddress, !Ref MemberAPublicAddress, '' ] ] ]
- !Join [ '=', [ external-private-ip, !GetAtt MemberAExternalInterface.PrimaryPrivateIpAddress ] ]
- !Join [ '=', [ internal-private-ip, !GetAtt MemberAInternalInterface.PrimaryPrivateIpAddress ] ]
- !Join [ '=', [ cluster-ip, !Ref ClusterPublicAddress ] ]
- !Join [ '=', [ cluster-eth0-private-ip, !Select [ 0, !GetAtt MemberAExternalInterface.SecondaryPrivateIpAddresses ] ] ]
- !Join [ '=', [ cluster-eth1-private-ip, !Select [ 0, !GetAtt MemberAInternalInterface.SecondaryPrivateIpAddresses ] ] ]
ImageId: !GetAtt AMI.Outputs.ImageId
InstanceType: !Ref GatewayInstanceType
BlockDeviceMappings:
Expand Down Expand Up @@ -568,6 +577,15 @@ Resources:
Tags:
- Key: Name
Value: !Join ['-', [!Ref GatewayName, Member-B]]
- Key: IPs
Value: !Join
- ':'
- - !Join [ '=', [ public-ip, !If [ AllocateAddress, !Ref MemberBPublicAddress, '' ] ] ]
- !Join [ '=', [ external-private-ip, !GetAtt MemberBExternalInterface.PrimaryPrivateIpAddress ] ]
- !Join [ '=', [ internal-private-ip, !GetAtt MemberBInternalInterface.PrimaryPrivateIpAddress ] ]
- !Join [ '=', [ cluster-ip, !Ref ClusterPublicAddress ] ]
- !Join [ '=', [ cluster-eth0-private-ip, !Select [ 0, !GetAtt MemberAExternalInterface.SecondaryPrivateIpAddresses ] ] ]
- !Join [ '=', [ cluster-eth1-private-ip, !Select [ 0, !GetAtt MemberAInternalInterface.SecondaryPrivateIpAddresses ] ] ]
ImageId: !GetAtt AMI.Outputs.ImageId
InstanceType: !Ref GatewayInstanceType
BlockDeviceMappings:
Expand Down
16 changes: 16 additions & 0 deletions aws/templates/cross-az-cluster/cross-az-cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,14 @@ Resources:
Tags:
- Key: Name
Value: !Join ['-', [!Ref GatewayName, Member-A]]
- Key: IPs
Value: !Join
- ':'
- - !Join [ '=', [ public-ip, !Ref MemberAPublicAddress ] ]
- !Join [ '=', [ external-private-ip, !GetAtt MemberAExternalInterface.PrimaryPrivateIpAddress ] ]
- !Join [ '=', [ internal-private-ip, !GetAtt MemberAInternalInterface.PrimaryPrivateIpAddress ] ]
- !Join [ '=', [ cluster-ip, !Ref ClusterPublicAddress ] ]
- !Join [ '=', [ secondary-external-private-ip, !Select [ 0, !GetAtt MemberAExternalInterface.SecondaryPrivateIpAddresses ] ] ]
ImageId: !GetAtt AMI.Outputs.ImageId
InstanceType: !Ref GatewayInstanceType
BlockDeviceMappings:
Expand Down Expand Up @@ -623,6 +631,14 @@ Resources:
Tags:
- Key: Name
Value: !Join ['-', [!Ref GatewayName, Member-B]]
- Key: IPs
Value: !Join
- ':'
- - !Join [ '=', [ public-ip, !Ref MemberBPublicAddress ] ]
- !Join [ '=', [ external-private-ip, !GetAtt MemberBExternalInterface.PrimaryPrivateIpAddress ] ]
- !Join [ '=', [ internal-private-ip, !GetAtt MemberBInternalInterface.PrimaryPrivateIpAddress ] ]
- !Join [ '=', [ cluster-ip, !Ref ClusterPublicAddress ] ]
- !Join [ '=', [ secondary-external-private-ip, !Select [ 0, !GetAtt MemberBExternalInterface.SecondaryPrivateIpAddresses ] ] ]
ImageId: !GetAtt AMI.Outputs.ImageId
InstanceType: !Ref GatewayInstanceType
BlockDeviceMappings:
Expand Down
1 change: 1 addition & 0 deletions terraform/aws/cluster/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ In order to check the template version, please refer to [sk116585](https://suppo
| 20230914 | Add support for maintenance mode password |
| 20230923 | Add support for C5d instance type |
| 20231012 | Update AWS Terraform provider version to 5.20.1 |
| 20240304 | Add IPs tag to cluster members |
## License
Expand Down
16 changes: 12 additions & 4 deletions terraform/aws/cluster/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,11 @@ resource "aws_instance" "member-a-instance" {
}

tags = merge({
Name = format("%s-Member-A",var.gateway_name)
Name = format("%s-Member-A",var.gateway_name),
IPs = format("public-ip=%s:external-private-ip=%s:internal-private-ip=%s:cluster-ip=%s:cluster-eth0-private-ip=%s:cluster-eth1-private-ip=%s",
var.allocate_and_associate_eip ? aws_eip.member_a_eip[0].public_ip : "", aws_network_interface.member_a_external_eni.private_ip,aws_network_interface.member_a_internal_eni.private_ip,
aws_eip.cluster_eip.public_ip, element(tolist(setsubtract(tolist(aws_network_interface.member_a_external_eni.private_ips), [aws_network_interface.member_a_external_eni.private_ip])), 0),
element(tolist(setsubtract(tolist(aws_network_interface.member_a_internal_eni.private_ips), [aws_network_interface.member_a_internal_eni.private_ip])), 0))
}, var.instance_tags)

ebs_block_device {
Expand Down Expand Up @@ -146,7 +150,7 @@ resource "aws_instance" "member-a-instance" {
GatewayBootstrapScript = local.gateway_bootstrap_script64,
SICKey = local.gateway_SICkey_base64,
TokenA = var.memberAToken,
MemberAPublicAddress = aws_eip.member_a_eip[0].public_ip,
MemberAPublicAddress = var.allocate_and_associate_eip ? aws_eip.member_a_eip[0].public_ip : "",
AllocateAddress = var.allocate_and_associate_eip,
OsVersion = local.version_split
})
Expand All @@ -168,7 +172,11 @@ resource "aws_instance" "member-b-instance" {
}

tags = merge({
Name = format("%s-Member-B",var.gateway_name)
Name = format("%s-Member-B",var.gateway_name),
IPs = format("public-ip=%s:external-private-ip=%s:internal-private-ip=%s:cluster-ip=%s:cluster-eth0-private-ip=%s:cluster-eth1-private-ip=%s",
var.allocate_and_associate_eip ? aws_eip.member_b_eip[0].public_ip : "", aws_network_interface.member_b_external_eni.private_ip,aws_network_interface.member_b_internal_eni.private_ip,
aws_eip.cluster_eip.public_ip, element(tolist(setsubtract(tolist(aws_network_interface.member_a_external_eni.private_ips), [aws_network_interface.member_a_external_eni.private_ip])), 0),
element(tolist(setsubtract(tolist(aws_network_interface.member_a_internal_eni.private_ips), [aws_network_interface.member_a_internal_eni.private_ip])), 0))
}, var.instance_tags)

ebs_block_device {
Expand Down Expand Up @@ -202,7 +210,7 @@ resource "aws_instance" "member-b-instance" {
GatewayBootstrapScript = local.gateway_bootstrap_script64,
SICKey = local.gateway_SICkey_base64,
TokenB = var.memberBToken,
MemberBPublicAddress = aws_eip.member_b_eip[0].public_ip,
MemberBPublicAddress = var.allocate_and_associate_eip ? aws_eip.member_b_eip[0].public_ip : "",
AllocateAddress = var.allocate_and_associate_eip,
OsVersion = local.version_split
})
Expand Down
8 changes: 4 additions & 4 deletions terraform/aws/cluster/output.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ output "member_b_public_ip" {
value = aws_eip.member_b_eip.*.public_ip
}
output "member_a_ssh" {
value = format("ssh -i %s admin@%s", var.key_name, aws_eip.member_a_eip[0].public_ip)
value = var.allocate_and_associate_eip ? format("ssh -i %s admin@%s", var.key_name, aws_eip.member_a_eip[0].public_ip) : ""
}
output "member_b_ssh" {
value = format("ssh -i %s admin@%s", var.key_name, aws_eip.member_b_eip[0].public_ip)
value = var.allocate_and_associate_eip ? format("ssh -i %s admin@%s", var.key_name, aws_eip.member_b_eip[0].public_ip) : ""
}
output "member_a_url" {
value = format("https://%s", aws_eip.member_a_eip[0].public_ip)
value = var.allocate_and_associate_eip ? format("https://%s", aws_eip.member_a_eip[0].public_ip) : ""
}
output "member_b_url" {
value = format("https://%s", aws_eip.member_b_eip[0].public_ip)
value = var.allocate_and_associate_eip ? format("https://%s", aws_eip.member_b_eip[0].public_ip) : ""
}
1 change: 1 addition & 0 deletions terraform/aws/cross-az-cluster/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ In order to check the template version, please refer to [sk116585](https://suppo
| 20230914 | Add support for maintenance mode password |
| 20230923 | Add support for C5d instance type |
| 20231012 | Update AWS Terraform provider version to 5.20.1 |
| 20240304 | Add IPs tag to cluster members |
## License
This project is licensed under the MIT License - see the [LICENSE](../../../cross-az/LICENSE) file for details
10 changes: 8 additions & 2 deletions terraform/aws/cross-az-cluster/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,10 @@ resource "aws_instance" "member-a-instance" {
}

tags = merge({
Name = format("%s-Member-A",var.gateway_name)
Name = format("%s-Member-A",var.gateway_name),
IPs = format("public-ip=%s:external-private-ip=%s:internal-private-ip=%s:cluster-ip=%s:secondary-external-private-ip=%s",
aws_eip.member_a_eip.public_ip, aws_network_interface.member_a_external_eni.private_ip,aws_network_interface.member_a_internal_eni.private_ip,
aws_eip.cluster_eip.public_ip, element(tolist(setsubtract(tolist(aws_network_interface.member_a_external_eni.private_ips), [aws_network_interface.member_a_external_eni.private_ip])), 0))
}, var.instance_tags)

ebs_block_device {
Expand Down Expand Up @@ -171,7 +174,10 @@ resource "aws_instance" "member-b-instance" {
}

tags = merge({
Name = format("%s-Member-B",var.gateway_name)
Name = format("%s-Member-B",var.gateway_name),
IPs = format("public-ip=%s:external-private-ip=%s:internal-private-ip=%s:cluster-ip=%s:secondary-external-private-ip=%s",
aws_eip.member_b_eip.public_ip, aws_network_interface.member_b_external_eni.private_ip,aws_network_interface.member_b_internal_eni.private_ip,
aws_eip.cluster_eip.public_ip, element(tolist(setsubtract(tolist(aws_network_interface.member_b_external_eni.private_ips), [aws_network_interface.member_b_external_eni.private_ip])), 0))
}, var.instance_tags)

ebs_block_device {
Expand Down

0 comments on commit 4a11799

Please sign in to comment.