opentofu/builtin/providers/icinga2/resource_icinga2_hostgroup_test.go
Len Smith 015e96d0dd Initial check in for Icinga2 Provider/Resource (#8306)
* 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
2016-12-12 15:28:26 +00:00

56 lines
1.4 KiB
Go

package icinga2
import (
"fmt"
"testing"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
"github.com/lrsmith/go-icinga2-api/iapi"
)
func TestAccCreateBasicHostGroup(t *testing.T) {
var testAccCreateBasicHostGroup = fmt.Sprintf(`
resource "icinga2_hostgroup" "tf-hg-1" {
name = "terraform-hostgroup-1"
display_name = "Terraform Test HostGroup"
}`)
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccCreateBasicHostGroup,
Check: resource.ComposeTestCheckFunc(
testAccCheckHostgroupExists("icinga2_hostgroup.tf-hg-1"),
testAccCheckResourceState("icinga2_hostgroup.tf-hg-1", "name", "terraform-hostgroup-1"),
testAccCheckResourceState("icinga2_hostgroup.tf-hg-1", "display_name", "Terraform Test HostGroup"),
),
},
},
})
}
func testAccCheckHostgroupExists(rn string) resource.TestCheckFunc {
return func(s *terraform.State) error {
resource, ok := s.RootModule().Resources[rn]
if !ok {
return fmt.Errorf("Hostgroup resource not found: %s", rn)
}
if resource.Primary.ID == "" {
return fmt.Errorf("Hostgroup resource id not set")
}
client := testAccProvider.Meta().(*iapi.Server)
_, err := client.GetHostgroup(resource.Primary.ID)
if err != nil {
return fmt.Errorf("Error getting getting hostgroup: %s", err)
}
return nil
}
}