Skip to content

Commit 5b06cb2

Browse files
committed
*: remove cluster_name from terraform config
All the resources now use `cluster_id` as the prefix and all the DNS records are created under `cluster_domain`. Therefore there is no need for `cluster_name` in terraform configuration. This also keep the calculation for the `clsuter_domain` in single location ie Go code outside of terraform.
1 parent 2432ce4 commit 5b06cb2

File tree

5 files changed

+20
-28
lines changed

5 files changed

+20
-28
lines changed

data/data/config.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ This applies only to cloud platforms.
3434
EOF
3535
}
3636

37-
variable "cluster_name" {
37+
variable "cluster_domain" {
3838
type = "string"
3939

4040
description = <<EOF
41-
The name of the cluster.
42-
If used in a cloud-environment, this will be prepended to `base_domain` resulting in the URL to the OpenShift console.
41+
The domain of the cluster.
42+
All the records for the cluster are created under this domain.
4343
4444
Note: This field MUST be set manually prior to creating the cluster.
4545
EOF

data/data/libvirt/main.tf

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
locals {
2-
cluster_domain = "${var.cluster_name}.${var.base_domain}"
3-
}
4-
51
provider "libvirt" {
62
uri = "${var.libvirt_uri}"
73
}
@@ -40,7 +36,7 @@ resource "libvirt_network" "net" {
4036
mode = "nat"
4137
bridge = "${var.libvirt_network_if}"
4238

43-
domain = "${local.cluster_domain}"
39+
domain = "${var.cluster_domain}"
4440

4541
addresses = [
4642
"${var.machine_cidr}",
@@ -96,27 +92,27 @@ resource "libvirt_domain" "master" {
9692
data "libvirt_network_dns_host_template" "bootstrap" {
9793
count = "${var.bootstrap_dns ? 1 : 0}"
9894
ip = "${var.libvirt_bootstrap_ip}"
99-
hostname = "api.${local.cluster_domain}"
95+
hostname = "api.${var.cluster_domain}"
10096
}
10197

10298
data "libvirt_network_dns_host_template" "masters" {
10399
count = "${var.master_count}"
104100
ip = "${var.libvirt_master_ips[count.index]}"
105-
hostname = "api.${local.cluster_domain}"
101+
hostname = "api.${var.cluster_domain}"
106102
}
107103

108104
data "libvirt_network_dns_host_template" "etcds" {
109105
count = "${var.master_count}"
110106
ip = "${var.libvirt_master_ips[count.index]}"
111-
hostname = "etcd-${count.index}.${local.cluster_domain}"
107+
hostname = "etcd-${count.index}.${var.cluster_domain}"
112108
}
113109

114110
data "libvirt_network_dns_srv_template" "etcd_cluster" {
115111
count = "${var.master_count}"
116112
service = "etcd-server-ssl"
117113
protocol = "tcp"
118-
domain = "${local.cluster_domain}"
114+
domain = "${var.cluster_domain}"
119115
port = 2380
120116
weight = 10
121-
target = "etcd-${count.index}.${local.cluster_domain}"
117+
target = "etcd-${count.index}.${var.cluster_domain}"
122118
}

data/data/openstack/main.tf

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
locals {
2-
cluster_domain = "${var.cluster_name}.${var.base_domain}"
3-
}
4-
51
provider "openstack" {
62
auth_url = "${var.openstack_credentials_auth_url}"
73
cert = "${var.openstack_credentials_cert}"
@@ -32,7 +28,7 @@ module "service" {
3228

3329
swift_container = "${openstack_objectstorage_container_v1.container.name}"
3430
cluster_id = "${var.cluster_id}"
35-
cluster_domain = "${var.base_domain}"
31+
cluster_domain = "${var.cluster_domain}"
3632
image_name = "${var.openstack_base_image}"
3733
flavor_name = "${var.openstack_master_flavor_name}"
3834
ignition = "${var.ignition_bootstrap}"
@@ -81,7 +77,7 @@ module "topology" {
8177
}
8278

8379
resource "openstack_objectstorage_container_v1" "container" {
84-
name = "${local.cluster_domain}"
80+
name = "${var.cluster_domain}"
8581

8682
# "kubernetes.io/cluster/${var.cluster_id}" = "owned"
8783
metadata = "${merge(map(

pkg/asset/cluster/tfvars.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ func (t *TerraformVariables) Generate(parents asset.Parents) error {
7979
masters := mastersAsset.Machines()
8080
masterCount := len(masters)
8181
data, err := tfvars.TFVars(
82-
clusterID.UUID,
83-
installConfig.Config.ObjectMeta.Name,
82+
clusterID.InfraID,
83+
installConfig.Config.ClusterDomain(),
8484
installConfig.Config.BaseDomain,
8585
&installConfig.Config.Networking.MachineCIDR.IPNet,
8686
bootstrapIgn,

pkg/tfvars/tfvars.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,21 @@ import (
77
)
88

99
type config struct {
10-
ClusterID string `json:"cluster_id,omitempty"`
11-
Name string `json:"cluster_name,omitempty"`
12-
BaseDomain string `json:"base_domain,omitempty"`
13-
MachineCIDR string `json:"machine_cidr"`
14-
Masters int `json:"master_count,omitempty"`
10+
ClusterID string `json:"cluster_id,omitempty"`
11+
ClusterDomain string `json:"cluster_domain,omitempty"`
12+
BaseDomain string `json:"base_domain,omitempty"`
13+
MachineCIDR string `json:"machine_cidr"`
14+
Masters int `json:"master_count,omitempty"`
1515

1616
IgnitionBootstrap string `json:"ignition_bootstrap,omitempty"`
1717
IgnitionMaster string `json:"ignition_master,omitempty"`
1818
}
1919

2020
// TFVars generates terraform.tfvar JSON for launching the cluster.
21-
func TFVars(clusterID string, clusterName string, baseDomain string, machineCIDR *net.IPNet, bootstrapIgn string, masterIgn string, masterCount int) ([]byte, error) {
21+
func TFVars(clusterID string, clusterDomain string, baseDomain string, machineCIDR *net.IPNet, bootstrapIgn string, masterIgn string, masterCount int) ([]byte, error) {
2222
config := &config{
2323
ClusterID: clusterID,
24-
Name: clusterName,
24+
ClusterDomain: clusterDomain,
2525
BaseDomain: baseDomain,
2626
MachineCIDR: machineCIDR.String(),
2727
Masters: masterCount,

0 commit comments

Comments
 (0)