Skip to content

Commit 6d62ca6

Browse files
authored
Merge pull request #63 from scottwinkler/feature/registry
prepare for registry
2 parents 9fd0e06 + 42a55ee commit 6d62ca6

File tree

17 files changed

+274
-215
lines changed

17 files changed

+274
-215
lines changed

.github/workflows/go.yml

Lines changed: 0 additions & 22 deletions
This file was deleted.

.github/workflows/release.yml

Lines changed: 0 additions & 42 deletions
This file was deleted.

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## 0.1.0 (Unreleased)
2+
3+
BACKWARDS INCOMPATIBILITIES / NOTES:

GNUmakefile

Lines changed: 5 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,6 @@
1-
TEST?=$$(go list ./... |grep -v 'vendor')
2-
GOFMT_FILES?=$$(find . -name '*.go' |grep -v vendor)
3-
PKG_NAME=shell
1+
default: testacc
42

5-
default: build
6-
7-
build: fmtcheck
8-
go install
9-
10-
test: fmtcheck
11-
go test -i $(TEST) || exit 1
12-
echo $(TEST) | \
13-
xargs -t -n4 go test $(TESTARGS) -timeout=30s -parallel=4
14-
15-
testacc: fmtcheck
16-
TF_ACC=1 go test $(TEST) -v $(TESTARGS) -timeout 15m
17-
18-
vet:
19-
@echo "go vet ."
20-
@go vet $$(go list ./... | grep -v vendor/) ; if [ $$? -eq 1 ]; then \
21-
echo ""; \
22-
echo "Vet found suspicious constructs. Please check the reported constructs"; \
23-
echo "and fix them if necessary before submitting the code for review."; \
24-
exit 1; \
25-
fi
26-
27-
fmt:
28-
gofmt -w $(GOFMT_FILES)
29-
30-
fmtcheck:
31-
@sh -c "'$(CURDIR)/scripts/gofmtcheck.sh'"
32-
33-
errcheck:
34-
@sh -c "'$(CURDIR)/scripts/errcheck.sh'"
35-
36-
test-compile:
37-
@if [ "$(TEST)" = "./..." ]; then \
38-
echo "ERROR: Set TEST to a specific package. For example,"; \
39-
echo " make test-compile TEST=./$(PKG_NAME)"; \
40-
exit 1; \
41-
fi
42-
go test -c $(TEST) $(TESTARGS)
43-
44-
.PHONY: build test testacc vet fmt fmtcheck errcheck test-compile
3+
# Run acceptance tests
4+
.PHONY: testacc
5+
testacc:
6+
TF_ACC=1 go test ./... -v $(TESTARGS) -timeout 120m

README.md

Lines changed: 56 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,11 @@
1-
# terraform-provider-shell
2-
![Go](https://github.com/scottwinkler/terraform-provider-shell/workflows/Go/badge.svg)
3-
## Introduction
1+
Terraform Provider Shell
2+
==================
43
This plugin is for wrapping shell scripts to make them fully fledged terraform resources. Note that this is a backdoor into the Terraform runtime. You can do some pretty dangerous things with this and it is up to you to make sure you don't get in trouble.
54

65
Since this provider is rather different than most other provider, it is recommended that you at least have some familiarity with the internals of Terraform before attempting to use this provider.
76

87
**Note:** many people use this provider for wrapping APIs of resources that are not supported by existing providers. For an example of using this provider to manage a Github repo resource, see `examples/github-repo`
98

10-
## Requirements
11-
12-
- [Terraform](https://www.terraform.io/downloads.html) 0.12.x
13-
- [Go](https://golang.org/doc/install) 1.13 (to build the provider plugin)
14-
15-
## Building The Provider
16-
17-
Clone repository to: `$GOPATH/src/github.com/scottwinkler/terraform-provider-shell`
18-
19-
```sh
20-
$ mkdir -p $GOPATH/src/github.com/scottwinkler; cd $GOPATH/src/github.com/scottwinkler
21-
$ git clone git@github.com:scottwinkler/terraform-provider-shell
22-
```
23-
24-
Enter the provider directory and build the provider
25-
26-
```sh
27-
$ cd $GOPATH/src/github.com/scottwinkler/terraform-provider-shell
28-
$ make build
29-
```
30-
31-
## Installing
32-
To use this plugin, go to releases and download the binary for your specific OS and architecture. You can install the plugin by either putting it in your `~/.terraform/plugins` folder or in your terraform workspace by performing a `terraform init`.
33-
349
## Configuring the Provider
3510
The provider can be configured with optional `environment` and `sensitive_environment` attributes. If these are set, then they will be used to configure all resources which rely on them (without triggering a force new update!)
3611

@@ -53,8 +28,9 @@ provider "shell" {
5328
interpreter = ["/bin/bash", "-c"]
5429
enable_parallelism = true
5530
}
56-
```
57-
## Data Sources
31+
Data Sources
32+
------------
33+
5834
The simplest example is the data source which implements only Read(). Any output to stdout or stderr will show up in the logs, but to save state, you must output a JSON payload to stdout. The last JSON object printed to stdout will be taken to be the output state. The JSON can be a complex nested JSON, but will be flattened into a `map[string]string`. The reason for this is that your JSON payload variables can be accessed from the output map of this resource and used like a normal terraform output, so the value must be a string. You can use the built-in jsondecode() function to read nested JSON values if you really need to.
5935
6036
Below is an example of using the data source. The output of `whoami` is stored in a JSON object for the key `user`
@@ -116,7 +92,9 @@ Outputs:
11692
weather = SanFrancisco: ⛅️ +54°F
11793
```
11894
119-
## Resources
95+
Resources
96+
------------
97+
12098
Resources are a bit more complicated. At a minimum, you must implement the `CREATE`, and `DELETE` lifecycle commands. `READ` and `UPDATE` are optional arguments.
12199
122100
* If you choose not to implement the `READ` command, then `CREATE` (and `UPDATE` if you are using it) must output JSON. The local state will not be synced with the actual state, but for many applications that is not a problem.
@@ -192,10 +170,55 @@ export TF_LOG=1
192170
```
193171
**Note:** if you are using sensitive_environment to set sensitive environment variables, these values won't show up in the logs
194172
195-
## Testing
196-
To run automated tests:
197173
174+
Requirements
175+
------------
176+
177+
- [Terraform](https://www.terraform.io/downloads.html) >= 0.12.x
178+
- [Go](https://golang.org/doc/install) >= 1.12
179+
180+
Building The Provider
181+
---------------------
182+
183+
1. Clone the repository
184+
1. Enter the repository directory
185+
1. Build the provider using the Go `install` command:
198186
```sh
199-
$ make test
187+
$ go install
200188
```
201189

190+
Adding Dependencies
191+
---------------------
192+
193+
This provider uses [Go modules](https://github.com/golang/go/wiki/Modules).
194+
Please see the Go documentation for the most up to date information about using Go modules.
195+
196+
To add a new dependency `github.com/author/dependency` to your Terraform provider:
197+
198+
```
199+
go get github.com/author/dependency
200+
go mod tidy
201+
```
202+
203+
Then commit the changes to `go.mod` and `go.sum`.
204+
205+
206+
Using the provider
207+
----------------------
208+
209+
Fill this in for each provider
210+
211+
Developing the Provider
212+
---------------------------
213+
214+
If you wish to work on the provider, you'll first need [Go](http://www.golang.org) installed on your machine (see [Requirements](#requirements) above).
215+
216+
To compile the provider, run `go install`. This will build the provider and put the provider binary in the `$GOPATH/bin` directory.
217+
218+
In order to run the full suite of Acceptance tests, run `make testacc`.
219+
220+
*Note:* Acceptance tests create real resources, and often cost money to run.
221+
222+
```sh
223+
$ make testacc
224+
```

examples/no-state-emitted-in-create/main.tf

Lines changed: 0 additions & 22 deletions
This file was deleted.

examples/simple-update/main.tf

Lines changed: 0 additions & 12 deletions
This file was deleted.

examples/simple-update/scripts/create.sh

Lines changed: 0 additions & 6 deletions
This file was deleted.

examples/simple-update/scripts/delete.sh

Lines changed: 0 additions & 4 deletions
This file was deleted.

examples/simple-update/scripts/read.sh

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)