Skip to content

Commit

Permalink
Update for recent Terraform and Kea versions, update release workflow…
Browse files Browse the repository at this point in the history
…, update .gitignore

Signed-off-by: Feliksas <[email protected]>
  • Loading branch information
Feliksas committed Nov 8, 2022
1 parent 6e183ab commit e99c9e1
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 55 deletions.
57 changes: 20 additions & 37 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,27 @@ jobs:
name: "Build, test and release"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v2
uses: actions/setup-go@v3
with:
go-version: 1.17

- name: Create Terraform plugins directory
run: mkdir -p ~/.terraform.d/plugins/linux_amd64
run: mkdir -p ~/.terraform.d/plugins/terraform.local/feliksas/kea-dhcp4/1.0.0/linux_amd64/

- name: Build
env:
CGO_ENABLED: "0"
GOOS: linux
GOARCH: amd64
run: go build -v -a -o ~/.terraform.d/plugins/linux_amd64/terraform-provider-kea-dhcp4_v1.0_x4
run: go build -v -a -o ~/.terraform.d/plugins/terraform.local/feliksas/kea-dhcp4/1.0.0/linux_amd64/terraform-provider-kea-dhcp4_v1.0.0

- name: Set up Terraform
uses: hashicorp/setup-terraform@v1
uses: hashicorp/setup-terraform@v2
with:
terraform_version: 0.12.20
terraform_version: 1.3.4

- name: Set up test environment
run: |
Expand All @@ -53,38 +53,21 @@ jobs:
terraform apply -auto-approve
terraform destroy -auto-approve
- name: Set version
- name: Import GPG key
if: startsWith(github.ref, 'refs/tags/')
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV

- name: Build artifacts (Linux)
if: startsWith(github.ref, 'refs/tags/')
env:
CGO_ENABLED: "0"
GOARCH: amd64
GOOS: linux
run: go build -a -o build/terraform-provider-kea-dhcp4_${{ env.RELEASE_VERSION }}-linux-amd64

- name: Build artifacts (macOS)
if: startsWith(github.ref, 'refs/tags/')
env:
CGO_ENABLED: "0"
GOARCH: amd64
GOOS: darwin
run: go build -a -o build/terraform-provider-kea-dhcp4_${{ env.RELEASE_VERSION }}-darwin-amd64

- name: Build artifacts (Windows)
if: startsWith(github.ref, 'refs/tags/')
env:
CGO_ENABLED: "0"
GOARCH: amd64
GOOS: windows
run: go build -a -o build/terraform-provider-kea-dhcp4_${{ env.RELEASE_VERSION }}-windows-amd64.exe
id: import_gpg
uses: crazy-max/ghaction-import-gpg@v5
with:
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.PASSPHRASE }}

- name: Release
uses: fnkr/github-action-ghr@v1
- name: Run GoReleaser
if: startsWith(github.ref, 'refs/tags/')
uses: goreleaser/goreleaser-action@v3
with:
version: latest
args: release --rm-dist
env:
GHR_COMPRESS: zip
GHR_PATH: build/
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }}
# GitHub sets this automatically
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ terraform-provider-kea-dhcp4
.gitconfig
.vscode
build/*
test-data/terraform/*lock.hcl
test-data/terraform/.terraform/
test-data/terraform/*tfstate*
51 changes: 51 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# 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 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:
prerelease: auto
4 changes: 2 additions & 2 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ type Dhcp4 struct {
OptionDef interface{} `json:"option-def,omitempty"` // Not implemented
RebindTimer int `json:"rebind-timer"`
RenewTimer int `json:"renew-timer"`
ReservationMode string `json:"reservation-mode"`
ReservationMode string `json:"reservation-mode,omitempty"`
SanityChecks SanityChecks `json:"sanity-checks"`
ServerHostname string `json:"server-hostname"`
ServerTag string `json:"server-tag"`
Expand Down Expand Up @@ -206,7 +206,7 @@ type Subnet4 struct {
RebindTimer int `json:"rebind-timer"`
Relay interface{} `json:"relay"`
RenewTimer int `json:"renew-timer"`
ReservationMode string `json:"reservation-mode"`
ReservationMode string `json:"reservation-mode,omitempty"`
Reservations []Reservations `json:"reservations"`
Subnet string `json:"subnet"`
T1Percent float64 `json:"t1-percent"`
Expand Down
1 change: 0 additions & 1 deletion entrypoint.kea.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ cleanup() {

trap cleanup EXIT

rm /run/kea/*
/usr/sbin/kea-ctrl-agent -c /etc/kea/kea-ctrl-agent.conf &
/usr/sbin/kea-dhcp4 -c /etc/kea/kea-dhcp4.conf &
wait -n
Expand Down
10 changes: 4 additions & 6 deletions kea.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
FROM ubuntu
RUN apt-get update && apt-get -y install curl apt-transport-https gnupg
RUN curl -1sLf 'https://dl.cloudsmith.io/public/isc/kea-1-8/cfg/setup/bash.deb.sh' | bash
RUN apt-get -y install isc-kea-common isc-kea-dhcp4-server isc-kea-ctrl-agent
RUN apt-get update
RUN apt-get -y install kea-common kea-dhcp4-server kea-ctrl-agent
ADD --chown=_kea:_kea ./test-data/kea/kea-dhcp4.conf /etc/kea/kea-dhcp4.conf
ADD --chown=_kea:_kea ./test-data/kea/kea-ctrl-agent.conf /etc/kea/kea-ctrl-agent.conf
RUN mkdir -p /var/log/kea /run/kea
RUN chown -R _kea. /var/log/kea /run/kea
USER _kea
ENV KEA_PIDFILE_DIR=/run/kea
ENV KEA_LOCKFILE_DIR=/run/lock/kea
ENV KEA_LOGGER_DESTINATION=/var/log/kea
EXPOSE 8000/tcp
COPY ./entrypoint.kea.sh /docker-entrypoint.sh
ENTRYPOINT ["/docker-entrypoint.sh"]
12 changes: 4 additions & 8 deletions terraform.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,14 @@ RUN apk add git
ARG CGO_ENABLED=0
ARG GOARCH=amd64
ARG GOOS=linux
RUN go build -a -o terraform-provider-kea-dhcp4_v1.0-linux-amd64
ARG GOOS=darwin
RUN go build -a -o terraform-provider-kea-dhcp4_v1.0-darwin-amd64
ARG GOOS=windows
RUN go build -a -o terraform-provider-kea-dhcp4_v1.0-windows-amd64
RUN go build -a -o terraform-provider-kea-dhcp4_v1.0.0

FROM scratch AS exporter
COPY --from=builder /build/terraform-provider-kea* /

FROM hashicorp/terraform:0.12.20 AS runner
RUN mkdir -p /root/.terraform.d/plugins/linux_amd64/
COPY --from=builder /build/terraform-provider-kea-dhcp4_v1.0-linux-amd64 /root/.terraform.d/plugins/linux_amd64/
FROM hashicorp/terraform:latest AS runner
RUN mkdir -p /root/.terraform.d/plugins/terraform.local/feliksas/kea-dhcp4/1.0.0/linux_amd64
COPY --from=builder /build/terraform-provider-kea-dhcp4_v1.0.0 /root/.terraform.d/plugins/terraform.local/feliksas/kea-dhcp4/1.0.0/linux_amd64/
RUN mkdir /tffiles
WORKDIR /tffiles
COPY ./test-data/terraform/*.tf /tffiles/
Expand Down
10 changes: 9 additions & 1 deletion test-data/terraform/dhcp-provider.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
# define kea-dhcp4 provider
terraform {
required_providers {
kea-dhcp4 = {
source = "terraform.local/feliksas/kea-dhcp4"
version = "1.0.0"
}
}
}

provider "kea-dhcp4" {
kea_server_address = "http://localhost:8080"
kea_server_username = "test"
Expand Down

0 comments on commit e99c9e1

Please sign in to comment.