Skip to content

Commit

Permalink
Initial version
Browse files Browse the repository at this point in the history
  • Loading branch information
tenstad committed Apr 30, 2021
1 parent 9707bde commit b455387
Show file tree
Hide file tree
Showing 20 changed files with 675 additions and 185 deletions.
18 changes: 8 additions & 10 deletions docs/data-sources/data_source.md
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*
13 changes: 7 additions & 6 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
---
page_title: "scaffolding Provider"
page_title: "remotefile Provider"
subcategory: ""
description: |-
Mangae files on remote hosts
---

# scaffolding Provider


# remotefile Provider

## Example Usage

```terraform
provider "scaffolding" {
# example configuration here
username = "foo"
private_key_path = "~/.ssh/id_rsa"
host = "foo.com"
port = "22"
}
```

Expand Down
23 changes: 14 additions & 9 deletions docs/resources/resource.md
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.
3 changes: 3 additions & 0 deletions examples/data-sources/remotefile_data_source/data-source.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
data "remotefile_data_source" "bar" {
path = "/tmp/bar.txt"
}
3 changes: 0 additions & 3 deletions examples/data-sources/scaffolding_data_source/data-source.tf

This file was deleted.

9 changes: 6 additions & 3 deletions examples/provider/provider.tf
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"
}
5 changes: 5 additions & 0 deletions examples/resources/remotefile_resource/resource.tf
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"
}
3 changes: 0 additions & 3 deletions examples/resources/scaffolding_resource/resource.tf

This file was deleted.

6 changes: 5 additions & 1 deletion go.mod
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
)
338 changes: 338 additions & 0 deletions go.sum

Large diffs are not rendered by default.

39 changes: 39 additions & 0 deletions internal/provider/data_source_remotefile.go
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
}
39 changes: 39 additions & 0 deletions internal/provider/data_source_remotefile_test.go
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"
}
`
36 changes: 0 additions & 36 deletions internal/provider/data_source_scaffolding.go

This file was deleted.

32 changes: 0 additions & 32 deletions internal/provider/data_source_scaffolding_test.go

This file was deleted.

Loading

0 comments on commit b455387

Please sign in to comment.