项目作者: scottwinkler

项目描述 :
Terraform provider for executing shell commands and saving output to state file
高级语言: Go
项目地址: git://github.com/scottwinkler/terraform-provider-shell.git
创建时间: 2018-06-08T07:56:50Z
项目社区:https://github.com/scottwinkler/terraform-provider-shell

开源协议:Mozilla Public License 2.0

下载


Terraform Provider Shell

https://registry.terraform.io/providers/scottwinkler/shell

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.

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.

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

Requirements

Building The Provider

  1. Clone the repository
  2. Enter the repository directory
  3. Build the provider using the Go install command:
    1. $ go install

Adding Dependencies

This provider uses Go modules.
Please see the Go documentation for the most up to date information about using Go modules.

To add a new dependency github.com/author/dependency to your Terraform provider:

  1. go get github.com/author/dependency
  2. go mod tidy

Then commit the changes to go.mod and go.sum.

Using the provider

You can use this provider to make custom external resources and data sources:

  1. terraform {
  2. required_providers {
  3. shell = {
  4. source = "scottwinkler/shell"
  5. version = "1.7.7"
  6. }
  7. }
  8. }
  9. variable "oauth_token" {
  10. type = string
  11. }
  12. provider "shell" {
  13. sensitive_environment = {
  14. OAUTH_TOKEN = var.oauth_token
  15. }
  16. }
  17. resource "shell_script" "github_repository" {
  18. lifecycle_commands {
  19. create = file("${path.module}/scripts/create.sh")
  20. read = file("${path.module}/scripts/read.sh")
  21. update = file("${path.module}/scripts/update.sh")
  22. delete = file("${path.module}/scripts/delete.sh")
  23. }
  24. environment = {
  25. NAME = "HELLO-WORLD"
  26. DESCRIPTION = "description"
  27. }
  28. }

Developing the Provider

If you wish to work on the provider, you’ll first need Go installed on your machine (see Requirements above).

To compile the provider, run go install. This will build the provider and put the provider binary in the $GOPATH/bin directory.

In order to run the full suite of Acceptance tests, run make testacc.

Note: Acceptance tests create real resources, and often cost money to run.

  1. $ make testacc