Skip to content

Commit 6cad358

Browse files
authored
kubernetes_service: cluster_ip should support None (#1292)
* cluster_ip for service should support None * Update CHANGELOG for v2.3.1
1 parent dd9e36c commit 6cad358

File tree

3 files changed

+55
-6
lines changed

3 files changed

+55
-6
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 2.3.1 (Unreleased)
2+
3+
BUG FIXES:
4+
* `cluster_ip` for `kubernetes_service` should support value `None` (#1291)
5+
16
## 2.3.0 (June 02, 2021)
27

38
BUG FIXES:

kubernetes/resource_kubernetes_service.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,15 @@ func resourceKubernetesServiceSchemaV1() map[string]*schema.Schema {
5353
Elem: &schema.Resource{
5454
Schema: map[string]*schema.Schema{
5555
"cluster_ip": {
56-
Type: schema.TypeString,
57-
Description: "The IP address of the service. It is usually assigned randomly by the master. If an address is specified manually and is not in use by others, it will be allocated to the service; otherwise, creation of the service will fail. `None` can be specified for headless services when proxying is not required. Ignored if type is `ExternalName`. More info: http://kubernetes.io/docs/user-guide/services#virtual-ips-and-service-proxies",
58-
Optional: true,
59-
ForceNew: true,
60-
Computed: true,
61-
ValidateFunc: validation.IsIPAddress,
56+
Type: schema.TypeString,
57+
Description: "The IP address of the service. It is usually assigned randomly by the master. If an address is specified manually and is not in use by others, it will be allocated to the service; otherwise, creation of the service will fail. `None` can be specified for headless services when proxying is not required. Ignored if type is `ExternalName`. More info: http://kubernetes.io/docs/user-guide/services#virtual-ips-and-service-proxies",
58+
Optional: true,
59+
ForceNew: true,
60+
Computed: true,
61+
ValidateFunc: validation.Any(
62+
validation.StringInSlice([]string{api.ClusterIPNone}, false),
63+
validation.IsIPAddress,
64+
),
6265
},
6366
"external_ips": {
6467
Type: schema.TypeSet,

kubernetes/resource_kubernetes_service_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,28 @@ func TestAccKubernetesService_loadBalancer_healthcheck(t *testing.T) {
247247
})
248248
}
249249

250+
func TestAccKubernetesService_headless(t *testing.T) {
251+
var conf api.Service
252+
name := acctest.RandomWithPrefix("tf-acc-test")
253+
resourceName := "kubernetes_service.test"
254+
255+
resource.Test(t, resource.TestCase{
256+
PreCheck: func() { testAccPreCheck(t) },
257+
IDRefreshName: resourceName,
258+
ProviderFactories: testAccProviderFactories,
259+
CheckDestroy: testAccCheckKubernetesServiceDestroy,
260+
Steps: []resource.TestStep{
261+
{
262+
Config: testAccKubernetesServiceConfig_headless(name),
263+
Check: resource.ComposeAggregateTestCheckFunc(
264+
testAccCheckKubernetesServiceExists(resourceName, &conf),
265+
resource.TestCheckResourceAttr(resourceName, "spec.0.cluster_ip", "None"),
266+
),
267+
},
268+
},
269+
})
270+
}
271+
250272
func TestAccKubernetesService_loadBalancer_annotations_aws(t *testing.T) {
251273
var conf api.Service
252274
name := acctest.RandomWithPrefix("tf-acc-test")
@@ -1078,6 +1100,25 @@ func testAccKubernetesServiceConfig_loadBalancer_annotations_aws_modified(name s
10781100
`, name)
10791101
}
10801102

1103+
func testAccKubernetesServiceConfig_headless(name string) string {
1104+
return fmt.Sprintf(`resource "kubernetes_service" "test" {
1105+
metadata {
1106+
name = "%s"
1107+
}
1108+
spec {
1109+
cluster_ip = "None"
1110+
selector = {
1111+
App = "MyApp"
1112+
}
1113+
port {
1114+
port = 8888
1115+
target_port = 80
1116+
}
1117+
}
1118+
}
1119+
`, name)
1120+
}
1121+
10811122
func testAccKubernetesServiceConfig_loadBalancer_healthcheck(name string, nodePort int) string {
10821123
return fmt.Sprintf(`resource "kubernetes_service" "test" {
10831124
metadata {

0 commit comments

Comments
 (0)