From 08b70efc960950a57b33affb448af79d8d056e9b Mon Sep 17 00:00:00 2001 From: Andrew Babichev Date: Wed, 4 Jan 2023 09:44:20 +0000 Subject: [PATCH] Add kubernetes_ingress_v1 timeouts (#1936) * Add kubernetes_ingress_v1 timeouts --- .changelog/1936.txt | 3 +++ kubernetes/provider_test.go | 2 +- kubernetes/resource_kubernetes_ingress_v1.go | 5 +++++ .../resource_kubernetes_ingress_v1_test.go | 17 +++++++++++++++-- website/docs/r/ingress_v1.html.markdown | 7 ++++++- 5 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 .changelog/1936.txt diff --git a/.changelog/1936.txt b/.changelog/1936.txt new file mode 100644 index 0000000000..d085803894 --- /dev/null +++ b/.changelog/1936.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +`resource/kubernetes_ingress_v1`: add create and delete timeouts +``` diff --git a/kubernetes/provider_test.go b/kubernetes/provider_test.go index 18ae7af12c..a9f6524bc6 100644 --- a/kubernetes/provider_test.go +++ b/kubernetes/provider_test.go @@ -250,7 +250,7 @@ func skipIfNotRunningInGke(t *testing.T) { t.Skip("The Kubernetes endpoint must come from GKE for this test to run - skipping") } for _, ev := range []string{"GOOGLE_PROJECT", "GOOGLE_REGION", "GOOGLE_ZONE"} { - if os.Getenv("ev") == "" { + if os.Getenv(ev) == "" { t.Skipf("%s must be set for GoogleCloud tests", ev) } } diff --git a/kubernetes/resource_kubernetes_ingress_v1.go b/kubernetes/resource_kubernetes_ingress_v1.go index 94aea11f0d..e126dcb996 100644 --- a/kubernetes/resource_kubernetes_ingress_v1.go +++ b/kubernetes/resource_kubernetes_ingress_v1.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "log" + "time" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" networking "k8s.io/api/networking/v1" @@ -25,6 +26,10 @@ func resourceKubernetesIngressV1() *schema.Resource { StateContext: schema.ImportStatePassthroughContext, }, Schema: resourceKubernetesIngressV1Schema(), + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(20 * time.Minute), + Delete: schema.DefaultTimeout(20 * time.Minute), + }, } } diff --git a/kubernetes/resource_kubernetes_ingress_v1_test.go b/kubernetes/resource_kubernetes_ingress_v1_test.go index bd0719d24c..c26ea415de 100644 --- a/kubernetes/resource_kubernetes_ingress_v1_test.go +++ b/kubernetes/resource_kubernetes_ingress_v1_test.go @@ -414,6 +414,9 @@ func testAccKubernetesIngressV1Config_serviceBackend(name string) string { } } } + timeouts { + create = "45m" + } }`, name) } @@ -586,10 +589,16 @@ func testAccKubernetesIngressV1Config_waitForLoadBalancer(name string) string { } port { port = 8000 - target_port = 80 + target_port = 8080 protocol = "TCP" } } + lifecycle { + ignore_changes = [ + metadata[0].annotations["cloud.google.com/neg"], + metadata[0].annotations["cloud.google.com/neg-status"], + ] + } } resource "kubernetes_deployment" "test" { @@ -612,9 +621,10 @@ resource "kubernetes_deployment" "test" { container { name = "test" image = "gcr.io/google-samples/hello-app:2.0" + env { name = "PORT" - value = "80" + value = "8080" } } } @@ -641,6 +651,9 @@ resource "kubernetes_ingress_v1" "test" { } } wait_for_load_balancer = true + timeouts { + create = "45m" + } }`, name, name, name, name, name, name, name) } diff --git a/website/docs/r/ingress_v1.html.markdown b/website/docs/r/ingress_v1.html.markdown index 884976eacc..45ce1929a9 100644 --- a/website/docs/r/ingress_v1.html.markdown +++ b/website/docs/r/ingress_v1.html.markdown @@ -10,7 +10,6 @@ description: |- Ingress is a collection of rules that allow inbound connections to reach the endpoints defined by a backend. An Ingress can be configured to give services externally-reachable urls, load balance traffic, terminate SSL, offer name based virtual hosting etc. - ## Example Usage ```hcl @@ -306,6 +305,12 @@ The following arguments are supported: * `ip` - IP is set for load-balancer ingress points that are IP based (typically GCE or OpenStack load-balancers). * `hostname` - Hostname is set for load-balancer ingress points that are DNS based (typically AWS load-balancers). +## Timeouts + +The following [Timeout](https://developer.hashicorp.com/terraform/language/resources/syntax#operation-timeouts) configuration options are available for the `kubernetes_ingress_v1` resource: + +* `create` - ingress load balancer creation timeout (default `20 minutes`). +* `delete` - ingress load balancer deletion timeout (default `20 minutes`). ## Import