Skip to content

Commit

Permalink
Overhaul for v2 SDK and registry
Browse files Browse the repository at this point in the history
  • Loading branch information
paultyng committed Aug 20, 2020
1 parent 2700d65 commit 7249c97
Show file tree
Hide file tree
Showing 15 changed files with 636 additions and 277 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: goreleaser

on:
push:
tags:
- 'v*'
jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/[email protected]
-
name: Unshallow
run: git fetch --prune --unshallow
-
name: Set up Go
uses: actions/[email protected]
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 }}
40 changes: 40 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
builds:
- env:
- CGO_ENABLED=0
mod_timestamp: '{{ .CommitTimestamp }}'
flags:
- -trimpath
ldflags:
- '-s -w -X main.version={{.Version}} -X main.commit={{.Commit}}'
goos:
- freebsd
- windows
- linux
- darwin
goarch:
- amd64
- '386'
- arm
- arm64
ignore:
- goos: darwin
goarch: '386'
binary: '{{ .ProjectName }}_v{{ .Version }}'
archives:
- format: zip
name_template: '{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}'
checksum:
name_template: '{{ .ProjectName }}_{{ .Version }}_SHA256SUMS'
algorithm: sha256
signs:
- artifacts: checksum
args:
- "--batch"
- "--local-user"
- "{{ .Env.GPG_FINGERPRINT }}"
- "--output"
- "${signature}"
- "--detach-sign"
- "${artifact}"
changelog:
skip: true
15 changes: 1 addition & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
# Terraform Provider for Local Git Repository

## Usage

```hcl
data "git_repository" "tf" {
path = "${path.module}"
}
resource "aws_vpc" "main" {
tags = {
git_commit = "${data.git_repository.tf.commit_hash}"
git_branch = "${data.git_repository.tf.branch}"
}
}
```
[Available in the Terraform Registry](https://registry.terraform.io/providers/paultyng/git/latest)
32 changes: 32 additions & 0 deletions docs/data-sources/repository.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
page_title: "git_repository Data Source - terraform-provider-git"
subcategory: ""
description: |-
---

# Data Source `git_repository`



## Example Usage

```terraform
data "git_repository" "tf" {
path = "${path.module}"
}
```

## Schema

### Optional

- **id** (String, Optional) The ID of this resource.
- **path** (String, Optional) Path to the .git directory

### Read-only

- **branch** (String, Read-only)
- **commit_hash** (String, Read-only)


21 changes: 21 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
layout: ""
page_title: "Provider: Git"
description: |-
The Git provider provides resources to interact with a local Git repository.
---

# Git Provider

The Git provider provides resources to interact with a local Git repository. Primarily this is useful
for using your current commit hash or tag in resource labeling, etc.

## Example Usage

```terraform
data "git_repository" "tf" {
path = "${path.module}"
}
```

## Schema
3 changes: 3 additions & 0 deletions examples/data-sources/git_repository/data-source.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
data "git_repository" "tf" {
path = "${path.module}"
}
11 changes: 4 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
module github.com/paultyng/terraform-provider-git

go 1.15

require (
github.com/emirpasic/gods v1.12.0 // indirect
github.com/hashicorp/terraform v0.12.0-alpha4.0.20190109165911-cdf7cc2449c9
github.com/kr/pty v1.1.3 // indirect
github.com/hashicorp/terraform-plugin-docs v0.1.3
github.com/hashicorp/terraform-plugin-sdk/v2 v2.0.1
github.com/pkg/errors v0.8.1 // indirect
github.com/stretchr/objx v0.1.1 // indirect
github.com/stretchr/testify v1.3.0 // indirect
golang.org/x/crypto v0.0.0-20190103213133-ff983b9c42bc // indirect
golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e // indirect
golang.org/x/sys v0.0.0-20190109145017-48ac38b7c8cb // indirect
gopkg.in/src-d/go-billy.v4 v4.3.0 // indirect
gopkg.in/src-d/go-git-fixtures.v3 v3.3.0 // indirect
gopkg.in/src-d/go-git.v4 v4.8.1
Expand Down
696 changes: 456 additions & 240 deletions go.sum

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package provider
import (
"log"

"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
git "gopkg.in/src-d/go-git.v4"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,10 @@ import (
"strings"
"testing"

"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

var testProviders = map[string]terraform.ResourceProvider{
"git": Provider(),
}

func execGit(t *testing.T, arg ...string) string {
t.Helper()

Expand All @@ -31,13 +27,18 @@ func TestDataSourceRepository(t *testing.T) {
if err != nil {
t.Fatal(err)
}
dir = filepath.Join(dir, "..")
dir = filepath.Join(dir, "../..")
dir = filepath.ToSlash(dir)

expectedBranch := execGit(t, "rev-parse", "--abbrev-ref", "HEAD")
expectedCommit := execGit(t, "rev-parse", "HEAD")

resource.UnitTest(t, resource.TestCase{
Providers: testProviders,
ProviderFactories: map[string]func() (*schema.Provider, error){
"git": func() (*schema.Provider, error) {
return New(), nil
},
},
Steps: []resource.TestStep{
{
Config: testDataSourceRepositoryConfig(dir),
Expand All @@ -52,7 +53,7 @@ func TestDataSourceRepository(t *testing.T) {

func testDataSourceRepositoryConfig(path string) string {
return fmt.Sprintf(`
data git_repository test {
data "git_repository" "test" {
path = "%s"
}
`, path)
Expand Down
5 changes: 2 additions & 3 deletions provider/provider.go → internal/provider/provider.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package provider

import (
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/terraform"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func Provider() terraform.ResourceProvider {
func New() *schema.Provider {
return &schema.Provider{
DataSourcesMap: map[string]*schema.Resource{
"git_repository": dataSourceRepository(),
Expand Down
File renamed without changes.
8 changes: 5 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package main

import (
"github.com/hashicorp/terraform/plugin"
"github.com/paultyng/terraform-provider-git/provider"
"github.com/hashicorp/terraform-plugin-sdk/v2/plugin"

"github.com/paultyng/terraform-provider-git/internal/provider"
)

func main() {
plugin.Serve(&plugin.ServeOpts{
ProviderFunc: provider.Provider})
ProviderFunc: provider.New,
})
}
17 changes: 17 additions & 0 deletions templates/index.md.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
layout: ""
page_title: "Provider: Git"
description: |-
The Git provider provides resources to interact with a local Git repository.
---

# Git Provider

The Git provider provides resources to interact with a local Git repository. Primarily this is useful
for using your current commit hash or tag in resource labeling, etc.

## Example Usage

{{tffile "examples/data-sources/git_repository/data-source.tf"}}

{{ .SchemaMarkdown | trimspace }}
7 changes: 7 additions & 0 deletions tools/tools.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// +build tools

package tools

import (
_ "github.com/hashicorp/terraform-plugin-docs/cmd/tfpluginwebsite"
)

0 comments on commit 7249c97

Please sign in to comment.