Categorygithub.com/jzbruno/terraform-provider-shell
modulepackage
0.2.1-linux
Repository: https://github.com/jzbruno/terraform-provider-shell.git
Documentation: pkg.go.dev

# README

Terraform Shell Provider

Overview

Build Status Maintainability Go Report Card

This is a basic shell provider that includes a data source to allow capturing output of commands for use with other Terraform resourcees.

In it's current state this provider is just a data source and should not be used to run commands that modify resources. A future addition of a resource should be used for that use case.

Install

  1. The provider can either be built or downloaded from GitHub. Get the provider.

    • To build the provider

      git clone [email protected]:jzbruno/terraform-provider-shell.git
      cd terraform-provider-shell/
      go get
      go build
      

    • To download the provider

      curl -sL https://github.com/jzbruno/terraform-provider-shell/releases/download/v0.1.0-alpha/terraform-provider-shell -o terraform-provider-shell
      

  2. Install the provider.

    chmod +x terraform-provider-shell
    mkdir -p ~/.terraform.d/plugins/
    cp terraform-provider-shell ~/.terraform.d/plugins/
    

    For more information about how Terraform discovers plugins, see Terraform Plugin Discovery

Example

The following example will store your public IP allowing it to be used in another resource

data "shell_command" "my_public_ip" {
  command = "curl -s ifconfig.co"
}

To use the output reference the data source in another Terraform resource. If the data source changes it will cause an update to the Terraform resource referencing it.

resource "aws_security_group" "allow_my_public_ip" {
  name        = "allow_my_public_ip"

  ingress {
    from_port   = 22
    to_port     = 22
    protocol    = "tcp"
    cidr_blocks = ["${data.shell_command.my_public_ip.output}/32"]
  }
}

Acceptance Test

To run the acceptance tests set test TF_ACC env var and run go test. An internet connection is required.

TF_ACC=1 go test -v ./...

Attribute Reference

Required

  • command

    The command string to run including arguments.

    • Type: string

Optional

  • shell

    The shell used to run commands including arguments.

    • Type: List of strings

    • Default:

      • Linux and Mac: ["/bin/bash", "-c"]
      • Windows: ["cmd", "-C"]
  • trim_whitespace

    If set to true, all leading and trailing whitespace will be trimmed from the output of the command.

    • Type: string
    • Default: true

Exported

The following attributes are exported in addition to the attributes listed above.

  • output

    The output of the command run.

    • Type: string

# Packages

No description provided by the author