Skip to content

Commit

Permalink
*: remove cluster_name from terraform config
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
abhinavdahiya committed Feb 22, 2019
1 parent 2432ce4 commit 5b06cb2
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 28 deletions.
6 changes: 3 additions & 3 deletions data/data/config.tf
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ This applies only to cloud platforms.
EOF
}

variable "cluster_name" {
variable "cluster_domain" {
type = "string"

description = <<EOF
The name of the cluster.
If used in a cloud-environment, this will be prepended to `base_domain` resulting in the URL to the OpenShift console.
The domain of the cluster.
All the records for the cluster are created under this domain.
Note: This field MUST be set manually prior to creating the cluster.
EOF
Expand Down
16 changes: 6 additions & 10 deletions data/data/libvirt/main.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
locals {
cluster_domain = "${var.cluster_name}.${var.base_domain}"
}

provider "libvirt" {
uri = "${var.libvirt_uri}"
}
Expand Down Expand Up @@ -40,7 +36,7 @@ resource "libvirt_network" "net" {
mode = "nat"
bridge = "${var.libvirt_network_if}"

domain = "${local.cluster_domain}"
domain = "${var.cluster_domain}"

addresses = [
"${var.machine_cidr}",
Expand Down Expand Up @@ -96,27 +92,27 @@ resource "libvirt_domain" "master" {
data "libvirt_network_dns_host_template" "bootstrap" {
count = "${var.bootstrap_dns ? 1 : 0}"
ip = "${var.libvirt_bootstrap_ip}"
hostname = "api.${local.cluster_domain}"
hostname = "api.${var.cluster_domain}"
}

data "libvirt_network_dns_host_template" "masters" {
count = "${var.master_count}"
ip = "${var.libvirt_master_ips[count.index]}"
hostname = "api.${local.cluster_domain}"
hostname = "api.${var.cluster_domain}"
}

data "libvirt_network_dns_host_template" "etcds" {
count = "${var.master_count}"
ip = "${var.libvirt_master_ips[count.index]}"
hostname = "etcd-${count.index}.${local.cluster_domain}"
hostname = "etcd-${count.index}.${var.cluster_domain}"
}

data "libvirt_network_dns_srv_template" "etcd_cluster" {
count = "${var.master_count}"
service = "etcd-server-ssl"
protocol = "tcp"
domain = "${local.cluster_domain}"
domain = "${var.cluster_domain}"
port = 2380
weight = 10
target = "etcd-${count.index}.${local.cluster_domain}"
target = "etcd-${count.index}.${var.cluster_domain}"
}
8 changes: 2 additions & 6 deletions data/data/openstack/main.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
locals {
cluster_domain = "${var.cluster_name}.${var.base_domain}"
}

provider "openstack" {
auth_url = "${var.openstack_credentials_auth_url}"
cert = "${var.openstack_credentials_cert}"
Expand Down Expand Up @@ -32,7 +28,7 @@ module "service" {

swift_container = "${openstack_objectstorage_container_v1.container.name}"
cluster_id = "${var.cluster_id}"
cluster_domain = "${var.base_domain}"
cluster_domain = "${var.cluster_domain}"
image_name = "${var.openstack_base_image}"
flavor_name = "${var.openstack_master_flavor_name}"
ignition = "${var.ignition_bootstrap}"
Expand Down Expand Up @@ -81,7 +77,7 @@ module "topology" {
}

resource "openstack_objectstorage_container_v1" "container" {
name = "${local.cluster_domain}"
name = "${var.cluster_domain}"

# "kubernetes.io/cluster/${var.cluster_id}" = "owned"
metadata = "${merge(map(
Expand Down
4 changes: 2 additions & 2 deletions pkg/asset/cluster/tfvars.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ func (t *TerraformVariables) Generate(parents asset.Parents) error {
masters := mastersAsset.Machines()
masterCount := len(masters)
data, err := tfvars.TFVars(
clusterID.UUID,
installConfig.Config.ObjectMeta.Name,
clusterID.InfraID,
installConfig.Config.ClusterDomain(),
installConfig.Config.BaseDomain,
&installConfig.Config.Networking.MachineCIDR.IPNet,
bootstrapIgn,
Expand Down
14 changes: 7 additions & 7 deletions pkg/tfvars/tfvars.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@ import (
)

type config struct {
ClusterID string `json:"cluster_id,omitempty"`
Name string `json:"cluster_name,omitempty"`
BaseDomain string `json:"base_domain,omitempty"`
MachineCIDR string `json:"machine_cidr"`
Masters int `json:"master_count,omitempty"`
ClusterID string `json:"cluster_id,omitempty"`
ClusterDomain string `json:"cluster_domain,omitempty"`
BaseDomain string `json:"base_domain,omitempty"`
MachineCIDR string `json:"machine_cidr"`
Masters int `json:"master_count,omitempty"`

IgnitionBootstrap string `json:"ignition_bootstrap,omitempty"`
IgnitionMaster string `json:"ignition_master,omitempty"`
}

// TFVars generates terraform.tfvar JSON for launching the cluster.
func TFVars(clusterID string, clusterName string, baseDomain string, machineCIDR *net.IPNet, bootstrapIgn string, masterIgn string, masterCount int) ([]byte, error) {
func TFVars(clusterID string, clusterDomain string, baseDomain string, machineCIDR *net.IPNet, bootstrapIgn string, masterIgn string, masterCount int) ([]byte, error) {
config := &config{
ClusterID: clusterID,
Name: clusterName,
ClusterDomain: clusterDomain,
BaseDomain: baseDomain,
MachineCIDR: machineCIDR.String(),
Masters: masterCount,
Expand Down

0 comments on commit 5b06cb2

Please sign in to comment.