Skip to content

Commit ef54959

Browse files
Chandan Babu RChandan Babu R
authored andcommitted
Allow private IP address to be assigned to instances created on OCI
The OCI tenancy available to kernel developers from Oracle allows only private IP addresses to be assigned to compute instances. Hence this commit brings back the ability to work with OCI instances having private IP addresses. The variable "public_ip_map" defined in terraform/*/output.tf files has also been renamed to "controller_ip_map" in order to abstract away the type of the IP address being used. Reviewed-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: Chandan Babu R <chandanbabu@kernel.org>
1 parent c4bed6d commit ef54959

File tree

8 files changed

+36
-28
lines changed

8 files changed

+36
-28
lines changed

playbooks/roles/terraform/tasks/main.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,22 @@
77
tags:
88
- bringup
99

10-
- name: Retrieve the public_ip_map from terraform
10+
- name: Retrieve the controller_ip_map from terraform
1111
delegate_to: localhost
1212
run_once: true
1313
ansible.builtin.command:
1414
chdir: "{{ topdir_path }}/terraform/{{ kdevops_terraform_provider }}"
15-
cmd: "terraform output -json public_ip_map"
15+
cmd: "terraform output -json controller_ip_map"
1616
register: terraform_output
1717
changed_when: false
1818
tags:
1919
- ssh
2020

21-
- name: Convert the retrieved public_ip_map into a dictionary
21+
- name: Convert the retrieved controller_ip_map into a dictionary
2222
delegate_to: localhost
2323
run_once: true
2424
ansible.builtin.set_fact:
25-
public_ip_map: "{{ terraform_output.stdout | from_json }}"
25+
controller_ip_map: "{{ terraform_output.stdout | from_json }}"
2626
tags:
2727
- ssh
2828

playbooks/roles/terraform/templates/ssh_config.j2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
Host {{ inventory_hostname }} {{ public_ip_map[inventory_hostname] }}
2-
HostName {{ public_ip_map[inventory_hostname] }}
1+
Host {{ inventory_hostname }} {{ controller_ip_map[inventory_hostname] }}
2+
HostName {{ controller_ip_map[inventory_hostname] }}
33
User {{ kdevops_terraform_ssh_config_user }}
44
Port 22
55
IdentityFile {{ kdevops_terraform_ssh_config_privkey_file }}

scripts/status_terraform.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ if [[ ${COUNT} -eq 1 ]]; then
1313
else
1414
echo "There are ${COUNT} active terraform resources on '$1'."
1515
fi
16-
terraform output public_ip_map
16+
terraform output controller_ip_map
1717
exit 0

terraform/aws/output.tf

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
# All generic output goes here
22

3-
# Each provider's output.tf needs to define a public_ip_map. This
3+
# Each provider's output.tf needs to define a controller_ip_map. This
44
# map is used to build the Ansible controller's ssh configuration.
5-
# Each map entry contains the node's hostname and public IP address.
6-
output "public_ip_map" {
7-
description = "The public IP addresses assigned to each instance"
5+
# Each map entry contains the node's hostname and public/private IP
6+
# address.
7+
output "controller_ip_map" {
8+
description = "The IP addresses assigned to each instance"
89
value = zipmap(var.kdevops_nodes[*], aws_eip.kdevops_eip[*].public_ip)
910
}
1011

terraform/azure/output.tf

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
# Each provider's output.tf needs to define a public_ip_map. This
1+
# Each provider's output.tf needs to define a controller_ip_map. This
22
# map is used to build the Ansible controller's ssh configuration.
3-
# Each map entry contains the node's hostname and public IP address.
4-
output "public_ip_map" {
5-
description = "The public IP addresses assigned to each instance"
3+
# Each map entry contains the node's hostname and public/private IP
4+
# address.
5+
output "controller_ip_map" {
6+
description = "The IP addresses assigned to each instance"
67
value = zipmap(var.kdevops_nodes[*], azurerm_public_ip.kdevops_publicip[*].ip_address)
78
}

terraform/gce/output.tf

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
# All generic output goes here
22

3-
# Each provider's output.tf needs to define a public_ip_map. This
3+
# Each provider's output.tf needs to define a controller_ip_map. This
44
# map is used to build the Ansible controller's ssh configuration.
5-
# Each map entry contains the node's hostname and public IP address.
6-
output "public_ip_map" {
7-
description = "The public IP addresses assigned to each instance"
5+
# Each map entry contains the node's hostname and public/private IP
6+
# address.
7+
output "controller_ip_map" {
8+
description = "The IP addresses assigned to each instance"
89
value = zipmap(var.kdevops_nodes[*],
910
google_compute_instance.kdevops_instance[*].network_interface[0].access_config[0].nat_ip)
1011
}

terraform/oci/output.tf

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
# All generic output goes here
22

3-
# Each provider's output.tf needs to define a public_ip_map. This
3+
# Each provider's output.tf needs to define a controller_ip_map. This
44
# map is used to build the Ansible controller's ssh configuration.
5-
# Each map entry contains the node's hostname and public IP address.
6-
output "public_ip_map" {
7-
description = "The public IP addresses assigned to each instance"
8-
value = zipmap(var.kdevops_nodes[*], oci_core_instance.kdevops_instance.*.public_ip)
5+
# Each map entry contains the node's hostname and public/private IP
6+
# address.
7+
output "controller_ip_map" {
8+
description = "The IP addresses assigned to each instance"
9+
value = zipmap(var.kdevops_nodes[*],
10+
var.oci_assign_public_ip ?
11+
oci_core_instance.kdevops_instance.*.public_ip :
12+
oci_core_instance.kdevops_instance.*.private_ip)
913
}

terraform/openstack/output.tf

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ output "kdevops_hosts_and_ipv4" {
1818
value = data.null_data_source.group_hostnames_and_ips.*.outputs
1919
}
2020

21-
# Each provider's output.tf needs to define a public_ip_map. This
21+
# Each provider's output.tf needs to define a controller_ip_map. This
2222
# map is used to build the Ansible controller's ssh configuration.
23-
# Each map entry contains the node's hostname and public IP address.
24-
output "public_ip_map" {
25-
description = "The public IP addresses assigned to each instance"
23+
# Each map entry contains the node's hostname and public/private IP
24+
# address.
25+
output "controller_ip_map" {
26+
description = "The IP addresses assigned to each instance"
2627
value = zipmap(var.kdevops_nodes[*], openstack_compute_instance_v2.kdevops_instances[*].access_ip_v4)
2728
}

0 commit comments

Comments
 (0)