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

fix: get storage class name from vmimage status #94

Merged
merged 1 commit into from
Apr 18, 2024

Conversation

FrankYang0529
Copy link
Member

issue: harvester/harvester#5165

  1. 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-dev/linux_amd64
cp bin/terraform-provider-harvester ~/.terraform.d/plugins/registry.terraform.io/harvester/harvester/0.0.0-dev/linux_amd64/terraform-provider-harvester_v0.0.0-dev
  1. Create a temporary folder and put the following content in versions.tf.
terraform {
  required_providers {
    harvester = {
      source  = "harvester/harvester"
      /* version = "0.6.4" */
      version = "0.0.0-dev"
    }
  }
}

provider "harvester" {
  kubeconfig = "~/.kube/config"
}
  1. Put the following content in main.tf in the temporary folder.
resource "harvester_image" "ubuntu20" {
   name      = "ubuntu-focal"
   namespace = "default"

   display_name = "ubuntu-focal"
   source_type  = "download"
   url          = "https://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-amd64.img"
 }

resource "harvester_cloudinit_secret" "cloud-config-ubuntu20" {
  name      = "cloud-config-ubuntu20"
  namespace = "default"

  user_data    = <<-EOF
    #cloud-config
    password: test
    chpasswd:
      expire: false
    ssh_pwauth: true
    package_update: true
    packages:
      - qemu-guest-agent
    runcmd:
      - - systemctl
        - enable
        - '--now'
        - qemu-guest-agent
    EOF
  network_data = ""
}

resource "harvester_virtualmachine" "ubuntu20" {
  name                 = "ubuntu20"
  namespace            = "default"
  restart_after_update = true

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

  cpu    = 1
  memory = "2Gi"

  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_secret_name    = harvester_cloudinit_secret.cloud-config-ubuntu20.name
    network_data_secret_name = harvester_cloudinit_secret.cloud-config-ubuntu20.name
  }
}
  1. Run terraform init and terraform apply without error.

Copy link
Contributor

@Yu-Jack Yu-Jack left a comment

Choose a reason for hiding this comment

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

Tested Apply complete! Resources: 3 added, 0 changed, 0 destroyed., LGTM, thanks!

Copy link
Member

@bk201 bk201 left a comment

Choose a reason for hiding this comment

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

lgtm!

@FrankYang0529 FrankYang0529 merged commit 47d1f28 into harvester:master Apr 18, 2024
2 checks passed
@FrankYang0529 FrankYang0529 deleted the HARV-5165 branch April 18, 2024 01:57
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