2017-02-06 23:53:01 +01:00
|
|
|
package consul
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
|
|
"github.com/hashicorp/terraform/terraform"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestAccDataConsulAgentSelf_basic(t *testing.T) {
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
Providers: testAccProviders,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccDataConsulAgentSelfConfig,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
2017-02-13 21:09:29 +01:00
|
|
|
testAccCheckDataSourceValue("data.consul_agent_self.read", "acl_datacenter", "<all>"),
|
|
|
|
testAccCheckDataSourceValue("data.consul_agent_self.read", "acl_default_policy", "<all>"),
|
|
|
|
testAccCheckDataSourceValue("data.consul_agent_self.read", "acl_disabled_ttl", "<all>"),
|
|
|
|
testAccCheckDataSourceValue("data.consul_agent_self.read", "acl_down_policy", "<all>"),
|
|
|
|
testAccCheckDataSourceValue("data.consul_agent_self.read", "acl_enforce_0_8_semantics", "<all>"),
|
|
|
|
testAccCheckDataSourceValue("data.consul_agent_self.read", "acl_ttl", "<all>"),
|
|
|
|
testAccCheckDataSourceValue("data.consul_agent_self.read", "advertise_addr", "<any>"),
|
|
|
|
testAccCheckDataSourceValue("data.consul_agent_self.read", "bind_addr", "<any>"),
|
|
|
|
testAccCheckDataSourceValue("data.consul_agent_self.read", "bootstrap_expect", "<all>"),
|
2017-03-14 15:36:14 +01:00
|
|
|
// the local test server is bootstrapped
|
|
|
|
testAccCheckDataSourceValue("data.consul_agent_self.read", "bootstrap_mode", "true"),
|
2017-02-13 21:09:29 +01:00
|
|
|
testAccCheckDataSourceValue("data.consul_agent_self.read", "client_addr", "<any>"),
|
|
|
|
testAccCheckDataSourceValue("data.consul_agent_self.read", "datacenter", "<any>"),
|
|
|
|
testAccCheckDataSourceValue("data.consul_agent_self.read", "dev_mode", "<any>"),
|
|
|
|
testAccCheckDataSourceValue("data.consul_agent_self.read", "domain", "<any>"),
|
|
|
|
testAccCheckDataSourceValue("data.consul_agent_self.read", "enable_anonymous_signature", "<any>"),
|
|
|
|
testAccCheckDataSourceValue("data.consul_agent_self.read", "enable_coordinates", "<any>"),
|
|
|
|
testAccCheckDataSourceValue("data.consul_agent_self.read", "enable_debug", "<any>"),
|
|
|
|
testAccCheckDataSourceValue("data.consul_agent_self.read", "enable_remote_exec", "<any>"),
|
|
|
|
testAccCheckDataSourceValue("data.consul_agent_self.read", "enable_syslog", "<any>"),
|
|
|
|
testAccCheckDataSourceValue("data.consul_agent_self.read", "enable_ui", "<any>"),
|
|
|
|
testAccCheckDataSourceValue("data.consul_agent_self.read", "enable_update_check", "<any>"),
|
2017-02-06 23:53:01 +01:00
|
|
|
testAccCheckDataSourceValue("data.consul_agent_self.read", "id", "<any>"),
|
2017-02-13 21:09:29 +01:00
|
|
|
testAccCheckDataSourceValue("data.consul_agent_self.read", "leave_on_int", "<any>"),
|
|
|
|
testAccCheckDataSourceValue("data.consul_agent_self.read", "leave_on_term", "<any>"),
|
|
|
|
testAccCheckDataSourceValue("data.consul_agent_self.read", "log_level", "<any>"),
|
2017-02-06 23:53:01 +01:00
|
|
|
testAccCheckDataSourceValue("data.consul_agent_self.read", "name", "<any>"),
|
2017-02-13 21:09:29 +01:00
|
|
|
testAccCheckDataSourceValue("data.consul_agent_self.read", "pid_file", "<all>"),
|
|
|
|
testAccCheckDataSourceValue("data.consul_agent_self.read", "rejoin_after_leave", "<any>"),
|
|
|
|
// testAccCheckDataSourceValue("data.consul_agent_self.read", "retry_join", "<all>"),
|
|
|
|
// testAccCheckDataSourceValue("data.consul_agent_self.read", "retry_join_wan", "<any>"),
|
|
|
|
testAccCheckDataSourceValue("data.consul_agent_self.read", "retry_max_attempts", "<any>"),
|
|
|
|
testAccCheckDataSourceValue("data.consul_agent_self.read", "retry_max_attempts_wan", "<any>"),
|
|
|
|
testAccCheckDataSourceValue("data.consul_agent_self.read", "serf_lan_bind_addr", "<all>"),
|
|
|
|
testAccCheckDataSourceValue("data.consul_agent_self.read", "serf_wan_bind_addr", "<all>"),
|
|
|
|
testAccCheckDataSourceValue("data.consul_agent_self.read", "server_mode", "<any>"),
|
|
|
|
testAccCheckDataSourceValue("data.consul_agent_self.read", "server_name", "<all>"),
|
|
|
|
// testAccCheckDataSourceValue("data.consul_agent_self.read", "start_join", "<all>"),
|
|
|
|
// testAccCheckDataSourceValue("data.consul_agent_self.read", "start_join_wan", "<all>"),
|
|
|
|
testAccCheckDataSourceValue("data.consul_agent_self.read", "syslog_facility", "<any>"),
|
|
|
|
testAccCheckDataSourceValue("data.consul_agent_self.read", "telemetry.enable_hostname", "<all>"),
|
|
|
|
testAccCheckDataSourceValue("data.consul_agent_self.read", "tls_ca_file", "<all>"),
|
|
|
|
testAccCheckDataSourceValue("data.consul_agent_self.read", "tls_cert_file", "<all>"),
|
|
|
|
testAccCheckDataSourceValue("data.consul_agent_self.read", "tls_key_file", "<all>"),
|
|
|
|
testAccCheckDataSourceValue("data.consul_agent_self.read", "tls_verify_incoming", "<any>"),
|
|
|
|
testAccCheckDataSourceValue("data.consul_agent_self.read", "tls_verify_outgoing", "<any>"),
|
|
|
|
testAccCheckDataSourceValue("data.consul_agent_self.read", "tls_verify_server_hostname", "<any>"),
|
2017-02-06 23:53:01 +01:00
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccCheckDataSourceValue(n, attr, val string) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
|
|
|
rn, ok := s.RootModule().Resources[n]
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("Resource not found")
|
|
|
|
}
|
2017-02-13 21:09:29 +01:00
|
|
|
out, found := rn.Primary.Attributes[attr]
|
|
|
|
switch {
|
|
|
|
case !found:
|
2017-02-06 23:53:01 +01:00
|
|
|
return fmt.Errorf("Attribute '%s' not found: %#v", attr, rn.Primary.Attributes)
|
2017-02-13 21:09:29 +01:00
|
|
|
case val == "<all>":
|
|
|
|
// Value found, don't care what the payload is (including the zero value)
|
|
|
|
case val != "<any>" && out != val:
|
2017-02-06 23:53:01 +01:00
|
|
|
return fmt.Errorf("Attribute '%s' value '%s' != '%s'", attr, out, val)
|
2017-02-13 21:09:29 +01:00
|
|
|
case val == "<any>" && out == "":
|
2017-02-06 23:53:01 +01:00
|
|
|
return fmt.Errorf("Attribute '%s' value '%s'", attr, out)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const testAccDataConsulAgentSelfConfig = `
|
|
|
|
data "consul_agent_self" "read" {
|
|
|
|
}
|
|
|
|
`
|