Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
systemsmanagement:sumaform
terraform-provider-libvirt
combustion.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File combustion.patch of Package terraform-provider-libvirt
From ed4ee81dfe1b6ed4075a84e42afddc87c53d8d2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Bosdonnat?= <cbosdonnat@suse.com> Date: Mon, 12 Feb 2024 11:18:00 +0100 Subject: [PATCH] Add Combustion resource to use instead of the ignition one --- libvirt/coreos_ignition_def.go | 7 +- libvirt/resource_libvirt_combustion.go | 91 +++++++++++++++++++++ libvirt/resource_libvirt_combustion_test.go | 73 +++++++++++++++++ 3 files changed, 168 insertions(+), 3 deletions(-) create mode 100644 libvirt/resource_libvirt_combustion.go create mode 100644 libvirt/resource_libvirt_combustion_test.go Index: terraform-provider-libvirt-0.6.3+git.1604843676.67f4f2aa/libvirt/coreos_ignition_def.go =================================================================== --- terraform-provider-libvirt-0.6.3+git.1604843676.67f4f2aa.orig/libvirt/coreos_ignition_def.go +++ terraform-provider-libvirt-0.6.3+git.1604843676.67f4f2aa/libvirt/coreos_ignition_def.go @@ -15,9 +15,10 @@ import ( ) type defIgnition struct { - Name string - PoolName string - Content string + Name string + PoolName string + Content string + Combustion bool } // Creates a new cloudinit with the defaults @@ -129,7 +130,7 @@ func (ign *defIgnition) createFile() (st file = true if _, err := os.Stat(ign.Content); err != nil { var js map[string]interface{} - if errConf := json.Unmarshal([]byte(ign.Content), &js); errConf != nil { + if errConf := json.Unmarshal([]byte(ign.Content), &js); !ign.Combustion && errConf != nil { return "", fmt.Errorf("coreos_ignition 'content' is neither a file "+ "nor a valid json object %s", ign.Content) } Index: terraform-provider-libvirt-0.6.3+git.1604843676.67f4f2aa/libvirt/resource_libvirt_combustion.go =================================================================== --- /dev/null +++ terraform-provider-libvirt-0.6.3+git.1604843676.67f4f2aa/libvirt/resource_libvirt_combustion.go @@ -0,0 +1,90 @@ +package libvirt + +import ( + "fmt" + "log" + + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" +) + +func resourceCombustion() *schema.Resource { + return &schema.Resource{ + Create: resourceCombustionCreate, + Read: resourceCombustionRead, + Delete: resourceCombustionDelete, + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + "pool": { + Type: schema.TypeString, + Optional: true, + Default: "default", + ForceNew: true, + }, + "content": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + }, + } +} + +func resourceCombustionCreate(d *schema.ResourceData, meta interface{}) error { + log.Printf("[DEBUG] creating combustion file") + client := meta.(*Client) + if client.libvirt == nil { + return fmt.Errorf(LibVirtConIsNil) + } + + combustion := newIgnitionDef() + + combustion.Name = d.Get("name").(string) + combustion.PoolName = d.Get("pool").(string) + combustion.Content = d.Get("content").(string) + combustion.Combustion = true + + log.Printf("[INFO] combustion: %+v", combustion) + + key, err := combustion.CreateAndUpload(client) + if err != nil { + return err + } + d.SetId(key) + + return resourceIgnitionRead(d, meta) +} + +func resourceCombustionRead(d *schema.ResourceData, meta interface{}) error { + virConn := meta.(*Client).libvirt + if virConn == nil { + return fmt.Errorf(LibVirtConIsNil) + } + + combustion, err := newIgnitionDefFromRemoteVol(virConn, d.Id()) + d.Set("pool", combustion.PoolName) + d.Set("name", combustion.Name) + + if err != nil { + return fmt.Errorf("error while retrieving remote volume: %s", err) + } + + return nil +} + +func resourceCombustionDelete(d *schema.ResourceData, meta interface{}) error { + client := meta.(*Client) + if client.libvirt == nil { + return fmt.Errorf(LibVirtConIsNil) + } + + key, err := getIgnitionVolumeKeyFromTerraformID(d.Id()) + if err != nil { + return err + } + + return volumeDelete(client, key) +} Index: terraform-provider-libvirt-0.6.3+git.1604843676.67f4f2aa/libvirt/resource_libvirt_combustion_test.go =================================================================== --- /dev/null +++ terraform-provider-libvirt-0.6.3+git.1604843676.67f4f2aa/libvirt/resource_libvirt_combustion_test.go @@ -0,0 +1,73 @@ +package libvirt + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/terraform" + libvirt "github.com/libvirt/libvirt-go" +) + +func TestAccLibvirtCombustion_Basic(t *testing.T) { + var volume libvirt.StorageVol + randomCombustionName := acctest.RandStringFromCharSet(10, acctest.CharSetAlpha) + randomPoolName := acctest.RandStringFromCharSet(10, acctest.CharSetAlpha) + randomPoolPath := "/tmp/terraform-provider-libvirt-pool-" + randomPoolName + var config = fmt.Sprintf(` + resource "libvirt_pool" "%s" { + name = "%s" + type = "dir" + path = "%s" + } + + resource "libvirt_combustion" "combustion" { + name = "%s" + content = "#!/bin/bash +# combustion: network +echo 'root:$6$3aQC9rrDLHiTf1yR$NoKe9tko0kFIpu0rQ2y/FOO' | chpasswd -e +" + pool = "${libvirt_pool.%s.name}" + } + `, randomPoolName, randomPoolName, randomPoolPath, randomCombustionName, randomPoolName) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckLibvirtIgnitionDestroy, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + testAccCheckIgnitionVolumeExists("libvirt_combustion.combustion", &volume), + resource.TestCheckResourceAttr( + "libvirt_combustion.combustion", "name", randomCombustionName), + resource.TestCheckResourceAttr( + "libvirt_combustion.combustion", "pool", randomPoolName), + ), + }, + }, + }) +} + +func testAccCheckLibvirtCombustionDestroy(s *terraform.State) error { + virtConn := testAccProvider.Meta().(*Client).libvirt + for _, rs := range s.RootModule().Resources { + if rs.Type != "libvirt_combustion" { + continue + } + // Try to find the Ignition Volume + ignKey, errKey := getIgnitionVolumeKeyFromTerraformID(rs.Primary.ID) + if errKey != nil { + return errKey + } + _, err := virtConn.LookupStorageVolByKey(ignKey) + if err == nil { + return fmt.Errorf( + "Error waiting for CombustionVolume (%s) to be destroyed: %w", + ignKey, err) + } + } + return nil +} Index: terraform-provider-libvirt-0.6.3+git.1604843676.67f4f2aa/libvirt/provider.go =================================================================== --- terraform-provider-libvirt-0.6.3+git.1604843676.67f4f2aa.orig/libvirt/provider.go +++ terraform-provider-libvirt-0.6.3+git.1604843676.67f4f2aa/libvirt/provider.go @@ -26,6 +26,7 @@ func Provider() terraform.ResourceProvid "libvirt_pool": resourceLibvirtPool(), "libvirt_cloudinit_disk": resourceCloudInitDisk(), "libvirt_ignition": resourceIgnition(), + "libvirt_combustion": resourceCombustion(), }, DataSourcesMap: map[string]*schema.Resource{
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor