mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-15 19:22:46 -06:00
015e96d0dd
* Initial checkin for PR request * Added an argument to provider to allow control over whether or not TLS Certs will skip verification. Controllable via provider or env variable being set * Initial check-in to use refactored module * Checkin of very MVP for creating/deleting host test which works and validates basic host creation and deletion * Check in with support for creating hosts with variables working * Checking in work to date * Remove code that causes travis CI to fail while I debug * Adjust create to accept multivale * Back on track. Working basic tests. go-icinga2-api needs more test too * Squashing * Back on track. Working basic tests. go-icinga2-api needs more test too * Check in refactored hostgroup support * Check in refactored check_command, hosts, and hsotgroup with a few test * Checking in service code * Add in dependency for icinga2 provider * Add documentation. Refactor, fix and extend based on feedback from Hashicorp * Added checking and validation around invalid URL and unavailable server
99 lines
2.0 KiB
Go
99 lines
2.0 KiB
Go
package icinga2
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/hashicorp/terraform/helper/schema"
|
|
"github.com/lrsmith/go-icinga2-api/iapi"
|
|
)
|
|
|
|
func resourceIcinga2Hostgroup() *schema.Resource {
|
|
|
|
return &schema.Resource{
|
|
Create: resourceIcinga2HostgroupCreate,
|
|
Read: resourceIcinga2HostgroupRead,
|
|
Delete: resourceIcinga2HostgroupDelete,
|
|
Schema: map[string]*schema.Schema{
|
|
"name": &schema.Schema{
|
|
Type: schema.TypeString,
|
|
Required: true,
|
|
Description: "name",
|
|
ForceNew: true,
|
|
},
|
|
"display_name": &schema.Schema{
|
|
Type: schema.TypeString,
|
|
Required: true,
|
|
Description: "Display name of Host Group",
|
|
ForceNew: true,
|
|
},
|
|
},
|
|
}
|
|
}
|
|
|
|
func resourceIcinga2HostgroupCreate(d *schema.ResourceData, meta interface{}) error {
|
|
|
|
client := meta.(*iapi.Server)
|
|
|
|
name := d.Get("name").(string)
|
|
displayName := d.Get("display_name").(string)
|
|
|
|
hostgroups, err := client.CreateHostgroup(name, displayName)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
found := false
|
|
for _, hostgroup := range hostgroups {
|
|
if hostgroup.Name == name {
|
|
d.SetId(name)
|
|
found = true
|
|
}
|
|
}
|
|
|
|
if !found {
|
|
return fmt.Errorf("Failed to Create Hostgroup %s : %s", name, err)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func resourceIcinga2HostgroupRead(d *schema.ResourceData, meta interface{}) error {
|
|
|
|
client := meta.(*iapi.Server)
|
|
name := d.Get("name").(string)
|
|
|
|
hostgroups, err := client.GetHostgroup(name)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
found := false
|
|
for _, hostgroup := range hostgroups {
|
|
if hostgroup.Name == name {
|
|
d.SetId(name)
|
|
d.Set("display_name", hostgroup.Attrs.DisplayName)
|
|
found = true
|
|
}
|
|
}
|
|
|
|
if !found {
|
|
return fmt.Errorf("Failed to Read Hostgroup %s : %s", name, err)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func resourceIcinga2HostgroupDelete(d *schema.ResourceData, meta interface{}) error {
|
|
|
|
client := meta.(*iapi.Server)
|
|
name := d.Get("name").(string)
|
|
|
|
err := client.DeleteHostgroup(name)
|
|
if err != nil {
|
|
return fmt.Errorf("Failed to Delete Hostgroup %s : %s", name, err)
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|