Skip to content

Commit

Permalink
Merge pull request #53 from kbst/terraformregistry
Browse files Browse the repository at this point in the history
Prepare provider to be published on the Terraform registry
  • Loading branch information
pst authored Oct 1, 2020
2 parents 4d64f15 + a04eca7 commit 012abde
Show file tree
Hide file tree
Showing 10 changed files with 270 additions and 89 deletions.
167 changes: 100 additions & 67 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ name: Run Tests

on: push

env:
GO_VERSION: ">=1.15"
TERRAFORM_VERSION: "0.12.29"

jobs:
tf_acc_tests:
runs-on: ubuntu-latest
Expand All @@ -15,10 +19,10 @@ jobs:
with:
version: "v0.6.1"

- name: 'Setup Go'
uses: actions/setup-go@v1
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: "1.13.5"
go-version: "${{ env.GO_VERSION }}"

- name: 'Run TF acceptance tests'
run: |
Expand All @@ -34,62 +38,56 @@ jobs:
- name: 'Checkout'
uses: actions/checkout@v1

- name: 'Setup Go'
uses: actions/setup-go@v1
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: "1.13.5"

- name: 'Compile provider'
run: |
go build -o terraform.d/plugins/linux_amd64/terraform-provider-kustomization
ls -al
pwd
go-version: "${{ env.GO_VERSION }}"

- name: 'Upload provider binary'
uses: actions/upload-artifact@v1
- name: Run goreleaser build
if: startsWith(github.ref, 'refs/tags/v')
uses: kbst/goreleaser-action@v2
with:
name: terraform.d
path: terraform.d

download_terraform:
runs-on: ubuntu-latest

steps:
version: latest
args: build --config .goreleaser-build.yml --rm-dist

- name: 'Download Terraform'
run: |
wget https://releases.hashicorp.com/terraform/0.12.20/terraform_0.12.20_linux_amd64.zip
unzip terraform_0.12.20_linux_amd64.zip
./terraform version
- name: Run goreleaser build --snapshot
if: startsWith(github.ref, 'refs/tags/v') == false
uses: kbst/goreleaser-action@v2
with:
version: latest
args: build --config .goreleaser-build.yml --rm-dist --snapshot

- name: 'Upload terraform binary'
uses: actions/upload-artifact@v1
- name: 'Upload dist'
uses: actions/upload-artifact@v2
with:
name: terraform
path: terraform
name: dist
path: dist/

int_test_kubeconfig_path:
runs-on: ubuntu-latest
needs: [compile_provider, download_terraform]
needs: [compile_provider]

steps:
- name: 'Checkout'
uses: actions/checkout@v1

- name: 'Download terraform binary'
uses: actions/download-artifact@v1
- name: Setup Terraform
uses: hashicorp/setup-terraform@v1.2.0
with:
name: terraform
terraform_wrapper: false
terraform_version: "${{ env.TERRAFORM_VERSION }}"

- name: 'Download provider binary'
uses: actions/download-artifact@v1
uses: actions/download-artifact@v2
with:
name: terraform.d
name: dist
path: dist

- name: 'Make binaries executable'
- name: 'Prepare provider binary'
run: |
chmod +x ./terraform/terraform
chmod +x ./terraform.d/plugins/linux_amd64/terraform-provider-kustomization
mkdir -p ./terraform.d/plugins/linux_amd64/
cp ./dist/terraform-provider-kustomization_linux_amd64/terraform-provider-kustomization_* ./terraform.d/plugins/linux_amd64/
chmod +x ./terraform.d/plugins/linux_amd64/terraform-provider-kustomization_*
- name: 'Setup Kind'
uses: engineerd/[email protected]
Expand All @@ -101,14 +99,14 @@ jobs:
export KUBECONFIG="$(kind get kubeconfig-path --name="kind")"
- name: 'Terraform Init'
run: ./terraform/terraform init
run: terraform init

- name: 'Terraform Apply'
run: ./terraform/terraform apply --auto-approve
run: terraform apply --auto-approve

int_test_kubeconfig_raw:
runs-on: ubuntu-latest
needs: [compile_provider, download_terraform]
needs: [compile_provider]

steps:
- name: 'Checkout'
Expand All @@ -119,20 +117,23 @@ jobs:
with:
version: "v0.6.1"

- name: 'Download terraform binary'
uses: actions/download-artifact@v1
- name: Setup Terraform
uses: hashicorp/setup-terraform@v1.2.0
with:
name: terraform
terraform_wrapper: false
terraform_version: "${{ env.TERRAFORM_VERSION }}"

- name: 'Download provider binary'
uses: actions/download-artifact@v1
uses: actions/download-artifact@v2
with:
name: terraform.d
name: dist
path: dist

- name: 'Make binaries executable'
- name: 'Prepare provider binary'
run: |
chmod +x ./terraform/terraform
chmod +x ./terraform.d/plugins/linux_amd64/terraform-provider-kustomization
mkdir -p ./terraform.d/plugins/linux_amd64/
cp ./dist/terraform-provider-kustomization_linux_amd64/terraform-provider-kustomization_* ./terraform.d/plugins/linux_amd64/
chmod +x ./terraform.d/plugins/linux_amd64/terraform-provider-kustomization_*
- name: 'Create provider.tf with kubeconfig_raw'
run: |
Expand All @@ -144,14 +145,14 @@ jobs:
echo "}" >> provider.tf
- name: 'Terraform Init'
run: ./terraform/terraform init
run: terraform init

- name: 'Terraform Apply'
run: ./terraform/terraform apply --auto-approve
run: terraform apply --auto-approve

int_test_state_import:
runs-on: ubuntu-latest
needs: [compile_provider, download_terraform]
needs: [compile_provider]

steps:
- name: 'Checkout'
Expand All @@ -162,20 +163,23 @@ jobs:
with:
version: "v0.6.1"

- name: 'Download terraform binary'
uses: actions/download-artifact@v1
- name: Setup Terraform
uses: hashicorp/setup-terraform@v1.2.0
with:
name: terraform
terraform_wrapper: false
terraform_version: "${{ env.TERRAFORM_VERSION }}"

- name: 'Download provider binary'
uses: actions/download-artifact@v1
uses: actions/download-artifact@v2
with:
name: terraform.d
name: dist
path: dist

- name: 'Make binaries executable'
- name: 'Prepare provider binary'
run: |
chmod +x ./terraform/terraform
chmod +x ./terraform.d/plugins/linux_amd64/terraform-provider-kustomization
mkdir -p ./terraform.d/plugins/linux_amd64/
cp ./dist/terraform-provider-kustomization_linux_amd64/terraform-provider-kustomization_* ./terraform.d/plugins/linux_amd64/
chmod +x ./terraform.d/plugins/linux_amd64/terraform-provider-kustomization_*
- name: 'Set KUBECONFIG env var'
run: |
Expand All @@ -192,14 +196,43 @@ jobs:
kustomize build test_kustomizations/basic/initial | kubectl apply -f -
- name: 'Terraform Init'
run: ./terraform/terraform init
run: terraform init

- name: 'Terraform Import'
run: |
./terraform/terraform import 'kustomization_resource.test["~G_v1_Namespace|~X|test-basic"]' '~G_v1_Namespace|~X|test-basic'
./terraform/terraform import 'kustomization_resource.test["apps_v1_Deployment|test-basic|test"]' 'apps_v1_Deployment|test-basic|test'
./terraform/terraform import 'kustomization_resource.test["~G_v1_Service|test-basic|test"]' '~G_v1_Service|test-basic|test'
./terraform/terraform import 'kustomization_resource.test["networking.k8s.io_v1beta1_Ingress|test-basic|test"]' 'networking.k8s.io_v1beta1_Ingress|test-basic|test'
terraform import 'kustomization_resource.test["~G_v1_Namespace|~X|test-basic"]' '~G_v1_Namespace|~X|test-basic'
terraform import 'kustomization_resource.test["apps_v1_Deployment|test-basic|test"]' 'apps_v1_Deployment|test-basic|test'
terraform import 'kustomization_resource.test["~G_v1_Service|test-basic|test"]' '~G_v1_Service|test-basic|test'
terraform import 'kustomization_resource.test["networking.k8s.io_v1beta1_Ingress|test-basic|test"]' 'networking.k8s.io_v1beta1_Ingress|test-basic|test'
- name: 'Terraform Apply'
run: ./terraform/terraform apply --auto-approve
run: terraform apply --auto-approve

goreleaser:
runs-on: ubuntu-latest
needs: [tf_acc_tests, int_test_kubeconfig_path, int_test_kubeconfig_raw, int_test_state_import]
if: startsWith(github.ref, 'refs/tags/v')
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: "${{ env.GO_VERSION }}"

- name: Import GPG key
id: import_gpg
uses: kbst/ghaction-import-gpg@v3
with:
gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.GPG_PASSPHRASE }}

- name: Run goreleaser release
uses: kbst/goreleaser-action@v2
with:
version: latest
args: release
env:
GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
terraform.d
*.tfstate*
crash.log
dist/
17 changes: 17 additions & 0 deletions .goreleaser-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
project_name: terraform-provider-kustomization
before:
hooks:
- go mod tidy
builds:
- env:
- CGO_ENABLED=0
mod_timestamp: '{{ .CommitTimestamp }}'
flags:
- -trimpath
ldflags:
- '-s -w -X main.version={{.Version}} -X main.commit={{.Commit}}'
goos:
- linux
goarch:
- amd64
binary: '{{ .ProjectName }}_v{{ .Version }}'
49 changes: 49 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
project_name: terraform-provider-kustomization
before:
hooks:
- go mod tidy
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:
# 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:
draft: true
prerelease: auto
changelog:
skip: false
12 changes: 0 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,3 @@ build:

test:
TF_ACC=1 go test -v ./kustomize

RELEASE := $(shell git describe --tags)

release-binaries:
GOOS=linux GOARCH=amd64 go build -o terraform.d/plugins/linux_amd64/terraform-provider-kustomization_$(RELEASE)
tar -caf terraform-provider-kustomization-linux-amd64_$(RELEASE).tgz terraform.d/plugins/linux_amd64/terraform-provider-kustomization_$(RELEASE)

GOOS=darwin GOARCH=amd64 go build -o terraform.d/plugins/darwin_amd64/terraform-provider-kustomization_$(RELEASE)
tar -caf terraform-provider-kustomization-darwin-amd64_$(RELEASE).tgz terraform.d/plugins/darwin_amd64/terraform-provider-kustomization_$(RELEASE)

GOOS=windows GOARCH=amd64 go build -o terraform.d/plugins/windows_amd64/terraform-provider-kustomization_$(RELEASE)
tar -caf terraform-provider-kustomization-windows-amd64_$(RELEASE).tgz terraform.d/plugins/windows_amd64/terraform-provider-kustomization_$(RELEASE)
Loading

0 comments on commit 012abde

Please sign in to comment.