-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
253 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# Visit https://goreleaser.com for documentation on how to customize this | ||
# behavior. | ||
before: | ||
hooks: | ||
# this is just an example and not a requirement for provider building/publishing | ||
- go mod tidy | ||
builds: | ||
- env: | ||
# goreleaser does not work with CGO, it could also complicate | ||
# usage by users in CI/CD systems like Terraform Cloud where | ||
# they are unable to install libraries. | ||
- CGO_ENABLED=0 | ||
mod_timestamp: '{{ .CommitTimestamp }}' | ||
flags: | ||
- -trimpath | ||
ldflags: | ||
- '-s -w -X github.com/jfrog/terraform-provider-platform/pkg/provder.Version={{.Version}}' | ||
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: | ||
# if you are using this is a GitHub action or some other automated pipeline, you | ||
# need to pass the batch flag to indicate its not interactive. | ||
- "--batch" | ||
- "--local-user" | ||
- "{{ .Env.GPG_FINGERPRINT }}" # set this environment variable for your signing key | ||
- "--output" | ||
- "${signature}" | ||
- "--detach-sign" | ||
- "${artifact}" | ||
release: | ||
# If you want to manually examine the release before its live, uncomment this line: | ||
# draft: true | ||
changelog: | ||
use: github-native |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
TEST?=./... | ||
PRODUCT=platform | ||
GO_ARCH=$(shell go env GOARCH) | ||
TARGET_ARCH=$(shell go env GOOS)_${GO_ARCH} | ||
GORELEASER_ARCH=${TARGET_ARCH} | ||
|
||
ifeq ($(GO_ARCH), amd64) | ||
GORELEASER_ARCH=${TARGET_ARCH}_$(shell go env GOAMD64) | ||
endif | ||
PKG_NAME=pkg/${PRODUCT} | ||
# if this path ever changes, you need to also update the 'ldflags' value in .goreleaser.yml | ||
PKG_VERSION_PATH=github.com/jfrog/terraform-provider-${PRODUCT}/${PKG_NAME} | ||
VERSION := $(shell git tag --sort=-creatordate | head -1 | sed -n 's/v\([0-9]*\).\([0-9]*\).\([0-9]*\)/\1.\2.\3/p') | ||
NEXT_VERSION?=$(shell echo ${VERSION}| awk -F '.' '{print $$1 "." $$2 "." $$3 +1 }' ) | ||
BUILD_PATH=terraform.d/plugins/registry.terraform.io/jfrog/${PRODUCT}/${NEXT_VERSION}/${TARGET_ARCH} | ||
SONAR_SCANNER_VERSION?=4.7.0.2747 | ||
SONAR_SCANNER_HOME?=${HOME}/.sonar/sonar-scanner-${SONAR_SCANNER_VERSION}-macosx | ||
|
||
default: build | ||
|
||
install: clean build | ||
rm -fR .terraform.d && \ | ||
mkdir -p ${BUILD_PATH} && \ | ||
mv -v dist/terraform-provider-${PRODUCT}_${GORELEASER_ARCH}/terraform-provider-${PRODUCT}_v${NEXT_VERSION}* ${BUILD_PATH} && \ | ||
rm -f .terraform.lock.hcl && \ | ||
sed -i.bak '0,/version = ".*"/s//version = "${NEXT_VERSION}"/' sample.tf && rm sample.tf.bak && \ | ||
terraform init | ||
|
||
clean: | ||
rm -fR dist terraform.d/ .terraform terraform.tfstate* .terraform.lock.hcl | ||
|
||
release: | ||
@git tag ${NEXT_VERSION} && git push --mirror | ||
@echo "Pushed ${NEXT_VERSION}" | ||
GOPROXY=https://proxy.golang.org GO111MODULE=on go get github.com/jfrog/terraform-provider-${PRODUCT}@v${NEXT_VERSION} | ||
@echo "Updated pkg cache" | ||
|
||
update_pkg_cache: | ||
GOPROXY=https://proxy.golang.org GO111MODULE=on go get github.com/jfrog/terraform-provider-${PRODUCT}@v${VERSION} | ||
|
||
build: fmt | ||
GORELEASER_CURRENT_TAG=${NEXT_VERSION} goreleaser build --single-target --clean --snapshot | ||
|
||
test: | ||
@echo "==> Starting unit tests" | ||
go test $(TEST) -timeout=30s -parallel=4 | ||
|
||
attach: | ||
dlv --listen=:2345 --headless=true --api-version=2 --accept-multiclient attach $$(pgrep terraform-provider-${PRODUCT}) | ||
|
||
acceptance: fmt | ||
export TF_ACC=true && \ | ||
go test -cover -coverprofile=coverage.txt -ldflags="-X '${PKG_VERSION_PATH}.Version=${NEXT_VERSION}-test'" -v -p 1 -parallel 20 -timeout 20m ./pkg/... | ||
|
||
# To generate coverage.txt run `make acceptance` first | ||
coverage: | ||
go tool cover -html=coverage.txt | ||
|
||
# SONAR_TOKEN (project token) must be set to run `make scan`. Check file sonar-project.properties for the configuration. | ||
scan: | ||
${SONAR_SCANNER_HOME}/bin/sonar-scanner -Dsonar.projectVersion=${VERSION} -Dsonar.go.coverage.reportPaths=coverage.txt | ||
|
||
fmt: | ||
@echo "==> Fixing source code with gofmt..." | ||
@go fmt ./... | ||
|
||
doc: | ||
rm -rfv docs/* | ||
go generate | ||
|
||
.PHONY: build fmt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module github.com/jfrog/terraform-provider-plaform | ||
|
||
go 1.19 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"flag" | ||
"log" | ||
|
||
"github.com/hashicorp/terraform-plugin-framework/providerserver" | ||
provider "github.com/jfrog/terraform-provider-platform/pkg/platform/provider" | ||
) | ||
|
||
// Run the docs generation tool, check its repository for more information on how it works and how docs | ||
// can be customized. | ||
//go:generate go run github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs | ||
|
||
func main() { | ||
var debug bool | ||
|
||
flag.BoolVar(&debug, "debug", false, "set to true to run the provider with support for debuggers like delve") | ||
flag.Parse() | ||
|
||
opts := providerserver.ServeOpts{ | ||
Address: "registry.terraform.io/jfrog/platform", | ||
Debug: debug, | ||
} | ||
|
||
err := providerserver.Serve(context.Background(), provider.New(), opts) | ||
|
||
if err != nil { | ||
log.Fatal(err.Error()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package platform | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/hashicorp/terraform-plugin-framework/datasource" | ||
"github.com/hashicorp/terraform-plugin-framework/provider" | ||
"github.com/hashicorp/terraform-plugin-framework/resource" | ||
) | ||
|
||
var Version = "0.0.1" | ||
|
||
// needs to be exported so make file can update this | ||
var productId = "terraform-provider-platform/" + Version | ||
|
||
var _ provider.Provider = (*platformProvider)(nil) | ||
var _ provider.ProviderWithMetadata = (*platformProvider)(nil) | ||
|
||
type platformProvider struct{} | ||
|
||
func New() func() provider.Provider { | ||
return func() provider.Provider { | ||
return &platformProvider{} | ||
} | ||
} | ||
|
||
func (p *platformProvider) Configure(ctx context.Context, req provider.ConfigureRequest, resp *provider.ConfigureResponse) { | ||
} | ||
|
||
func (p *platformProvider) Metadata(ctx context.Context, req provider.MetadataRequest, resp *provider.MetadataResponse) { | ||
resp.TypeName = "platform" | ||
} | ||
|
||
func (p *platformProvider) DataSources(ctx context.Context) []func() datasource.DataSource { | ||
return []func() datasource.DataSource{ | ||
// NewDataSource, | ||
} | ||
} | ||
|
||
func (p *platformProvider) Resources(ctx context.Context) []func() resource.Resource { | ||
return []func() resource.Resource{ | ||
// NewResourceWorkerService, | ||
} | ||
} | ||
|
||
func (p *platformProvider) Schema(ctx context.Context, req provider.SchemaRequest, resp *provider.SchemaResponse) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package platform | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/hashicorp/terraform-plugin-framework/provider/schema" | ||
"github.com/hashicorp/terraform-plugin-framework/resource" | ||
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" | ||
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" | ||
) | ||
|
||
var _ resource.Resource = (*workersServiceResource)(nil) | ||
|
||
type workersServiceResource struct { | ||
provider platformProvider | ||
} | ||
|
||
func NewResource() resource.Resource { | ||
return &workersServiceResource{} | ||
} | ||
|
||
func (e *workersServiceResource) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { | ||
resp.TypeName = "workers_service" | ||
} | ||
|
||
func (e *workersServiceResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { | ||
resp.Schema = schema.Schema{ | ||
Attributes: map[string]schema.Attribute{ | ||
"key": schema.StringAttribute{ | ||
Required: true, | ||
PlanModifiers: []planmodifier.String{ | ||
stringplanmodifier.UseStateForUnknown(), | ||
}, | ||
}, | ||
"enabled": schema.BoolAttribute{}, | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
//go:build tools | ||
|
||
package tools | ||
|
||
import ( | ||
// document generation | ||
_ "github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs" | ||
) |