Skip to content

Commit

Permalink
Merge pull request #7 from scottwinkler/fix/0.12-support
Browse files Browse the repository at this point in the history
update
  • Loading branch information
scottwinkler authored Jul 2, 2019
2 parents 56533de + e89154d commit 59c3191
Show file tree
Hide file tree
Showing 4 changed files with 416 additions and 77 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ website/node_modules
resources
resources2
src/
.vscode
.vscode/
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@ To use a data resource you need to implement the read command. Any output to std

#accessing the output from the data resource
output "commit_id" {
value = "${data.shell_script.test.output["commit_id"]}"
value = data.shell_script.test.output["commit_id"]
}

Resources are a bit more complicated. You must implement the create, and delete lifecycle commands, but read and update are also optionally available. If you choose not to implement the read command, then create (and update if you are using it) must output the state in the form of a properly formatted json. The local state will not be synced with the actual state, but for many applications that is not a problem. If you choose not to implement update, then if a change occurs that would trigger an update the resource will be instead be destroyed and then recreated. Again, for many applications this is not a problem, update can be tricky to use as it depends a lot on the use case. If you implement read, then you must output the state in the form of a properly formatted json, and you should not output the state in either the create or update scripts. See the examples in the test folder for how to do each of these.

resource "shell_script" "test" {
lifecycle_commands {
create = "${file("${path.module}/scripts/create.sh")}"
read = "${file("${path.module}/scripts/read.sh")}"
update = "${file("${path.module}/scripts/update.sh")}"
delete = "${file("${path.module}/scripts/delete.sh")}"
create = file("${path.module}/scripts/create.sh")
read = file("${path.module}/scripts/read.sh")
update = file("${path.module}/scripts/update.sh")
delete = file("${path.module}/scripts/delete.sh")
}

working_directory = "${path.module}"
working_directory = path.module

environment = {
yolo = "yolo"
Expand All @@ -44,7 +44,7 @@ Resources are a bit more complicated. You must implement the create, and delete
}

output "commit_id" {
value = "${shell_script.test.output["commit_id"]}"
value = shell_script.test.output["commit_id"]
}

In the example above I am changing my working_directory, setting some environment variables that will be utilized by all my scripts, and configuring my lifecycle commands for create, read, update and delete. Create and Update should modify the resource but not update the state, while Read should update the state but not modify the resource. An example shell script resouce could have a file being written to in the create. Read would simply cat that previously created file and output it to >&3. Update could measure the changes from the old state (available through stdin) and the new state (implicitly available through environment variables) to decide how best to handle an update. Again since this is a custom resource it is up to you to decide how best to handle updates, in many cases it may make sense not to implement update at all and rely on just create/read/delete. Delete needs to clean up any resources that were created but does not need to return anything. State data is available in the output variable, which is mapped from the json of your read command.
Expand All @@ -58,5 +58,5 @@ There is now an example for how to use the shell provider to invoke python files
If you wish to build this yourself, follow the instructions:

cd terraform-provider-shell
dep ensure
go build

51 changes: 6 additions & 45 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,49 +1,10 @@
module github.com/scottwinkler/terraform-provider-shell
module githubdev.dco.elmae/CloudPlatform/terraform-provider-shell

go 1.12

require (
github.com/agext/levenshtein v1.2.1
github.com/apparentlymart/go-cidr v0.0.0-20170616213631-2bd8b58cf427
github.com/apparentlymart/go-textseg v1.0.0
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e
github.com/armon/go-radix v1.0.0
github.com/aws/aws-sdk-go v1.16.9
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d
github.com/bgentry/speakeasy v0.1.0
github.com/blang/semver v0.0.0-20170202183821-4a1e882c79dc
github.com/golang/protobuf v1.2.0
github.com/hashicorp/errwrap v1.0.0
github.com/hashicorp/go-cleanhttp v0.5.0
github.com/hashicorp/go-getter v0.0.0-20180327010114-90bb99a48d86
github.com/hashicorp/go-hclog v0.0.0-20170716174523-b4e5765d1e5f
github.com/hashicorp/go-multierror v1.0.0
github.com/hashicorp/go-plugin v0.0.0-20180125190438-e53f54cbf51e
github.com/hashicorp/go-safetemp v1.0.0
github.com/hashicorp/go-uuid v0.0.0-20160120003506-36289988d83c
github.com/hashicorp/go-version v1.0.0
github.com/hashicorp/hcl v0.0.0-20170504190234-a4b07c25de5f
github.com/hashicorp/hcl2 v0.0.0-20180308163058-5f8ed954abd8
github.com/hashicorp/hil v0.0.0-20170627220502-fa9f258a9250
github.com/hashicorp/terraform v0.11.11
github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af
github.com/mattn/go-isatty v0.0.4
github.com/mitchellh/cli v0.0.0-20171129193617-33edc47170b5
github.com/mitchellh/copystructure v0.0.0-20170525013902-d23ffcb85de3
github.com/mitchellh/go-homedir v0.0.0-20161203194507-b8bc1bf76747
github.com/mitchellh/go-testing-interface v1.0.0
github.com/mitchellh/go-wordwrap v1.0.0
github.com/mitchellh/hashstructure v0.0.0-20160209213820-6b17d669fac5
github.com/mitchellh/mapstructure v0.0.0-20170307201123-53818660ed49
github.com/mitchellh/reflectwalk v0.0.0-20170726202117-63d60e9d0dbc
github.com/oklog/run v1.0.0
github.com/posener/complete v1.2.1
github.com/armon/circbuf v0.0.0-20190214190532-5111143e8da2
github.com/hashicorp/terraform v0.12.0
github.com/rs/xid v1.2.1
github.com/ulikunitz/xz v0.5.5
github.com/zclconf/go-cty v0.0.0-20180302160414-49fa5e03c418
golang.org/x/crypto v0.0.0-20170209233901-453249f01cfe
golang.org/x/net v0.0.0-20181217023233-e147a9138326
golang.org/x/sys v0.0.0-20181220182059-7c4c994c65f7
golang.org/x/text v0.3.0
google.golang.org/genproto v0.0.0-20181219182458-5a97ab628bfb
google.golang.org/grpc v1.17.0
github.com/scottwinkler/terraform-provider-shell v0.0.0-20190308051913-56533de967fb
)
Loading

0 comments on commit 59c3191

Please sign in to comment.