diff --git a/examples/test.tf b/examples/test.tf index ec5aa81..ff5a7c8 100644 --- a/examples/test.tf +++ b/examples/test.tf @@ -1,9 +1,11 @@ provider "shell" {} - -//test complete data resource +//test complete data resource data "shell_script" "test" { lifecycle_commands { + create = <&3 EOF @@ -113,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 9e7a82c..5789e2f 100644 --- a/shell/data_source_shell_script.go +++ b/shell/data_source_shell_script.go @@ -1,16 +1,21 @@ package shell import ( - "log" - "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, @@ -24,6 +29,11 @@ func dataSourceShellScript() *schema.Resource { Required: true, ForceNew: true, }, + "create": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, }, }, }, diff --git a/shell/resource_shell_script.go b/shell/resource_shell_script.go index bdf7035..00d7480 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 { @@ -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,