Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Breaking change: SDK v2 #42

Merged
merged 6 commits into from
Oct 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .go-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.11.5
1.15.2
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ services:
- docker
language: go
go:
- "1.11.x"
- stable
- tip

env:
- GO111MODULE=on GOFLAGS=-mod=vendor
Expand All @@ -19,7 +20,7 @@ install:
script:
- make test
- make vet
- make website-test
- make testacc

branches:
only:
Expand Down
18 changes: 1 addition & 17 deletions GNUmakefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
TEST?=$$(go list ./... |grep -v 'vendor')
GOFMT_FILES?=$$(find . -name '*.go' |grep -v vendor)
WEBSITE_REPO=github.com/hashicorp/terraform-website
PKG_NAME=local

default: build
Expand Down Expand Up @@ -43,19 +42,4 @@ test-compile:
fi
go test -c $(TEST) $(TESTARGS)

website:
ifeq (,$(wildcard $(GOPATH)/src/$(WEBSITE_REPO)))
echo "$(WEBSITE_REPO) not found in your GOPATH (necessary for layouts and assets), get-ting..."
git clone https://$(WEBSITE_REPO) $(GOPATH)/src/$(WEBSITE_REPO)
endif
@$(MAKE) -C $(GOPATH)/src/$(WEBSITE_REPO) website-provider PROVIDER_PATH=$(shell pwd) PROVIDER_NAME=$(PKG_NAME)

website-test:
ifeq (,$(wildcard $(GOPATH)/src/$(WEBSITE_REPO)))
echo "$(WEBSITE_REPO) not found in your GOPATH (necessary for layouts and assets), get-ting..."
git clone https://$(WEBSITE_REPO) $(GOPATH)/src/$(WEBSITE_REPO)
endif
@$(MAKE) -C $(GOPATH)/src/$(WEBSITE_REPO) website-provider-test PROVIDER_PATH=$(shell pwd) PROVIDER_NAME=$(PKG_NAME)

.PHONY: build test testacc vet fmt fmtcheck errcheck test-compile website website-test

.PHONY: build test testacc vet fmt fmtcheck errcheck test-compile
7 changes: 3 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module github.com/terraform-providers/terraform-provider-local

require (
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hashicorp/terraform-plugin-sdk v1.0.0
)
go 1.15

require github.com/hashicorp/terraform-plugin-sdk/v2 v2.0.3
399 changes: 340 additions & 59 deletions go.sum

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package local
package provider

import (
"crypto/sha1"
"encoding/base64"
"encoding/hex"
"io/ioutil"

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

func dataSourceLocalFile() *schema.Resource {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package local
package provider

import (
"encoding/base64"
"fmt"
"testing"

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

func TestLocalFileDataSource(t *testing.T) {
Expand Down
17 changes: 17 additions & 0 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package provider

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

func New() *schema.Provider {
return &schema.Provider{
Schema: map[string]*schema.Schema{},
ResourcesMap: map[string]*schema.Resource{
"local_file": resourceLocalFile(),
},
DataSourcesMap: map[string]*schema.Resource{
"local_file": dataSourceLocalFile(),
},
}
}
17 changes: 17 additions & 0 deletions internal/provider/provider_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package provider

import (
"testing"

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

var testProviders = map[string]*schema.Provider{
"local": New(),
}

func TestProvider(t *testing.T) {
if err := New().InternalValidate(); err != nil {
t.Fatalf("err: %s", err)
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package local
package provider

import (
"crypto/sha1"
Expand All @@ -9,7 +9,7 @@ import (
"path"
"strconv"

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

func resourceLocalFile() *schema.Resource {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,56 +1,61 @@
package local
package provider

import (
"errors"
"fmt"
"io/ioutil"
"os"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
r "github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
"path"
"path/filepath"
"runtime"
"testing"

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

func TestLocalFile_Basic(t *testing.T) {
td := testTempDir(t)
defer os.RemoveAll(td)

f := filepath.Join(td, "local_file")

var cases = []struct {
path string
content string
config string
}{
{
"local_file",
"This is some content", `
f,
"This is some content", fmt.Sprintf(`
resource "local_file" "file" {
content = "This is some content"
filename = "local_file"
}`,
filename = "%s"
}`, f),
},
{
"local_file",
"This is some sensitive content", `
f,
"This is some sensitive content", fmt.Sprintf(`
resource "local_file" "file" {
sensitive_content = "This is some sensitive content"
filename = "local_file"
}`,
filename = "%s"
}`, f),
},
{
"local_file",
"This is some sensitive content", `
f,
"This is some sensitive content", fmt.Sprintf(`
resource "local_file" "file" {
content_base64 = "VGhpcyBpcyBzb21lIHNlbnNpdGl2ZSBjb250ZW50"
filename = "local_file"
}`,
filename = "%s"
}`, f),
},
{
"local_file",
"This is some sensitive content", `
f,
"This is some sensitive content", fmt.Sprintf(`
resource "local_file" "file" {
content_base64 = base64encode("This is some sensitive content")
filename = "local_file"
}`,
filename = "%s"
}`, f),
},
}

Expand Down Expand Up @@ -131,10 +136,10 @@ resource "local_file" "file" {
}

func TestLocalFile_Permissions(t *testing.T) {
td := testTempDir(t)
defer os.RemoveAll(td)

randomPath := acctest.RandomWithPrefix("test-file-perms")

destinationDirPath := "../test/" + randomPath
destinationDirPath := td
destinationFilePath := destinationDirPath + "/local_file"
filePermission := os.FileMode(0600)
directoryPermission := os.FileMode(0700)
Expand Down Expand Up @@ -200,3 +205,11 @@ resource "local_file" "file" {
defer os.Remove(destinationDirPath)

}

func testTempDir(t *testing.T) string {
tmp, err := ioutil.TempDir("", "tf")
if err != nil {
t.Fatal(err)
}
return tmp
}
27 changes: 27 additions & 0 deletions internal/provider/validator.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package provider

import (
"fmt"
"strconv"
)

func validateMode(i interface{}, k string) (s []string, es []error) {
v, ok := i.(string)

if !ok {
es = append(es, fmt.Errorf("expected type of %s to be string", k))
return
}

if len(v) > 4 || len(v) < 3 {
es = append(es, fmt.Errorf("bad mode for file - string length should be 3 or 4 digits: %s", v))
}

fileMode, err := strconv.ParseInt(v, 8, 64)

if err != nil || fileMode > 0777 || fileMode < 0 {
es = append(es, fmt.Errorf("bad mode for file - must be three octal digits: %s", v))
}

return
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package local
package provider

import (
"regexp"
Expand Down
18 changes: 0 additions & 18 deletions local/provider.go

This file was deleted.

18 changes: 0 additions & 18 deletions local/provider_test.go

This file was deleted.

27 changes: 0 additions & 27 deletions local/validator.go

This file was deleted.

6 changes: 3 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package main

import (
"github.com/hashicorp/terraform-plugin-sdk/plugin"
"github.com/terraform-providers/terraform-provider-local/local"
"github.com/hashicorp/terraform-plugin-sdk/v2/plugin"
"github.com/terraform-providers/terraform-provider-local/internal/provider"
)

func main() {
plugin.Serve(&plugin.ServeOpts{
ProviderFunc: local.Provider})
ProviderFunc: provider.New})
}
11 changes: 11 additions & 0 deletions vendor/cloud.google.com/go/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading