hi there,
I am writing my first acceptance test for a custom TF provider and I am stuck with the provider configuration. I have configured all the environment variables for the provider inputs, however, when running test I am getting errors, e.g.
Error: Missing required argument
The argument "host" is required, but was not set.
Here is the test code I am trying to run
func TestAccLDAPOU_basic(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccCheckLDAOUConfigBasic,
Check: resource.ComposeTestCheckFunc(
testAccCheckLDAPOUExists("ldap_ou.test"),
),
},
},
})
}
func testAccCheckLDAPOUDestroy(s *terraform.State) error {
c := testAccProvider.Meta().(*goldap.Client)
for _, rs := range s.RootModule().Resources {
if rs.Type != "ldap_ou" {
continue
}
ouID := rs.Primary.ID
err := c.DeleteOU(ouID)
if err != nil {
return err
}
}
return nil
}
func testAccCheckLDAPOUExists(n string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
if !ok {
return fmt.Errorf("Not found: %s", n)
}
if rs.Primary.ID == "" {
return fmt.Errorf("No OrderID set")
}
return nil
}
}
const testAccCheckLDAOUConfigBasic = `
resource "ldap_ou" "test" {
path = "OU=LDAP-Test,DC=example,DC=org"
name = "test_ou"
description = "Something I need to test"
}
`
and here is the provider_test.go content
var testAccProviders map[string]*schema.Provider
var testAccProvider *schema.Provider
func init() {
testAccProvider = Provider()
testAccProviders = map[string]*schema.Provider{
"ldap": testAccProvider,
}
}
func TestProvider(t *testing.T) {
if err := Provider().InternalValidate(); err != nil {
t.Fatalf("err: %s", err)
}
}
func testAccPreCheck(t *testing.T) {
if v := os.Getenv("host"); v == "" {
t.Fatal("host must be set for acceptance tests")
}
if v := os.Getenv("port"); v == "" {
t.Fatal("port must be set for acceptance tests")
}
if v := os.Getenv("bind_user"); v == "" {
t.Fatal("bind_user must be set for acceptance tests")
}
if v := os.Getenv("bind_password"); v == "" {
t.Fatal("bind_password must be set for acceptance tests")
}
if v := os.Getenv("schema_type"); v == "" {
t.Fatal("schme_type must be set for acceptance tests")
}
}
what am I missing?