Skip to content

Commit 820daaf

Browse files
committedJan 7, 2021
Initial commit
0 parents  commit 820daaf

29 files changed

+1776
-0
lines changed
 

‎.github/CODE_OF_CONDUCT.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Code of Conduct
2+
3+
HashiCorp Community Guidelines apply to you when interacting with the community here on GitHub and contributing code.
4+
5+
Please read the full text at https://www.hashicorp.com/community-guidelines

‎.github/ISSUE_TEMPLATE.md

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
Hi there,
2+
3+
Thank you for opening an issue. Please note that we try to keep the Terraform issue tracker reserved for bug reports and feature requests. For general usage questions, please see: https://www.terraform.io/community.html.
4+
5+
### Terraform Version
6+
Run `terraform -v` to show the version. If you are not running the latest version of Terraform, please upgrade because your issue may have already been fixed.
7+
8+
### Affected Resource(s)
9+
Please list the resources as a list, for example:
10+
- opc_instance
11+
- opc_storage_volume
12+
13+
If this issue appears to affect multiple resources, it may be an issue with Terraform's core, so please mention this.
14+
15+
### Terraform Configuration Files
16+
```hcl
17+
# Copy-paste your Terraform configurations here - for large Terraform configs,
18+
# please use a service like Dropbox and share a link to the ZIP file. For
19+
# security, you can also encrypt the files using our GPG public key.
20+
```
21+
22+
### Debug Output
23+
Please provider a link to a GitHub Gist containing the complete debug output: https://www.terraform.io/docs/internals/debugging.html. Please do NOT paste the debug output in the issue; just paste a link to the Gist.
24+
25+
### Panic Output
26+
If Terraform produced a panic, please provide a link to a GitHub Gist containing the output of the `crash.log`.
27+
28+
### Expected Behavior
29+
What should have happened?
30+
31+
### Actual Behavior
32+
What actually happened?
33+
34+
### Steps to Reproduce
35+
Please list the steps required to reproduce the issue, for example:
36+
1. `terraform apply`
37+
38+
### Important Factoids
39+
Are there anything atypical about your accounts that we should know? For example: Running in EC2 Classic? Custom version of OpenStack? Tight ACLs?
40+
41+
### References
42+
Are there any other GitHub issues (open or closed) or Pull Requests that should be linked here? For example:
43+
- GH-1234

‎.github/dependabot.yml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# See GitHub's docs for more information on this file:
2+
# https://docs.github.com/en/free-pro-team@latest/github/administering-a-repository/configuration-options-for-dependency-updates
3+
version: 2
4+
updates:
5+
# Maintain dependencies for GitHub Actions
6+
- package-ecosystem: "github-actions"
7+
directory: "/"
8+
schedule:
9+
# Check for updates to GitHub Actions every weekday
10+
interval: "daily"
11+
12+
# Maintain dependencies for Go modules
13+
- package-ecosystem: "gomod"
14+
directory: "/"
15+
schedule:
16+
# Check for updates to Go modules every weekday
17+
interval: "daily"

‎.github/workflows/release.yml

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# This GitHub action can publish assets for release when a tag is created.
2+
# Currently its setup to run on any tag that matches the pattern "v*" (ie. v0.1.0).
3+
#
4+
# This uses an action (paultyng/ghaction-import-gpg) that assumes you set your
5+
# private key in the `GPG_PRIVATE_KEY` secret and passphrase in the `PASSPHRASE`
6+
# secret. If you would rather own your own GPG handling, please fork this action
7+
# or use an alternative one for key handling.
8+
#
9+
# You will need to pass the `--batch` flag to `gpg` in your signing step
10+
# in `goreleaser` to indicate this is being used in a non-interactive mode.
11+
#
12+
name: release
13+
on:
14+
push:
15+
tags:
16+
- 'v*'
17+
jobs:
18+
goreleaser:
19+
runs-on: ubuntu-latest
20+
steps:
21+
-
22+
name: Checkout
23+
uses: actions/checkout@v2
24+
-
25+
name: Unshallow
26+
run: git fetch --prune --unshallow
27+
-
28+
name: Set up Go
29+
uses: actions/setup-go@v2
30+
with:
31+
go-version: 1.14
32+
-
33+
name: Import GPG key
34+
id: import_gpg
35+
uses: paultyng/ghaction-import-gpg@v2.1.0
36+
env:
37+
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
38+
PASSPHRASE: ${{ secrets.PASSPHRASE }}
39+
-
40+
name: Run GoReleaser
41+
uses: goreleaser/goreleaser-action@v2
42+
with:
43+
version: latest
44+
args: release --rm-dist
45+
env:
46+
GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }}
47+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

‎.github/workflows/test.yml

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# This GitHub action runs your tests for each commit push and/or PR. Optionally
2+
# you can turn it on using a cron schedule for regular testing.
3+
#
4+
name: Tests
5+
on:
6+
pull_request:
7+
paths-ignore:
8+
- 'README.md'
9+
push:
10+
paths-ignore:
11+
- 'README.md'
12+
# For systems with an upstream API that could drift unexpectedly (like most SaaS systems, etc.),
13+
# we recommend testing at a regular interval not necessarily tied to code changes. This will
14+
# ensure you are alerted to something breaking due to an API change, even if the code did not
15+
# change.
16+
# schedule:
17+
# - cron: '0 13 * * *'
18+
jobs:
19+
# ensure the code builds...
20+
build:
21+
name: Build
22+
runs-on: ubuntu-latest
23+
timeout-minutes: 5
24+
steps:
25+
26+
- name: Set up Go
27+
uses: actions/setup-go@v2.1.3
28+
with:
29+
go-version: '1.15'
30+
id: go
31+
32+
- name: Check out code into the Go module directory
33+
uses: actions/checkout@v2.3.3
34+
35+
- name: Get dependencies
36+
run: |
37+
go mod download
38+
39+
- name: Build
40+
run: |
41+
go build -v .
42+
43+
# run acceptance tests in a matrix with Terraform core versions
44+
test:
45+
name: Matrix Test
46+
needs: build
47+
runs-on: ubuntu-latest
48+
timeout-minutes: 15
49+
strategy:
50+
fail-fast: false
51+
matrix:
52+
# list whatever Terraform versions here you would like to support
53+
terraform:
54+
- '0.12.29'
55+
- '0.13.4'
56+
- '0.14.0-beta2'
57+
steps:
58+
59+
- name: Set up Go
60+
uses: actions/setup-go@v2.1.3
61+
with:
62+
go-version: '1.15'
63+
id: go
64+
65+
- name: Check out code into the Go module directory
66+
uses: actions/checkout@v2.3.3
67+
68+
- name: Get dependencies
69+
run: |
70+
go mod download
71+
72+
- name: TF acceptance tests
73+
timeout-minutes: 10
74+
env:
75+
TF_ACC: "1"
76+
TF_ACC_TERRAFORM_VERSION: ${{ matrix.terraform }}
77+
78+
# Set whatever additional acceptance test env vars here. You can
79+
# optionally use data from your repository secrets using the
80+
# following syntax:
81+
# SOME_VAR: ${{ secrets.SOME_VAR }}
82+
83+
run: |
84+
go test -v -cover ./internal/provider/

‎.gitignore

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
*.dll
2+
*.exe
3+
.DS_Store
4+
example.tf
5+
terraform.tfplan
6+
terraform.tfstate
7+
bin/
8+
dist/
9+
modules-dev/
10+
/pkg/
11+
website/.vagrant
12+
website/.bundle
13+
website/build
14+
website/node_modules
15+
.vagrant/
16+
*.backup
17+
./*.tfstate
18+
.terraform/
19+
*.log
20+
*.bak
21+
*~
22+
.*.swp
23+
.idea
24+
*.iml
25+
*.test
26+
*.iml
27+
28+
website/vendor
29+
30+
# Test exclusions
31+
!command/test-fixtures/**/*.tfstate
32+
!command/test-fixtures/**/.terraform/
33+
34+
# Keep windows files with windows line endings
35+
*.winfile eol=crlf

‎.goreleaser.yml

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Visit https://goreleaser.com for documentation on how to customize this
2+
# behavior.
3+
before:
4+
hooks:
5+
# this is just an example and not a requirement for provider building/publishing
6+
- go mod tidy
7+
builds:
8+
- env:
9+
# goreleaser does not work with CGO, it could also complicate
10+
# usage by users in CI/CD systems like Terraform Cloud where
11+
# they are unable to install libraries.
12+
- CGO_ENABLED=0
13+
mod_timestamp: '{{ .CommitTimestamp }}'
14+
flags:
15+
- -trimpath
16+
ldflags:
17+
- '-s -w -X main.version={{.Version}} -X main.commit={{.Commit}}'
18+
goos:
19+
- freebsd
20+
- windows
21+
- linux
22+
- darwin
23+
goarch:
24+
- amd64
25+
- '386'
26+
- arm
27+
- arm64
28+
ignore:
29+
- goos: darwin
30+
goarch: '386'
31+
binary: '{{ .ProjectName }}_v{{ .Version }}'
32+
archives:
33+
- format: zip
34+
name_template: '{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}'
35+
checksum:
36+
name_template: '{{ .ProjectName }}_{{ .Version }}_SHA256SUMS'
37+
algorithm: sha256
38+
signs:
39+
- artifacts: checksum
40+
args:
41+
# if you are using this in a GitHub action or some other automated pipeline, you
42+
# need to pass the batch flag to indicate its not interactive.
43+
- "--batch"
44+
- "--local-user"
45+
- "{{ .Env.GPG_FINGERPRINT }}" # set this environment variable for your signing key
46+
- "--output"
47+
- "${signature}"
48+
- "--detach-sign"
49+
- "${artifact}"
50+
release:
51+
# If you want to manually examine the release before its live, uncomment this line:
52+
# draft: true
53+
changelog:
54+
skip: true

‎.vscode/launch.json

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "Acceptance Tests",
9+
"type": "go",
10+
"request": "launch",
11+
"mode": "test",
12+
// this assumes your workspace is the root of the repo
13+
"program": "${fileDirname}",
14+
"env": {
15+
"TF_ACC": "1",
16+
},
17+
"args": [],
18+
},
19+
{
20+
"name": "Debug - Attach External CLI",
21+
"type": "go",
22+
"request": "launch",
23+
"mode": "debug",
24+
// this assumes your workspace is the root of the repo
25+
"program": "${workspaceFolder}",
26+
"env": {},
27+
"args": [
28+
// pass the debug flag for reattaching
29+
"-debug",
30+
],
31+
}
32+
]
33+
}

‎CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## 0.1.0 (Unreleased)
2+
3+
BACKWARDS INCOMPATIBILITIES / NOTES:

‎GNUmakefile

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
default: testacc
2+
3+
# Run acceptance tests
4+
.PHONY: testacc
5+
testacc:
6+
TF_ACC=1 go test ./... -v $(TESTARGS) -timeout 120m

‎LICENSE

+373
Large diffs are not rendered by default.

‎README.md

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Terraform Provider Scaffolding
2+
3+
This repository is a *template* for a [Terraform](https://www.terraform.io) provider. It is intended as a starting point for creating Terraform providers, containing:
4+
5+
- A resource, and a data source (`internal/provider/`),
6+
- Examples (`examples/`) and generated documentation (`docs/`),
7+
- Miscellanious meta files.
8+
9+
These files contain boilerplate code that you will need to edit to create your own Terraform provider. A full guide to creating Terraform providers can be found at [Writing Custom Providers](https://www.terraform.io/docs/extend/writing-custom-providers.html).
10+
11+
Please see the [GitHub template repository documentation](https://help.github.com/en/github/creating-cloning-and-archiving-repositories/creating-a-repository-from-a-template) for how to create a new repository from this template on GitHub.
12+
13+
Once you've written your provider, you'll want to [publish it on the Terraform Registry](https://www.terraform.io/docs/registry/providers/publishing.html) so that others can use it.
14+
15+
16+
## Requirements
17+
18+
- [Terraform](https://www.terraform.io/downloads.html) >= 0.13.x
19+
- [Go](https://golang.org/doc/install) >= 1.15
20+
21+
## Building The Provider
22+
23+
1. Clone the repository
24+
1. Enter the repository directory
25+
1. Build the provider using the Go `install` command:
26+
```sh
27+
$ go install
28+
```
29+
30+
## Adding Dependencies
31+
32+
This provider uses [Go modules](https://github.com/golang/go/wiki/Modules).
33+
Please see the Go documentation for the most up to date information about using Go modules.
34+
35+
To add a new dependency `github.com/author/dependency` to your Terraform provider:
36+
37+
```
38+
go get github.com/author/dependency
39+
go mod tidy
40+
```
41+
42+
Then commit the changes to `go.mod` and `go.sum`.
43+
44+
## Using the provider
45+
46+
Fill this in for each provider
47+
48+
## Developing the Provider
49+
50+
If you wish to work on the provider, you'll first need [Go](http://www.golang.org) installed on your machine (see [Requirements](#requirements) above).
51+
52+
To compile the provider, run `go install`. This will build the provider and put the provider binary in the `$GOPATH/bin` directory.
53+
54+
To generate or update documentation, run `go generate`.
55+
56+
In order to run the full suite of Acceptance tests, run `make testacc`.
57+
58+
*Note:* Acceptance tests create real resources, and often cost money to run.
59+
60+
```sh
61+
$ make testacc
62+
```

‎docs/data-sources/data_source.md

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
page_title: "scaffolding_data_source Data Source - terraform-provider-scaffolding"
3+
subcategory: ""
4+
description: |-
5+
Sample data source in the Terraform provider scaffolding.
6+
---
7+
8+
# Data Source `scaffolding_data_source`
9+
10+
Sample data source in the Terraform provider scaffolding.
11+
12+
## Example Usage
13+
14+
```terraform
15+
data "scaffolding_data_source" "example" {
16+
sample_attribute = "foo"
17+
}
18+
```
19+
20+
## Schema
21+
22+
### Required
23+
24+
- **sample_attribute** (String, Required) Sample attribute.
25+
26+
### Optional
27+
28+
- **id** (String, Optional) The ID of this resource.
29+
30+

‎docs/index.md

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
page_title: "scaffolding Provider"
3+
subcategory: ""
4+
description: |-
5+
6+
---
7+
8+
# scaffolding Provider
9+
10+
11+
12+
## Example Usage
13+
14+
```terraform
15+
provider "scaffolding" {
16+
# example configuration here
17+
}
18+
```
19+
20+
## Schema

‎docs/resources/resource.md

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
page_title: "scaffolding_resource Resource - terraform-provider-scaffolding"
3+
subcategory: ""
4+
description: |-
5+
Sample resource in the Terraform provider scaffolding.
6+
---
7+
8+
# Resource `scaffolding_resource`
9+
10+
Sample resource in the Terraform provider scaffolding.
11+
12+
## Example Usage
13+
14+
```terraform
15+
resource "scaffolding_resource" "example" {
16+
sample_attribute = "foo"
17+
}
18+
```
19+
20+
## Schema
21+
22+
### Optional
23+
24+
- **id** (String, Optional) The ID of this resource.
25+
- **sample_attribute** (String, Optional) Sample attribute.
26+
27+

‎examples/README.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Examples
2+
3+
This directory contains examples that are mostly used for documentation, but can also be run/tested manually via the Terraform CLI.
4+
5+
The document generation tool looks for files in the following locations by default. All other *.tf files besides the ones mentioned below are ignored by the documentation tool. This is useful for creating examples that can run and/or ar testable even if some parts are not relevant for the documentation.
6+
7+
* **provider/provider.tf** example file for the provider index page
8+
* **data-sources/<full data source name>/data-source.tf** example file for the named data source page
9+
* **resources/<full resource name>/resource.tf** example file for the named data source page
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
data "scaffolding_data_source" "example" {
2+
sample_attribute = "foo"
3+
}

‎examples/provider/provider.tf

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
provider "scaffolding" {
2+
# example configuration here
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
resource "scaffolding_resource" "example" {
2+
sample_attribute = "foo"
3+
}

‎go.mod

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module github.com/hashicorp/terraform-provider-scaffolding
2+
3+
go 1.15
4+
5+
require (
6+
github.com/hashicorp/terraform-plugin-docs v0.3.0
7+
github.com/hashicorp/terraform-plugin-sdk/v2 v2.4.0
8+
)

‎go.sum

+609
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package provider
2+
3+
import (
4+
"context"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
7+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
8+
)
9+
10+
func dataSourceScaffolding() *schema.Resource {
11+
return &schema.Resource{
12+
// This description is used by the documentation generator and the language server.
13+
Description: "Sample data source in the Terraform provider scaffolding.",
14+
15+
ReadContext: dataSourceScaffoldingRead,
16+
17+
Schema: map[string]*schema.Schema{
18+
"sample_attribute": {
19+
// This description is used by the documentation generator and the language server.
20+
Description: "Sample attribute.",
21+
Type: schema.TypeString,
22+
Required: true,
23+
},
24+
},
25+
}
26+
}
27+
28+
func dataSourceScaffoldingRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
29+
// use the meta value to retrieve your client from the provider configure method
30+
// client := meta.(*apiClient)
31+
32+
idFromAPI := "my-id"
33+
d.SetId(idFromAPI)
34+
35+
return diag.Errorf("not implemented")
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package provider
2+
3+
import (
4+
"regexp"
5+
"testing"
6+
7+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
8+
)
9+
10+
func TestAccDataSourceScaffolding(t *testing.T) {
11+
t.Skip("data source not yet implemented, remove this once you add your own code")
12+
13+
resource.UnitTest(t, resource.TestCase{
14+
PreCheck: func() { testAccPreCheck(t) },
15+
ProviderFactories: providerFactories,
16+
Steps: []resource.TestStep{
17+
{
18+
Config: testAccDataSourceScaffolding,
19+
Check: resource.ComposeTestCheckFunc(
20+
resource.TestMatchResourceAttr(
21+
"data.scaffolding_data_source.foo", "sample_attribute", regexp.MustCompile("^ba")),
22+
),
23+
},
24+
},
25+
})
26+
}
27+
28+
const testAccDataSourceScaffolding = `
29+
data "scaffolding_data_source" "foo" {
30+
sample_attribute = "bar"
31+
}
32+
`

‎internal/provider/provider.go

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package provider
2+
3+
import (
4+
"context"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
7+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
8+
)
9+
10+
func init() {
11+
// Set descriptions to support markdown syntax, this will be used in document generation
12+
// and the language server.
13+
schema.DescriptionKind = schema.StringMarkdown
14+
15+
// Customize the content of descriptions when output. For example you can add defaults on
16+
// to the exported descriptions if present.
17+
// schema.SchemaDescriptionBuilder = func(s *schema.Schema) string {
18+
// desc := s.Description
19+
// if s.Default != nil {
20+
// desc += fmt.Sprintf(" Defaults to `%v`.", s.Default)
21+
// }
22+
// return strings.TrimSpace(desc)
23+
// }
24+
}
25+
26+
func New(version string) func() *schema.Provider {
27+
return func() *schema.Provider {
28+
p := &schema.Provider{
29+
DataSourcesMap: map[string]*schema.Resource{
30+
"scaffolding_data_source": dataSourceScaffolding(),
31+
},
32+
ResourcesMap: map[string]*schema.Resource{
33+
"scaffolding_resource": resourceScaffolding(),
34+
},
35+
}
36+
37+
p.ConfigureContextFunc = configure(version, p)
38+
39+
return p
40+
}
41+
}
42+
43+
type apiClient struct {
44+
// Add whatever fields, client or connection info, etc. here
45+
// you would need to setup to communicate with the upstream
46+
// API.
47+
}
48+
49+
func configure(version string, p *schema.Provider) func(context.Context, *schema.ResourceData) (interface{}, diag.Diagnostics) {
50+
return func(context.Context, *schema.ResourceData) (interface{}, diag.Diagnostics) {
51+
// Setup a User-Agent for your API client (replace the provider name for yours):
52+
// userAgent := p.UserAgent("terraform-provider-scaffolding", version)
53+
// TODO: myClient.UserAgent = userAgent
54+
55+
return &apiClient{}, nil
56+
}
57+
}

‎internal/provider/provider_test.go

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package provider
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
7+
)
8+
9+
// providerFactories are used to instantiate a provider during acceptance testing.
10+
// The factory function will be invoked for every Terraform CLI command executed
11+
// to create a provider server to which the CLI can reattach.
12+
var providerFactories = map[string]func() (*schema.Provider, error){
13+
"scaffolding": func() (*schema.Provider, error) {
14+
return New("dev")(), nil
15+
},
16+
}
17+
18+
func TestProvider(t *testing.T) {
19+
if err := New("dev")().InternalValidate(); err != nil {
20+
t.Fatalf("err: %s", err)
21+
}
22+
}
23+
24+
func testAccPreCheck(t *testing.T) {
25+
// You can add code here to run prior to any test case execution, for example assertions
26+
// about the appropriate environment variables being set are common to see in a pre-check
27+
// function.
28+
}
+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package provider
2+
3+
import (
4+
"context"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
7+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
8+
)
9+
10+
func resourceScaffolding() *schema.Resource {
11+
return &schema.Resource{
12+
// This description is used by the documentation generator and the language server.
13+
Description: "Sample resource in the Terraform provider scaffolding.",
14+
15+
CreateContext: resourceScaffoldingCreate,
16+
ReadContext: resourceScaffoldingRead,
17+
UpdateContext: resourceScaffoldingUpdate,
18+
DeleteContext: resourceScaffoldingDelete,
19+
20+
Schema: map[string]*schema.Schema{
21+
"sample_attribute": {
22+
// This description is used by the documentation generator and the language server.
23+
Description: "Sample attribute.",
24+
Type: schema.TypeString,
25+
Optional: true,
26+
},
27+
},
28+
}
29+
}
30+
31+
func resourceScaffoldingCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
32+
// use the meta value to retrieve your client from the provider configure method
33+
// client := meta.(*apiClient)
34+
35+
idFromAPI := "my-id"
36+
d.SetId(idFromAPI)
37+
38+
return diag.Errorf("not implemented")
39+
}
40+
41+
func resourceScaffoldingRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
42+
// use the meta value to retrieve your client from the provider configure method
43+
// client := meta.(*apiClient)
44+
45+
return diag.Errorf("not implemented")
46+
}
47+
48+
func resourceScaffoldingUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
49+
// use the meta value to retrieve your client from the provider configure method
50+
// client := meta.(*apiClient)
51+
52+
return diag.Errorf("not implemented")
53+
}
54+
55+
func resourceScaffoldingDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
56+
// use the meta value to retrieve your client from the provider configure method
57+
// client := meta.(*apiClient)
58+
59+
return diag.Errorf("not implemented")
60+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package provider
2+
3+
import (
4+
"regexp"
5+
"testing"
6+
7+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
8+
)
9+
10+
func TestAccResourceScaffolding(t *testing.T) {
11+
t.Skip("resource not yet implemented, remove this once you add your own code")
12+
13+
resource.UnitTest(t, resource.TestCase{
14+
PreCheck: func() { testAccPreCheck(t) },
15+
ProviderFactories: providerFactories,
16+
Steps: []resource.TestStep{
17+
{
18+
Config: testAccResourceScaffolding,
19+
Check: resource.ComposeTestCheckFunc(
20+
resource.TestMatchResourceAttr(
21+
"scaffolding_resource.foo", "sample_attribute", regexp.MustCompile("^ba")),
22+
),
23+
},
24+
},
25+
})
26+
}
27+
28+
const testAccResourceScaffolding = `
29+
resource "scaffolding_resource" "foo" {
30+
sample_attribute = "bar"
31+
}
32+
`

‎main.go

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"flag"
6+
"log"
7+
8+
"github.com/hashicorp/terraform-plugin-sdk/v2/plugin"
9+
"github.com/hashicorp/terraform-provider-scaffolding/internal/provider"
10+
)
11+
12+
// Run "go generate" to format example terraform files and generate the docs for the registry/website
13+
14+
// If you do not have terraform installed, you can remove the formatting command, but its suggested to
15+
// ensure the documentation is formatted properly.
16+
//go:generate terraform fmt -recursive ./examples/
17+
18+
// Run the docs generation tool, check its repository for more information on how it works and how docs
19+
// can be customized.
20+
//go:generate go run github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs
21+
22+
var (
23+
// these will be set by the goreleaser configuration
24+
// to appropriate values for the compiled binary
25+
version string = "dev"
26+
27+
// goreleaser can also pass the specific commit if you want
28+
// commit string = ""
29+
)
30+
31+
func main() {
32+
var debugMode bool
33+
34+
flag.BoolVar(&debugMode, "debug", false, "set to true to run the provider with support for debuggers like delve")
35+
flag.Parse()
36+
37+
opts := &plugin.ServeOpts{ProviderFunc: provider.New(version)}
38+
39+
if debugMode {
40+
// TODO: update this string with the full name of your provider as used in your configs
41+
err := plugin.Debug(context.Background(), "registry.terraform.io/hashicorp/scaffolding", opts)
42+
if err != nil {
43+
log.Fatal(err.Error())
44+
}
45+
return
46+
}
47+
48+
plugin.Serve(opts)
49+
}

‎tools/tools.go

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// +build tools
2+
3+
package tools
4+
5+
import (
6+
// document generation
7+
_ "github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs"
8+
)

0 commit comments

Comments
 (0)
Please sign in to comment.