generated from hashicorp/terraform-provider-scaffolding
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
675 additions
and
185 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,28 @@ | ||
--- | ||
page_title: "scaffolding_data_source Data Source - terraform-provider-scaffolding" | ||
page_title: "remotefile_data_source Data Source - terraform-provider-remotefile" | ||
subcategory: "" | ||
description: |- | ||
Sample data source in the Terraform provider scaffolding. | ||
Remote file datasource. | ||
--- | ||
|
||
# Data Source `scaffolding_data_source` | ||
# Data Source `remotefile_data_source` | ||
|
||
Sample data source in the Terraform provider scaffolding. | ||
Remote file datasource. | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
data "scaffolding_data_source" "example" { | ||
sample_attribute = "foo" | ||
data "remotefile_data_source" "bar" { | ||
path = "/tmp/bar.txt" | ||
} | ||
``` | ||
|
||
## Schema | ||
|
||
### Required | ||
|
||
- **sample_attribute** (String, Required) Sample attribute. | ||
- **path** (String, Required) Path to file on remote host. | ||
|
||
### Optional | ||
|
||
- **id** (String, Optional) The ID of this resource. | ||
|
||
|
||
- *none* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,32 @@ | ||
--- | ||
page_title: "scaffolding_resource Resource - terraform-provider-scaffolding" | ||
page_title: "remotefile_resource Resource - terraform-provider-remotefile" | ||
subcategory: "" | ||
description: |- | ||
Sample resource in the Terraform provider scaffolding. | ||
File on remote host. | ||
--- | ||
|
||
# Resource `scaffolding_resource` | ||
# Resource `remotefile_resource` | ||
|
||
Sample resource in the Terraform provider scaffolding. | ||
File on remote host. | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
resource "scaffolding_resource" "example" { | ||
sample_attribute = "foo" | ||
resource "remotefile_resource" "foo" { | ||
path = "/tmp/foo.txt" | ||
content = "bar" | ||
permissions = "0777" | ||
} | ||
``` | ||
|
||
## Schema | ||
|
||
### Optional | ||
### Required | ||
|
||
- **id** (String, Optional) The ID of this resource. | ||
- **sample_attribute** (String, Optional) Sample attribute. | ||
- **path** (String, Required) Path to file on remote host. | ||
- **content** (String, Required) Content of file on remote host. | ||
|
||
### Optional | ||
|
||
- **permissions** (String, Optional) The file permissions. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
data "remotefile_data_source" "bar" { | ||
path = "/tmp/bar.txt" | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
provider "scaffolding" { | ||
# example configuration here | ||
} | ||
provider "remotefile" { | ||
username = "foo" | ||
private_key_path = "~/.ssh/id_rsa" | ||
host = "foo.com" | ||
port = "22" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
resource "remotefile_resource" "foo" { | ||
path = "/tmp/foo.txt" | ||
content = "bar" | ||
permissions = "0777" | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,12 @@ | ||
module github.com/hashicorp/terraform-provider-scaffolding | ||
module github.com/tenstad/terraform-provider-remotefile | ||
|
||
go 1.15 | ||
|
||
require ( | ||
github.com/bramvdbogaerde/go-scp v0.0.0-20210327204631-70ee53679fc9 | ||
github.com/hashicorp/terraform v0.15.1 | ||
github.com/hashicorp/terraform-plugin-docs v0.3.0 | ||
github.com/hashicorp/terraform-plugin-sdk/v2 v2.6.1 | ||
github.com/pkg/sftp v1.13.0 | ||
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package provider | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"hash/fnv" | ||
"strconv" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
func dataSourceRemotefile() *schema.Resource { | ||
return &schema.Resource{ | ||
Description: "Sample data source in the Terraform provider scaffolding.", | ||
|
||
ReadContext: dataSourceRemotefileRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"path": { | ||
Description: "Path to file on remote host.", | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceRemotefileRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
err := resourceRemotefileRead(ctx, d, meta) | ||
|
||
if !err.HasError() { | ||
h := fnv.New32a() | ||
h.Write([]byte(fmt.Sprintf("%s @ %s", d.Get("content"), d.Get("path")))) | ||
d.SetId(strconv.Itoa(int(h.Sum32()))) | ||
} | ||
|
||
return err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package provider | ||
|
||
import ( | ||
"io/ioutil" | ||
"regexp" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
func TestAccDataSourceRemotefile(t *testing.T) { | ||
|
||
resource.UnitTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
ProviderFactories: providerFactories, | ||
Steps: []resource.TestStep{ | ||
{ | ||
PreConfig: func() { | ||
err := ioutil.WriteFile("/tmp/bar.txt", []byte("baz"), 0777) | ||
if err != nil { | ||
t.Fatal("unable to create test file to read") | ||
} | ||
}, | ||
Config: testAccDataSourceRemotefile, | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestMatchResourceAttr( | ||
// TODO: check content is correct | ||
"data.remotefile_data_source.bar", "content", regexp.MustCompile("")), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
const testAccDataSourceRemotefile = ` | ||
data "remotefile_data_source" "bar" { | ||
path = "/tmp/bar.txt" | ||
} | ||
` |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.