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
63 lines
1.9 KiB
Go
63 lines
1.9 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 TestAccCreateCheckcommand(t *testing.T) {
|
|
|
|
var testAccCreateCheckcommand = fmt.Sprintf(`
|
|
resource "icinga2_checkcommand" "checkcommand" {
|
|
name = "terraform-test-checkcommand-1"
|
|
templates = [ "plugin-check-command" ]
|
|
command = "/usr/local/bin/check_command"
|
|
arguments = {
|
|
"-I" = "$IARG$"
|
|
"-J" = "$JARG$" }
|
|
}`)
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
Providers: testAccProviders,
|
|
Steps: []resource.TestStep{
|
|
resource.TestStep{
|
|
Config: testAccCreateCheckcommand,
|
|
Check: resource.ComposeTestCheckFunc(
|
|
testAccCheckCheckcommandExists("icinga2_checkcommand.checkcommand"),
|
|
testAccCheckResourceState("icinga2_checkcommand.checkcommand", "name", "terraform-test-checkcommand-1"),
|
|
testAccCheckResourceState("icinga2_checkcommand.checkcommand", "command", "/usr/local/bin/check_command"),
|
|
testAccCheckResourceState("icinga2_checkcommand.checkcommand", "arguments.%", "2"),
|
|
testAccCheckResourceState("icinga2_checkcommand.checkcommand", "arguments.-I", "$IARG$"),
|
|
testAccCheckResourceState("icinga2_checkcommand.checkcommand", "arguments.-J", "$JARG$"),
|
|
),
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
func testAccCheckCheckcommandExists(rn string) resource.TestCheckFunc {
|
|
return func(s *terraform.State) error {
|
|
resource, ok := s.RootModule().Resources[rn]
|
|
if !ok {
|
|
return fmt.Errorf("Checkcommand resource not found: %s", rn)
|
|
}
|
|
|
|
if resource.Primary.ID == "" {
|
|
return fmt.Errorf("Checkcommand resource id not set")
|
|
}
|
|
|
|
client := testAccProvider.Meta().(*iapi.Server)
|
|
_, err := client.GetCheckcommand(resource.Primary.ID)
|
|
if err != nil {
|
|
return fmt.Errorf("Error getting getting Checkcommand: %s", err)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
}
|