Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions OWNERS_ALIASES
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,9 @@ aliases:
- abhinavdahiya
- dav1x
- staebler
baremetal-reviewers:
- celebdor
- markmc
- russellb
- hardys
- stbenjam
5 changes: 5 additions & 0 deletions data/data/baremetal/OWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# See the OWNERS docs: https://git.k8s.io/community/contributors/guide/owners.md
# This file just uses aliases defined in OWNERS_ALIASES.

reviewers:
- baremetal-reviewers
49 changes: 49 additions & 0 deletions data/data/baremetal/bootstrap/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Bootstrap Module

This [Terraform][] [module][] manages [libvirt][] resources only needed during cluster bootstrapping.
It uses [implicit provider inheritance][implicit-provider-inheritance] to access the [libvirt provider][libvirt-provider].

## Example

Set up a `main.tf` with:

```hcl
provider "libvirt" {
uri = "qemu:///system"
}

resource "libvirt_network" "example" {
name = "example"
mode = "none"
domain = "example.com"
addresses = ["192.168.0.0/24"]
}

resource "libvirt_volume" "example" {
name = "example"
source = "file:///path/to/example.qcow2"
}

module "bootstrap" {
source = "github.com/openshift/installer//data/data/libvirt/bootstrap"

addresses = ["192.168.0.1"]
base_volume_id = "${libvirt_volume.example.id}"
cluster_id = "my-cluster"
ignition = "{\"ignition\": {\"version\": \"2.2.0\"}}",
network_id = "${libvirt_network.example.id}"
}
```

Then run:

```console
$ terraform init
$ terraform plan
```

[libvirt]: https://libvirt.org/
[libvirt-provider]: https://github.com/dmacvicar/terraform-provider-libvirt
[implicit-provider-inheritance]: https://www.terraform.io/docs/modules/usage.html#implicit-provider-inheritance
[module]: https://www.terraform.io/docs/modules/
[Terraform]: https://www.terraform.io/
41 changes: 41 additions & 0 deletions data/data/baremetal/bootstrap/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
resource "libvirt_volume" "bootstrap" {
name = "${var.cluster_id}-bootstrap"
source = var.image
}

resource "libvirt_ignition" "bootstrap" {
name = "${var.cluster_id}-bootstrap.ign"
content = var.ignition
}

resource "libvirt_domain" "bootstrap" {
name = "${var.cluster_id}-bootstrap"

memory = "4096"

vcpu = "4"

coreos_ignition = libvirt_ignition.bootstrap.id

disk {
volume_id = libvirt_volume.bootstrap.id
}

console {
type = "pty"
target_port = 0
}

cpu = {
mode = "host-passthrough"
}

network_interface {
bridge = var.external_bridge
}

network_interface {
bridge = var.provisioning_bridge
}
}

25 changes: 25 additions & 0 deletions data/data/baremetal/bootstrap/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
variable "cluster_id" {
type = string
description = "The identifier for the cluster."
}

variable "image" {
description = "The URL of the OS disk image"
type = string
}

variable "ignition" {
type = string
description = "The content of the bootstrap ignition file."
}

variable "external_bridge" {
type = string
description = "The name of the bridge providing external access"
}

variable "provisioning_bridge" {
type = string
description = "The name of the bridge used for provisioning"
}

4 changes: 4 additions & 0 deletions data/data/baremetal/bootstrap/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

terraform {
required_version = ">= 0.12"
}
31 changes: 31 additions & 0 deletions data/data/baremetal/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
provider "libvirt" {
uri = var.libvirt_uri
}

provider "ironic" {
url = var.ironic_uri
microversion = "1.52"
}

module "bootstrap" {
source = "./bootstrap"

cluster_id = var.cluster_id
image = var.os_image
ignition = var.ignition_bootstrap
external_bridge = var.external_bridge
provisioning_bridge = var.provisioning_bridge
}

module "masters" {
source = "./masters"

ironic_uri = var.ironic_uri
master_count = var.master_count
ignition = var.ignition_master
hosts = var.hosts
properties = var.properties
root_devices = var.root_devices
driver_infos = var.driver_infos
instance_infos = var.instance_infos
}
42 changes: 42 additions & 0 deletions data/data/baremetal/masters/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
resource "ironic_node_v1" "openshift-master-host" {
count = var.master_count
name = var.hosts[count.index]["name"]
resource_class = "baremetal"

inspect = true
clean = true
available = true

ports = [
{
address = var.hosts[count.index]["port_address"]
pxe_enabled = "true"
},
]

properties = var.properties[count.index]
root_device = var.root_devices[count.index]

driver = var.hosts[count.index]["driver"]
driver_info = var.driver_infos[count.index]
}

resource "ironic_allocation_v1" "openshift-master-allocation" {
name = "master-${count.index}"
count = var.master_count
resource_class = "baremetal"

candidate_nodes = ironic_node_v1.openshift-master-host.*.id
}

resource "ironic_deployment" "openshift-master-deployment" {
count = var.master_count
node_uuid = element(
ironic_allocation_v1.openshift-master-allocation.*.node_uuid,
count.index,
)

instance_info = var.instance_infos[count.index]
user_data = var.ignition
}

39 changes: 39 additions & 0 deletions data/data/baremetal/masters/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
variable "ironic_uri" {
type = string
description = "URI for Ironic that bootstrap should wait for to be available"
}

variable "master_count" {
type = string
description = "Number of masters"
default = 3
}
variable "ignition" {
type = string
description = "The content of the master ignition file"
}

variable "hosts" {
type = list(map(string))
description = "Hardware details for hosts"
}

variable "properties" {
type = list(map(string))
description = "Properties for hosts"
}

variable "root_devices" {
type = list(map(string))
description = "Root devices for hosts"
}

variable "driver_infos" {
type = list(map(string))
description = "BMC information for hosts"
}

variable "instance_infos" {
type = list(map(string))
description = "Instance information for hosts"
}
4 changes: 4 additions & 0 deletions data/data/baremetal/masters/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

terraform {
required_version = ">= 0.12"
}
50 changes: 50 additions & 0 deletions data/data/baremetal/variables-baremetal.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
variable "ironic_uri" {
type = string
description = "ironic connection URI"
}

variable "libvirt_uri" {
type = string
description = "libvirt connection URI"
}

variable "os_image" {
type = string
description = "The URL of the OS disk image"
}

variable "external_bridge" {
type = string
description = "The name of the external bridge"
}

variable "provisioning_bridge" {
type = string
description = "The name of the provisioning bridge"
}

variable "hosts" {
type = list(map(string))
description = "Hardware details for hosts"
}

variable "properties" {
type = list(map(string))
description = "Properties for hosts"
}

variable "root_devices" {
type = list(map(string))
description = "Root devices for hosts"
}

variable "driver_infos" {
type = list(map(string))
description = "BMC information for hosts"
}

variable "instance_infos" {
type = list(map(string))
description = "Instance information for hosts"
}

4 changes: 4 additions & 0 deletions data/data/baremetal/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

terraform {
required_version = ">= 0.12"
}
24 changes: 21 additions & 3 deletions pkg/terraform/exec/plugins/Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions pkg/terraform/exec/plugins/Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,7 @@ ignored = [
[[override]]
name = "github.com/hashicorp/go-azure-helpers"
version = "0.4.1"

[[constraint]]
name = "github.com/openshift-metalkube/terraform-provider-ironic"
version = "v0.1.3"
17 changes: 17 additions & 0 deletions pkg/terraform/exec/plugins/ironic.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// +build baremetal

package plugins

import (
"github.com/hashicorp/terraform/plugin"
"github.com/openshift-metalkube/terraform-provider-ironic/ironic"
)

func init() {
exec := func() {
plugin.Serve(&plugin.ServeOpts{
ProviderFunc: ironic.Provider,
})
}
KnownPlugins["terraform-provider-ironic"] = exec
}
Loading