Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bootstrap #78

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

FrankYang0529
Copy link
Member

@FrankYang0529 FrankYang0529 commented Mar 30, 2023

issue: harvester/harvester#1797

Test plan

  1. Create a new Harvester cluster and don't login.
  2. Build terraform-harvester-provider.
CGO_ENABLED=0 go build -mod=vendor -o bin/terraform-provider-harvester .
mkdir -p ~/.terraform.d/plugins/registry.terraform.io/harvester/harvester/0.0.0-master/linux_amd64
cp bin/terraform-provider-harvester ~/.terraform.d/plugins/registry.terraform.io/harvester/harvester/0.0.0-master/linux_amd64/terraform-provider-harvester_v0.0.0-master
  1. Create a temporary folder and put the following content in main.tf (remember to change api_url).
terraform {
  required_providers {
    harvester = {
      source = "harvester/harvester"
      version = "0.0.0-master"
    }
  }
}

provider "harvester" {
  alias = "bootstrap"

  api_url    = "https://192.168.3.131"
  bootstrap = true
}

resource "harvester_bootstrap" "admin" {
  provider = harvester.bootstrap

  initial_password = "admin"
  password = "passwdpasswd"
}

provider "harvester" {
  alias = "admin"

  api_url    = "https://192.168.3.131"
  kubeconfig = harvester_bootstrap.admin.kubeconfig
}

resource "harvester_volume" "test-disk" {
  provider = harvester.admin

  name      = "test-disk"
  namespace = "default"

  size = "1Gi"
}

resource "harvester_image" "ubuntu20" {
  provider = harvester.admin

  name      = "ubuntu20"
  namespace = "harvester-public"

  display_name = "ubuntu-20.04-server-cloudimg-amd64.img"
  source_type  = "download"
  url          = "http://cloud-images.ubuntu.com/releases/focal/release/ubuntu-20.04-server-cloudimg-amd64.img"
}

resource "harvester_virtualmachine" "ubuntu20" {
  provider = harvester.admin

  name                 = "ubuntu20"
  namespace            = "default"
  restart_after_update = true

  description = "test ubuntu20 raw image"
  tags = {
    ssh-user = "ubuntu"
  }

  cpu    = 2
  memory = "2Gi"

  efi         = true
  secure_boot = true

  run_strategy    = "RerunOnFailure"
  hostname        = "ubuntu20"
  reserved_memory = "100Mi"
  machine_type    = "q35"

  network_interface {
    name           = "nic-1"
    wait_for_lease = true
  }

  disk {
    name       = "rootdisk"
    type       = "disk"
    size       = "10Gi"
    bus        = "virtio"
    boot_order = 1

    image       = harvester_image.ubuntu20.id
    auto_delete = true
  }

  cloudinit {
    user_data    = <<-EOF
      #cloud-config
      password: 123456
      chpasswd:
        expire: false
      ssh_pwauth: true
      package_update: true
      packages:
        - qemu-guest-agent
      runcmd:
        - - systemctl
          - enable
          - '--now'
          - qemu-guest-agent
      EOF
    network_data = ""
  }
}
  1. Run terraform init and terraform apply. Terraform should update password to passwdpasswd and create a new image and vm.

@FrankYang0529 FrankYang0529 force-pushed the add-bootstrap branch 2 times, most recently from 0a834b1 to 5cc3dda Compare March 30, 2023 04:00
Copy link
Contributor

@futuretea futuretea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refer to harvester/harvester#3673, It seems like we won't disable MCM in 1.2.0. So users can use terraform-provider-rancher2 to do this.

harvester/harvester#1797 (comment)

@FrankYang0529
Copy link
Member Author

Refer to harvester/harvester#3673, It seems like we won't disable MCM in 1.2.0. So users can use terraform-provider-rancher2 to do this.

harvester/harvester#1797 (comment)

Hi @futuretea, yes, users can use rancher2 directly if they enable the mcm feature. However, the mcm feature is an option for users. If they don't enable it, we still need to give users a choice to bootstrap with terraform harvester provider.

@futuretea futuretea self-requested a review April 25, 2023 03:31
@belgaied2
Copy link

This PR is interesting because I am encountering issues where it is not possible to use the Harvester provider where the KUBECONFIG file does not yet exist. I get the following error during terraform plan phase:
Error: the server could not find the requested resource (get settings.harvesterhci.io server-version)

Is this solved somewhere? Can the plan phase be successful without an existing kubeconfig file ?

@FrankYang0529 FrankYang0529 force-pushed the add-bootstrap branch 4 times, most recently from 951a694 to cfce8e0 Compare August 12, 2024 03:37
@FrankYang0529
Copy link
Member Author

Hi @belgaied2, thanks for the testing. I updated the code. Now, it can handle terraform plan without an existing kubeconfig file. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants