Skip to content

Commit

Permalink
Merge branch 'release/v0.6.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
rucciva committed Aug 24, 2021
2 parents 941a507 + e8f00ea commit 97f6459
Show file tree
Hide file tree
Showing 22 changed files with 1,928 additions and 150 deletions.
8 changes: 3 additions & 5 deletions docs/data-sources/script.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@ Read arbritrary resource by specifying commands that will be uploaded and execut
## Example Usage

```hcl
locals {
package_name = "apache2"
}
resource "linux_script" "install_package" {
data "linux_script" "package_version" {
lifecycle_commands {
read = "apt-cache policy $PACKAGE_NAME | grep 'Installed:' | grep -v '(none)' | awk '{ print $2 }' | xargs | tr -d '\n'"
}
environment = {
PACKAGE_NAME = local.package_name
PACKAGE_NAME = "apache2"
PACKAGE_VERSION = "2.4.18-2ubuntu3.4"
}
}
Expand All @@ -23,6 +20,7 @@ resource "linux_script" "install_package" {

The following arguments are supported:

- `provider_override` - (Optional) see [provider_override](../#provider-override).
- `lifecycle_commands` - (Required) see [lifecycle_commands](#lifecycle_commands).
- `interpreter` - (Optional, string list) Interpreter for running each `lifecycle_commands`. Default empty list.
- `working_directory` - (Optional, string) The working directory where each `lifecycle_commands` is executed. Default empty string.
Expand Down
41 changes: 38 additions & 3 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ Provider for managing linux machine through SSH connection.

```hcl
provider "linux" {
host = "127.0.0.1"
port = 22
user = "root"
host = "127.0.0.1"
port = 22
user = "root"
password = "root"
}
Expand Down Expand Up @@ -45,10 +45,12 @@ resource "linux_script" "install_package" {
update = "apt update && apt install -y $PACKAGE_NAME=$PACKAGE_VERSION"
delete = "apt remove -y $PACKAGE_NAME"
}
environment = {
PACKAGE_NAME = local.package_name
PACKAGE_VERSION = "2.4.18-2ubuntu3.4"
}
triggers = {
PACKAGE_NAME = local.package_name"
}
Expand Down Expand Up @@ -79,3 +81,36 @@ resource "linux_script" "install_package" {
## Lazy SSH Connection Setup

SSH connection are only made when Terraform enters Create|Read|Update|Delete phase of this provider's resources. Thus specifying it's arguments with value that only known after apply should be possible.

## Provider Override

It is also possible to provide ssh connection configuration directly in resources or data sources definition under `provider_override` block as a workaround for implementing dynamic provider. The arguments are the same as [the one above](#argument-reference) with additional `id` attribute, which is used in connection pooling and locking mechanism.

```terraform
resource "linux_script" "install_package" {
provider_override {
id = "myhost"
host = "127.0.0.1"
port = 22
user = "root"
password = "root"
}
lifecycle_commands {
create = "apt update && apt install -y $PACKAGE_NAME=$PACKAGE_VERSION"
read = "apt-cache policy $PACKAGE_NAME | grep 'Installed:' | grep -v '(none)' | awk '{ print $2 }' | xargs | tr -d '\n'"
update = "apt update && apt install -y $PACKAGE_NAME=$PACKAGE_VERSION"
delete = "apt remove -y $PACKAGE_NAME"
}
environment = {
PACKAGE_NAME = local.package_name
PACKAGE_VERSION = "2.4.18-2ubuntu3.4"
}
triggers = {
PACKAGE_NAME = local.package_name"
}
}
```
1 change: 1 addition & 0 deletions docs/resources/directory.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ resource "linux_file" "file" {

The following arguments are supported:

- `provider_override` - (Optional) see [provider_override](../#provider-override).
- `path` - (Required, string) Absolute path of the directory. Parent directory will be prepared as needed. Changing this will move all contents under the current directory to the new directory.
- `owner` - (Optional, int) User ID of the folder. Default `0`.
- `group` - (Optional, int) Group ID of the folder. Default `0`.
Expand Down
1 change: 1 addition & 0 deletions docs/resources/file.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ resource "linux_file" "file" {

The following arguments are supported:

- `provider_override` - (Optional) see [provider_override](../#provider-override).
- `path` - (Required, string) Absolute path of the file. Parent directory will be prepared as needed.
- `content` - (Optional, string) Content of the file to create. Default to empty string.
- `owner` - (Optional, int) User ID of the folder. Default `0`.
Expand Down
1 change: 1 addition & 0 deletions docs/resources/script.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ resource "linux_script" "install_package" {

The following arguments are supported:

- `provider_override` - (Optional) see [provider_override](../#provider-override).
- `lifecycle_commands` - (Required) see [lifecycle_commands](#lifecycle_commands).
- `interpreter` - (Optional, string list) Interpreter for running each `lifecycle_commands`. Default empty list.
- `working_directory` - (Optional, string) The working directory where each `lifecycle_commands` is executed. Default empty string.
Expand Down
9 changes: 3 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,16 @@ go 1.15

require (
github.com/MakeNowJust/heredoc v1.0.0
github.com/Masterminds/goutils v1.1.0 // indirect
github.com/Masterminds/semver v1.5.0 // indirect
github.com/Masterminds/sprig v2.22.0+incompatible
github.com/alessio/shellescape v1.3.1
github.com/google/uuid v1.1.2
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
github.com/hashicorp/terraform v0.13.5
github.com/hashicorp/terraform-plugin-sdk/v2 v2.3.0
github.com/huandu/xstrings v1.3.2 // indirect
github.com/hashicorp/terraform-plugin-sdk/v2 v2.7.0
github.com/spf13/cast v1.3.1
github.com/stretchr/testify v1.6.1
github.com/stretchr/testify v1.7.0
go.uber.org/zap v1.16.0
golang.org/x/net v0.0.0-20201110031124-69a78807bb2b
golang.org/x/net v0.0.0-20210326060303-6b1517762897
)

replace github.com/hashicorp/terraform => ./internal/workaround/hashicorp/terraform
Loading

0 comments on commit 97f6459

Please sign in to comment.