Skip to content

Add ipMode field #2557

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: v3-major-release
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/resources/ingress.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ Read-Only:
Read-Only:

- `hostname` (String)
- `ip_mode` (String)
- `ip` (String)


Expand Down
1 change: 1 addition & 0 deletions docs/resources/ingress_v1.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ Read-Only:
Read-Only:

- `hostname` (String)
- `ip_mode` (String)
- `ip` (String)


Expand Down
1 change: 1 addition & 0 deletions docs/resources/service.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ Read-Only:

- `hostname` (String)
- `ip` (String)
- `ip_mode` (String)



Expand Down
1 change: 1 addition & 0 deletions docs/resources/service_v1.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ Read-Only:

- `hostname` (String)
- `ip` (String)
- `ip_mode` (String)



Expand Down
4 changes: 4 additions & 0 deletions kubernetes/resource_kubernetes_service_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,10 @@ func resourceKubernetesServiceSchemaV1() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"ip_mode": {
Type: schema.TypeString,
Computed: true,
},
"hostname": {
Type: schema.TypeString,
Computed: true,
Expand Down
60 changes: 60 additions & 0 deletions kubernetes/resource_kubernetes_service_v1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,49 @@ func TestAccKubernetesServiceV1_loadBalancer_healthcheck(t *testing.T) {
})
}

func TestAccKubernetesServiceV1_loadBalancer_ipMode(t *testing.T) {
var conf corev1.Service
name := acctest.RandomWithPrefix("tf-acc-test")
resourceName := "kubernetes_service_v1.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t); skipIfNoLoadBalancersAvailable(t) },
IDRefreshIgnore: []string{"metadata.0.resource_version"},
ProviderFactories: testAccProviderFactories,
CheckDestroy: testAccCheckKubernetesServiceV1Destroy,
Steps: []resource.TestStep{
{
Config: testAccKubernetesConfig_ignoreAnnotations() +
testAccKubernetesServiceV1Config_loadBalancer_ipMode(name, "VIP"),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckKubernetesServiceV1Exists(resourceName, &conf),
resource.TestCheckResourceAttr(resourceName, "metadata.0.name", name),
resource.TestCheckResourceAttr(resourceName, "spec.#", "1"),
resource.TestCheckResourceAttr(resourceName, "spec.0.type", "LoadBalancer"),
resource.TestCheckResourceAttr(resourceName, "status.0.load_balancer.0.ingress.0.ip_mode", "VIP"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"metadata.0.resource_version", "wait_for_load_balancer"},
},
{
Config: testAccKubernetesConfig_ignoreAnnotations() +
testAccKubernetesServiceV1Config_loadBalancer_ipMode(name, "Proxy"),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckKubernetesServiceV1Exists(resourceName, &conf),
resource.TestCheckResourceAttr(resourceName, "metadata.0.name", name),
resource.TestCheckResourceAttr(resourceName, "spec.#", "1"),
resource.TestCheckResourceAttr(resourceName, "spec.0.type", "LoadBalancer"),
resource.TestCheckResourceAttr(resourceName, "status.0.load_balancer.0.ingress.0.ip_mode", "Proxy"),
),
},
},
})
}

func TestAccKubernetesServiceV1_headless(t *testing.T) {
var conf corev1.Service
name := acctest.RandomWithPrefix("tf-acc-test")
Expand Down Expand Up @@ -1104,6 +1147,23 @@ func testAccKubernetesServiceV1Config_loadBalancer_annotations_aws_modified(name
}
`, name)
}
func testAccKubernetesServiceV1Config_loadBalancer_ipMode(name, ipMode string) string {
return fmt.Sprintf(`
resource "kubernetes_service_v1" "test" {
metadata {
name = "%s"
}

spec {
type = "LoadBalancer"
port {
port = 80
target_port = 8080
}
}
}
`, name)
}

func testAccKubernetesServiceV1Config_headless(name string) string {
return fmt.Sprintf(`resource "kubernetes_service_v1" "test" {
Expand Down
1 change: 1 addition & 0 deletions kubernetes/structure_service_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ func flattenLoadBalancerStatus(in v1.LoadBalancerStatus) []interface{} {

att["ip"] = ingress.IP
att["hostname"] = ingress.Hostname
att["ip_mode"] = ingress.IPMode
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we're missing the expander which is where we receive the resp that contains the ip_mode

Copy link
Contributor

@JaylonmcShan03 JaylonmcShan03 Mar 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After doing some digging, there isn't an expanded function in place. And I believe the reason for that is due to status.loadbalancer being computed. I believe the IpMode should be computed, which would get rid of the need for the expander. Just made a new commit making ip_mode computed. Please let me know your thoughts!


out[i] = att
}
Expand Down
Loading