Skip to content

Commit

Permalink
Merge pull request #27 from terraform-providers/b-service-optional-port
Browse files Browse the repository at this point in the history
r/service: Make port optional field
  • Loading branch information
radeksimko authored Jul 18, 2017
2 parents 33297fa + c4b99c9 commit a85fc4b
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
2 changes: 1 addition & 1 deletion kubernetes/resource_kubernetes_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
46 changes: 45 additions & 1 deletion kubernetes/resource_kubernetes_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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" {
Expand Down

0 comments on commit a85fc4b

Please sign in to comment.