Giter Club home page Giter Club logo

terraform-provider-scaffolding's Introduction

⚠️ Archived

This template is no longer being maintained and is now archived. We recommend using the terraform-provider-scaffolding-framework template repository built on the Terraform Plugin Framework for new provider development because it offers significant advantages compared to the SDKv2.

Terraform Provider Scaffolding (Terraform Plugin SDK)

This template repository is built on the Terraform Plugin SDK. The template repository built on the Terraform Plugin Framework can be found at terraform-provider-scaffolding-framework.

This repository is a template for a Terraform provider. It is intended as a starting point for creating Terraform providers, containing:

  • A resource, and a data source (internal/provider/),
  • Examples (examples/) and generated documentation (docs/),
  • Miscellaneous meta files.

These files contain boilerplate code that you will need to edit to create your own Terraform provider. Tutorials for creating Terraform providers can be found on the HashiCorp Learn platform.

Please see the GitHub template repository documentation for how to create a new repository from this template on GitHub.

Once you've written your provider, you'll want to publish it on the Terraform Registry so that others can use it.

Requirements

Building The Provider

  1. Clone the repository
  2. Enter the repository directory
  3. Build the provider using the Go install command:
$ go install

Adding Dependencies

This provider uses Go modules. Please see the Go documentation for the most up to date information about using Go modules.

To add a new dependency github.com/author/dependency to your Terraform provider:

go get github.com/author/dependency
go mod tidy

Then commit the changes to go.mod and go.sum.

Using the provider

Fill this in for each provider

Developing the Provider

If you wish to work on the provider, you'll first need Go installed on your machine (see Requirements above).

To compile the provider, run go install. This will build the provider and put the provider binary in the $GOPATH/bin directory.

To generate or update documentation, run go generate.

In order to run the full suite of Acceptance tests, run make testacc.

Note: Acceptance tests create real resources, and often cost money to run.

$ make testacc

terraform-provider-scaffolding's People

Contributors

aareet avatar bflad avatar bgpat avatar bookshelfdave avatar catsby avatar dependabot[bot] avatar hashicorp-copywrite[bot] avatar jaxelr avatar jon-ruckwood avatar justincampbell avatar katbyte avatar kmoe avatar paddycarver avatar paultyng avatar pdecat avatar radeksimko avatar rickducott avatar sbgoods avatar smacfarlane avatar smillerdev avatar trentrosenbaum avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

terraform-provider-scaffolding's Issues

Suggestion: Replace Travis CI with GitHub Actions

Hi, many thanks for refactoring this repo for external audience. We have been using this as a template for a while. Both this repo and terraform-provider-template is mentioned in the docs and they are very similar, but this seemed to be most up to date.

We noticed the Travis CI configuration was removed in some previous pull request. This is feature request / suggestion to add GitHub Actions workflow to replace Travis CI.

Example GitHub Actions workflow (.github/workflows/test.yml):

name: test

on:
  pull_request:
  push:
    branches:
      - master

jobs:
  go-test:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - uses: actions/setup-go@v2-beta
      with:
        go-version: '~1.13'
    - run: go test -v ./...

  golangci-lint:
    runs-on: ubuntu-latest
    container: golangci/golangci-lint:v1.24
    steps:
    - uses: actions/checkout@v2
    - run: golangci-lint run ./...

  tfproviderlint:
    runs-on: ubuntu-latest
    container: bflad/tfproviderlint:0.14
    steps:
    - uses: actions/checkout@v2
    - run: tfproviderlint ./...

Many thanks for considering,

feat: add example of usage of ValidateDiagFunc

Details

An example of

  • how to use this function instead of the old ValidateFunc
  • and how to test it

would be helpful.

Currently, I cannot get it running:

"host_path": {
  Type:             schema.TypeString,
  Optional:         true,
  ForceNew:         true,
  ValidateDiagFunc: validateDockerContainerPath,
},

and the implementation:

func validateDockerContainerPath() schema.SchemaValidateDiagFunc {
	return func(v interface{}, path cty.Path) diag.Diagnostics {
		value := v.(string)
		var diags diag.Diagnostics
		if !regexp.MustCompile(`^[a-zA-Z]:\\|^/`).MatchString(value) {
			diags = append(diags, diag.Errorf("%q must be an absolute path", value)...)
		}

		return diags
	}
}

I get the error

cannot use validateDockerContainerPath (value of type func() schema.SchemaValidateDiagFunc) as schema.SchemaValidateDiagFunc value in struct literal

Versions

  • terraform: v0.14.3
  • github.com/hashicorp/terraform-plugin-sdk/v2 v2.4.0

Links

Error: Could not find valid encryption key packet in key 62b905cxxxxxxx on action github import GPG

Hi there,

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.

Terraform Version

Terraform v0.13.5

Affected Resource(s)

try toiport Key in github action

Terraform Configuration Files

name: release
on:
  push:
    tags:
      - 'v*'
jobs:
  goreleaser:
    runs-on: ubuntu-latest
    steps:
      -
        name: Checkout
        uses: actions/checkout@v2
      -
        name: Unshallow
        run: git fetch --prune --unshallow
      -
        name: Set up Go
        uses: actions/setup-go@v2
        with:
          go-version: 1.14
      -
        name: Import GPG key
        id: import_gpg
        uses: paultyng/[email protected]
        env:
          GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
          PASSPHRASE: ${{ secrets.PASSPHRASE }}
      -
        name: Run GoReleaser
        uses: goreleaser/goreleaser-action@v2
        with:
          version: latest
          args: release --rm-dist
        env:
          GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }}
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Debug Output

Error: Could not find valid encryption key packet in key 62b905cxxxxxxx

Panic Output

Expected Behavior

import gpg private key

Actual Behavior

🔮 Checking GPG private key
Error: Could not find valid encryption key packet in key 62b905cxxxxxxx

Steps to Reproduce

  1. gpg --armor --export-secret-key F1840E7D69CDF54D66XXXXXXXXXXXXXXXXX -w0 | xclip
    2 create secrets on github
  2. git tag -f v0.0.1

Error: did not find expected key

We are trying to build and sign this 3rd party provider, but https://github.com/checkly/terraform-provider-checkly but I think we are missing one step in the setup docs as published here https://www.terraform.io/docs/registry/providers/publishing.html#github-actions-preferred-

Is the Env.GPG_FINGERPRINT actually the same as the mentioned GPG_PRIVATE_KEY?

Debug Output

https://github.com/checkly/terraform-provider-checkly/runs/1209221389?check_suite_focus=true

Expected Behavior

It should build and sign the provider

Actual Behavior

It errors out on not finding the variable GPG_FINGERPRINT - "{{ .Env.GPG_FINGERPRINT }}" # set this environment variable for your signing key

Steps to Reproduce

push a tagged release on the mentioned repo

Bump Development/Build Minimum Go Version to 1.17

Terraform Version

N/A (main branch development)

Description

Following the Go support policy and given the ecosystem availability and stability of the latest Go minor version, it's time to upgrade. This will ensure that this project can use recent improvements to the Go runtime, standard library functionality, and continue to receive security updates

Proposal

  • Run the following commands to upgrade the Go module files and remove deprecated syntax such as //+build:
go mod edit -go=1.17
go mod tidy
go fix
  • Ensure any GitHub Actions workflows (.github/workflows/*.yml) use 1.18 in place of any 1.17 and 1.17 in place of any 1.16 or earlier
  • Ensure the README or any Contributing documentation notes the Go 1.17 expected minimum
  • (Not applicable to all projects) Ensure the .go-version is at least 1.17 or later
  • Enable the tenv linter in .golangci.yml and remediate any issues.

References

Doc: resource_scaffolding.go schema to include list & hash map examples

Documentation unclear on how best to impliment a resource schema beyond string values.

Current Example

resource "scaffolding_resource" "example" {
  sample_attribute = "foo"
}

Desired Example

resource "scaffolding_resource" "example" {
  sample_attribute = "foo"
  sample_list_attribute = [ "foo", "bar" ]
  sample_map_attribute = { foo = "bar" }
}

Terraform Version

Terraform v1.1.7
on darwin_arm64

Affected Resource(s)

Exclude unused goos/goarch flavours from goreleaser config

Suggestion

Add explicit ignores to goreleaser config for the following flavours.

  ignore:
    - goos: darwin
      goarch: '386'
    - goos: darwin
      goarch: 'arm'
    - goos: freebsd
      goarch: 'arm64'
    - goos: windows
      goarch: 'arm'
    - goos: windows
      goarch: 'arm64'

Analysis

Currently, the suggested goreleaser configuration is as below, and go 1.17 builds almost the entire matrix. But the problem is that some of the flavours are not officially supported/endorsed by Terraform, and building them wastes resources and CI credits.

  goos:
    - freebsd
    - windows
    - linux
    - darwin
  goarch:
    - amd64
    - '386'
    - arm
    - arm64
  ignore:
    - goos: darwin
      goarch: '386'

According to the provider docs that link to this project, only the following flavours need to be built:

goos\goarch amd64 386 arm arm64
darwin x x
freebsd x x
linux x x x x
windows x x

Looking at what various providers push to Terraform registry, it's the same matrix, but with one addition: freebsd_arm.
For example, here and here. Hence the suggested list of explicit ignores to align with the current state.

Publishing releases to Terraform Registry stopped working

Sorry for opening this here, but it seems impossible to reach [email protected] (we've emailed too).

We are not able to publish new versions to cloudamqp/cloudamqp. It started with a release that wasn't picked up by the registry, similar to hashicorp/terraform#27533.

In my efforts to try to solve that, I read the following and removed the webhook from our repo, hoping I would be able to re-add it.

If the webhook is missing or not functioning, you can use the Resync button on the provider settings page. First, remove any existing webhooks for registry.terraform.io. Then, click the Resync button on the Terraform Registry's provider settings page. A new webhook should be created.

Problem is, I can't see any Resync button anywhere. How can we get the webhook back? How can get publishing releases to Terraform Registry working again?

Thanks for your time.


cc @bflad @paddycarver sorry to mention you, but I saw you were active here yesterday and I'm a bit desperate to be honest

Bump Go Version to 1.18

Description

Following the Go support policy and given the ecosystem availability of the latest Go minor version, it's time to upgrade. This will ensure that this project can use recent improvements to the Go runtime, standard library functionality, and continue to receive security updates

Proposal

  • Run the following commands to upgrade the Go module files and automatically fix outdated Go code:
go mod edit -go=1.18
go mod tidy
go fix ./...
  • Ensure any GitHub Actions workflows (.github/workflows/*.yml) use 1.19 in place of any 1.18 and 1.18 in place of any 1.17 or earlier
  • Ensure the README or any Contributing documentation notes the Go 1.18 expected minimum
  • (Not applicable to all projects) Ensure the .go-version is at least 1.18 or later

References

The page of “Writing Custom Providers” DOES NOT exist

The page of “Writing Custom Providers” DOES NOT exist which is describe in “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.”

Terraform Custom Provider Use Factories to Test

Hi there,

I’m creating a new Provider, but i have some doubts in provider Factories.

I’m following terraform-provider-scaffolding so in provider_test.go i have the following:

var providerFactories = map[string]func() (*schema.Provider, error){
    "acdcn": func() (*schema.Provider, error) {
        return New("dev")(), nil
    },
}

Then in resource test file i would like access to Provider to be able to use my api client to delete the created resource. I’m trying the following:

provider, err := providerFactories["acdcn"]()

apiClient := provider.Meta().(*client.Client)

But the provider.Meta() is always nil. How i can access to my api client configured in provider?

The Test works well, the resource is created, but i’m unable to destroy the resource inside function configured in CheckDestroy.

Thanks

[PROPOSAL] Switch to Go Modules

As part of the preparation for Terraform v0.12, we would like to migrate all providers to use Go Modules. We plan to continue checking dependencies into vendor/ to remain compatible with existing tooling/CI for a period of time, however go modules will be used for management. Go Modules is the official solution for the go programming language, we understand some providers might not want this change yet, however we encourage providers to begin looking towards the switch as this is how we will be managing all Go projects in the future. Would maintainers please react with 👍 for support, or 👎 if you wish to have this provider omitted from the first wave of pull requests. If your provider is in support, we would ask that you avoid merging any pull requests that mutate the dependencies while the Go Modules PR is open (in fact a total codefreeze would be even more helpful), otherwise we will need to close that PR and re-run go mod init. Once merged, dependencies can be added or updated as follows:

$ GO111MODULE=on go get github.com/some/module@master
$ GO111MODULE=on go mod tidy
$ GO111MODULE=on go mod vendor

GO111MODULE=on might be unnecessary depending on your environment, this example will fetch a module @ master and record it in your project's go.mod and go.sum files. It's a good idea to tidy up afterward and then copy the dependencies into vendor/. To remove dependencies from your project, simply remove all usage from your codebase and run:

$ GO111MODULE=on go mody tidy
$ GO111MODULE=on go mod vendor

Thank you sincerely for all your time, contributions, and cooperation!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.