From 9f8d059d76f6b1a13dd6b5981765bcc74656e9f0 Mon Sep 17 00:00:00 2001 From: Frederic Pinaud Date: Wed, 4 Mar 2020 16:43:47 +0100 Subject: [PATCH 1/2] Add timeouts to provider ( not running well ) --- examples/test.tf | 24 +++++++++++++++--------- shell/data_source_shell_script.go | 12 ++++++++++++ shell/resource_shell_script.go | 12 +++++++++--- 3 files changed, 36 insertions(+), 12 deletions(-) diff --git a/examples/test.tf b/examples/test.tf index ec5aa81..847f3a1 100644 --- a/examples/test.tf +++ b/examples/test.tf @@ -2,16 +2,18 @@ provider "shell" {} //test complete data resource -data "shell_script" "test" { +resource "shell_script" "test" { lifecycle_commands { - read = <&3 + create = < test.sh >&3 EOF + delete = "rm -rf test.sh" + } + timeouts { + create = "1m" + delete = "2m" } -} - -output "commit_id" { - value = data.shell_script.test.output["commit_id"] } //test resource with no read or update @@ -75,7 +77,7 @@ resource "shell_script" "test4" { } //test complete resource -resource "shell_script" "test5" { +/*resource "shell_script" "test5" { lifecycle_commands { create = file("${path.module}/scripts/create.sh") read = file("${path.module}/scripts/read.sh") @@ -89,12 +91,16 @@ resource "shell_script" "test5" { yolo = "yolo" ball = "room" } + timeouts { + create = "1m" + delete = "1m" + } } output "commit_id2" { value = shell_script.test5.output["commit_id"] } - +*/ //resource with triggers resource "shell_script" "test6" { lifecycle_commands { diff --git a/shell/data_source_shell_script.go b/shell/data_source_shell_script.go index 9e7a82c..a2f74e3 100644 --- a/shell/data_source_shell_script.go +++ b/shell/data_source_shell_script.go @@ -2,6 +2,7 @@ package shell import ( "log" + "time" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/rs/xid" @@ -24,6 +25,11 @@ func dataSourceShellScript() *schema.Resource { Required: true, ForceNew: true, }, + "create": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, }, }, }, @@ -45,6 +51,12 @@ func dataSourceShellScript() *schema.Resource { Elem: schema.TypeString, }, }, + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(1 * time.Minute), + Read: schema.DefaultTimeout(1 * time.Minute), + Update: schema.DefaultTimeout(1 * time.Minute), + Delete: schema.DefaultTimeout(1 * time.Minute), + }, } } diff --git a/shell/resource_shell_script.go b/shell/resource_shell_script.go index bdf7035..b56d749 100644 --- a/shell/resource_shell_script.go +++ b/shell/resource_shell_script.go @@ -1,11 +1,11 @@ package shell import ( - "log" - "reflect" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/rs/xid" + "log" + "reflect" + "time" ) func resourceShellScript() *schema.Resource { @@ -72,6 +72,12 @@ func resourceShellScript() *schema.Resource { Default: false, }, }, + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(1 * time.Minute), + Read: schema.DefaultTimeout(1 * time.Minute), + Update: schema.DefaultTimeout(1 * time.Minute), + Delete: schema.DefaultTimeout(1 * time.Minute), + }, } } From 1e3df339f4d4bc193fcbfe5bbfea72e92c50273e Mon Sep 17 00:00:00 2001 From: Frederic Pinaud Date: Fri, 6 Mar 2020 10:18:43 +0100 Subject: [PATCH 2/2] Add Timeouts resources and a test for it --- examples/test.tf | 54 ++++++++++++++++++++++--------- shell/data_source_shell_script.go | 18 +++++------ shell/resource_shell_script.go | 12 +++---- 3 files changed, 52 insertions(+), 32 deletions(-) diff --git a/examples/test.tf b/examples/test.tf index 847f3a1..ff5a7c8 100644 --- a/examples/test.tf +++ b/examples/test.tf @@ -1,21 +1,21 @@ provider "shell" {} - -//test complete data resource -resource "shell_script" "test" { +//test complete data resource +data "shell_script" "test" { lifecycle_commands { create = < test.sh >&3 + touch test + EOF + read = <&3 EOF - delete = "rm -rf test.sh" - } - timeouts { - create = "1m" - delete = "2m" } } +output "commit_id" { + value = data.shell_script.test.output["commit_id"] +} + //test resource with no read or update resource "shell_script" "test2" { lifecycle_commands { @@ -77,7 +77,7 @@ resource "shell_script" "test4" { } //test complete resource -/*resource "shell_script" "test5" { +resource "shell_script" "test5" { lifecycle_commands { create = file("${path.module}/scripts/create.sh") read = file("${path.module}/scripts/read.sh") @@ -91,16 +91,12 @@ resource "shell_script" "test4" { yolo = "yolo" ball = "room" } - timeouts { - create = "1m" - delete = "1m" - } } output "commit_id2" { value = shell_script.test5.output["commit_id"] } -*/ + //resource with triggers resource "shell_script" "test6" { lifecycle_commands { @@ -119,4 +115,30 @@ resource "shell_script" "test6" { triggers = { abc = 123 } +} + +//resource with triggers +resource "shell_script" "test7" { + lifecycle_commands { + create = file("${path.module}/scripts/create.sh") + read = file("${path.module}/scripts/read.sh") + delete = file("${path.module}/scripts/delete.sh") + } + + working_directory = "${path.module}" + + environment = { + yolo = "yolo" + ball = "room" + } + + triggers = { + abc = 123 + } + timeouts { + create = "2m" + delete = "3m" + update = "2m" + read = "5m" + } } \ No newline at end of file diff --git a/shell/data_source_shell_script.go b/shell/data_source_shell_script.go index a2f74e3..5789e2f 100644 --- a/shell/data_source_shell_script.go +++ b/shell/data_source_shell_script.go @@ -1,17 +1,21 @@ package shell import ( - "log" - "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/rs/xid" + "log" + "time" ) func dataSourceShellScript() *schema.Resource { return &schema.Resource{ Read: dataSourceShellScriptRead, - + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(10 * time.Minute), + Read: schema.DefaultTimeout(10 * time.Minute), + Update: schema.DefaultTimeout(10 * time.Minute), + Delete: schema.DefaultTimeout(10 * time.Minute), + }, Schema: map[string]*schema.Schema{ "lifecycle_commands": { Type: schema.TypeList, @@ -51,12 +55,6 @@ func dataSourceShellScript() *schema.Resource { Elem: schema.TypeString, }, }, - Timeouts: &schema.ResourceTimeout{ - Create: schema.DefaultTimeout(1 * time.Minute), - Read: schema.DefaultTimeout(1 * time.Minute), - Update: schema.DefaultTimeout(1 * time.Minute), - Delete: schema.DefaultTimeout(1 * time.Minute), - }, } } diff --git a/shell/resource_shell_script.go b/shell/resource_shell_script.go index b56d749..00d7480 100644 --- a/shell/resource_shell_script.go +++ b/shell/resource_shell_script.go @@ -14,6 +14,12 @@ func resourceShellScript() *schema.Resource { Delete: resourceShellScriptDelete, Read: resourceShellScriptRead, Update: resourceShellScriptUpdate, + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(10 * time.Minute), + Read: schema.DefaultTimeout(10 * time.Minute), + Update: schema.DefaultTimeout(10 * time.Minute), + Delete: schema.DefaultTimeout(10 * time.Minute), + }, Schema: map[string]*schema.Schema{ "lifecycle_commands": { Type: schema.TypeList, @@ -72,12 +78,6 @@ func resourceShellScript() *schema.Resource { Default: false, }, }, - Timeouts: &schema.ResourceTimeout{ - Create: schema.DefaultTimeout(1 * time.Minute), - Read: schema.DefaultTimeout(1 * time.Minute), - Update: schema.DefaultTimeout(1 * time.Minute), - Delete: schema.DefaultTimeout(1 * time.Minute), - }, } }