diff --git a/kubernetes/resource_kubernetes_service.go b/kubernetes/resource_kubernetes_service.go index 9251545a70..4aad06a005 100644 --- a/kubernetes/resource_kubernetes_service.go +++ b/kubernetes/resource_kubernetes_service.go @@ -68,7 +68,7 @@ func resourceKubernetesService() *schema.Resource { "port": { Type: schema.TypeList, Description: "The list of ports that are exposed by this service. More info: http://kubernetes.io/docs/user-guide/services#virtual-ips-and-service-proxies", - Required: true, + Optional: true, MinItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ diff --git a/kubernetes/resource_kubernetes_service_test.go b/kubernetes/resource_kubernetes_service_test.go index 1cb19bf674..13e650cd80 100644 --- a/kubernetes/resource_kubernetes_service_test.go +++ b/kubernetes/resource_kubernetes_service_test.go @@ -181,7 +181,6 @@ func TestAccKubernetesService_nodePort(t *testing.T) { testAccCheckKubernetesServiceExists("kubernetes_service.test", &conf), resource.TestCheckResourceAttr("kubernetes_service.test", "metadata.0.name", name), resource.TestCheckResourceAttr("kubernetes_service.test", "spec.#", "1"), - resource.TestCheckResourceAttr("kubernetes_service.test", "spec.#", "1"), resource.TestCheckResourceAttrSet("kubernetes_service.test", "spec.0.cluster_ip"), resource.TestCheckResourceAttr("kubernetes_service.test", "spec.0.external_ips.#", "2"), resource.TestCheckResourceAttr("kubernetes_service.test", "spec.0.external_ips.1452553500", "10.0.0.4"), @@ -223,6 +222,37 @@ func TestAccKubernetesService_nodePort(t *testing.T) { }) } +func TestAccKubernetesService_externalName(t *testing.T) { + var conf api.Service + name := fmt.Sprintf("tf-acc-test-%s", acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum)) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + IDRefreshName: "kubernetes_service.test", + Providers: testAccProviders, + CheckDestroy: testAccCheckKubernetesServiceDestroy, + Steps: []resource.TestStep{ + { + Config: testAccKubernetesServiceConfig_externalName(name), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckKubernetesServiceExists("kubernetes_service.test", &conf), + resource.TestCheckResourceAttr("kubernetes_service.test", "metadata.0.name", name), + resource.TestCheckResourceAttr("kubernetes_service.test", "spec.#", "1"), + resource.TestCheckResourceAttr("kubernetes_service.test", "spec.0.cluster_ip", ""), + resource.TestCheckResourceAttr("kubernetes_service.test", "spec.0.external_ips.#", "0"), + resource.TestCheckResourceAttr("kubernetes_service.test", "spec.0.external_name", "terraform.io"), + resource.TestCheckResourceAttr("kubernetes_service.test", "spec.0.load_balancer_ip", ""), + resource.TestCheckResourceAttr("kubernetes_service.test", "spec.0.load_balancer_source_ranges.#", "0"), + resource.TestCheckResourceAttr("kubernetes_service.test", "spec.0.port.#", "0"), + resource.TestCheckResourceAttr("kubernetes_service.test", "spec.0.selector.%", "0"), + resource.TestCheckResourceAttr("kubernetes_service.test", "spec.0.session_affinity", "None"), + resource.TestCheckResourceAttr("kubernetes_service.test", "spec.0.type", "ExternalName"), + ), + }, + }, + }) +} + func TestAccKubernetesService_importBasic(t *testing.T) { resourceName := "kubernetes_service.test" name := fmt.Sprintf("tf-acc-test-%s", acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum)) @@ -480,6 +510,20 @@ resource "kubernetes_service" "test" { }`, name, name) } +func testAccKubernetesServiceConfig_externalName(name string) string { + return fmt.Sprintf(` +resource "kubernetes_service" "test" { + metadata { + name = "%s" + } + spec { + type = "ExternalName" + external_name = "terraform.io" + } +} +`, name) +} + func testAccKubernetesServiceConfig_generatedName(prefix string) string { return fmt.Sprintf(` resource "kubernetes_service" "test" {