Skip to content

Commit f6d46ba

Browse files
committed
feat: add iac code
1 parent 9b8f4b0 commit f6d46ba

File tree

99 files changed

+7911
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+7911
-0
lines changed

iac/README.md

Lines changed: 479 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
[bastion]
2+
${address_bastion}
3+
4+
[masters]
5+
%{ for master in master_nodes ~}
6+
${master.access_ip_v4}
7+
%{endfor ~}
8+
9+
[workers]
10+
%{ for worker in worker_nodes ~}
11+
${worker.access_ip_v4}
12+
%{endfor ~}
13+
14+
%{if address_bastion == ""~}
15+
[masters:vars]
16+
ansible_ssh_common_args='-o StrictHostKeyChecking=no -o IdentityFile=./id_rsa -o UserKnownHostsFile=/dev/null'
17+
18+
[workers:vars]
19+
ansible_ssh_common_args='-o StrictHostKeyChecking=no -o IdentityFile=./id_rsa -o UserKnownHostsFile=/dev/null'
20+
%{endif~}
21+
22+
%{if address_bastion != ""~}
23+
[masters:vars]
24+
ansible_ssh_common_args='-o StrictHostKeyChecking=no -o IdentityFile=./id_rsa -o UserKnownHostsFile=/dev/null -o ProxyCommand="ssh -o IdentityFile=./id_rsa -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -W %h:%p -q ${ssh_user}@${address_bastion}"'
25+
26+
[workers:vars]
27+
ansible_ssh_common_args='-o StrictHostKeyChecking=no -o IdentityFile=./id_rsa -o UserKnownHostsFile=/dev/null -o ProxyCommand="ssh -o IdentityFile=./id_rsa -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -W %h:%p -q ${ssh_user}@${address_bastion}"'
28+
%{endif~}
29+
30+
31+
32+
33+
[all:vars]
34+
ansible_user="${ssh_user}"
35+
ansible_python_interpreter=/usr/bin/python3
36+
ansible_ssh_private_key_file=./id_rsa
37+
ansible_ssh_extra_args='-o StrictHostKeyChecking=no'
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
resource "local_file" "ansible_inventory" {
3+
content = templatefile("${path.module}/inventory.tpl",
4+
{
5+
address_bastion = var.address_bastion
6+
worker_nodes = var.worker_nodes
7+
master_nodes = var.master_nodes
8+
ssh_user = var.ssh_user
9+
})
10+
filename = "infra-inventory"
11+
12+
depends_on = [ var.master_nodes, var.worker_nodes ]
13+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
variable "address_bastion" {
2+
type = string
3+
default = ""
4+
}
5+
6+
variable "master_nodes" {
7+
type = list(object({
8+
id = string
9+
name = string
10+
access_ip_v4 = string
11+
}))
12+
}
13+
14+
variable "ssh_user" {
15+
type = string
16+
default = "ubuntu"
17+
}
18+
19+
variable "worker_nodes" {
20+
type = list(object({
21+
id = string
22+
name = string
23+
access_ip_v4 = string
24+
}))
25+
}
26+
27+

iac/cloud/openstack/lib/ca/main.tf

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
resource "local_file" "ca-certificate" {
2+
filename = "${path.root}/ca.crt"
3+
content = var.services_ca_crt != "" ? var.services_ca_crt : tls_self_signed_cert.ca[0].cert_pem
4+
file_permission = "0644"
5+
}
6+
7+
resource "local_file" "ca-certificate-key" {
8+
filename = "${path.root}/ca.key"
9+
content = var.services_ca_key != "" ? var.services_ca_key : tls_private_key.ca[0].private_key_pem
10+
file_permission = "0600"
11+
}
12+
13+
resource "tls_private_key" "ca" {
14+
count = var.services_ca_key != "" ? 0 : 1
15+
algorithm = "RSA"
16+
}
17+
18+
resource "tls_self_signed_cert" "ca" {
19+
count = var.services_ca_crt != "" ? 0 : 1
20+
#key_algorithm = "RSA"
21+
private_key_pem = tls_private_key.ca[0].private_key_pem
22+
is_ca_certificate = true
23+
24+
subject {
25+
organization = "Rackspace Kubernetes Managed Services CA"
26+
}
27+
28+
validity_period_hours = 87600
29+
30+
allowed_uses = [
31+
"key_encipherment",
32+
"digital_signature",
33+
"server_auth",
34+
"client_auth",
35+
"cert_signing",
36+
]
37+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
output "certificate" {
2+
value = local_file.ca-certificate.content
3+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
variable "services_ca_crt" {
2+
type = string
3+
default = ""
4+
}
5+
6+
variable "services_ca_key" {
7+
type = string
8+
default = ""
9+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
3+
resource "openstack_networking_port_v2" "vrrp" {
4+
name = "${var.naming_prefix}vrrp"
5+
network_id = var.network_id
6+
security_group_ids = var.security_group_ids
7+
admin_state_up = "true"
8+
fixed_ip {
9+
ip_address = var.vrrp_ip
10+
subnet_id = var.subnet_id
11+
}
12+
}
13+
14+
resource "openstack_compute_floatingip_v2" "k8s_api_ip" {
15+
count = var.floatingip_pool == "" ? 0 : 1
16+
pool = var.floatingip_pool
17+
18+
}
19+
20+
resource "openstack_networking_floatingip_associate_v2" "fip_1" {
21+
count = var.floatingip_pool == "" ? 0 : 1
22+
floating_ip = openstack_compute_floatingip_v2.k8s_api_ip[0].address
23+
port_id = openstack_networking_port_v2.vrrp.id
24+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
output "ip" {
2+
value = var.floatingip_pool == "" ? var.vrrp_ip : openstack_compute_floatingip_v2.k8s_api_ip[0].address
3+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
variable "floatingip_pool" {
2+
type = string
3+
default = ""
4+
}
5+
6+
variable "naming_prefix" {
7+
type = string
8+
}
9+
10+
variable "network_id" {
11+
type = string
12+
}
13+
variable "vrrp_ip" {
14+
type = string
15+
}
16+
17+
variable "subnet_id" {
18+
type = string
19+
}
20+
21+
variable "use_octavia" {
22+
type = bool
23+
}
24+
variable "security_group_ids" {
25+
type = list(string)
26+
default = []
27+
}
28+
29+
variable "vlan_id" {
30+
type = string
31+
default = ""
32+
}

0 commit comments

Comments
 (0)