Skip to content

Commit

Permalink
Merge pull request #1 from liqotech/dev
Browse files Browse the repository at this point in the history
Liqo Provider - IaC with Terraform
  • Loading branch information
aleoli authored Jan 18, 2023
2 parents 9f316d9 + 77fae78 commit e17359b
Show file tree
Hide file tree
Showing 25 changed files with 2,354 additions and 16 deletions.
67 changes: 67 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Linting
on:
pull_request:

jobs:
golangci:
name: Lint golang files
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}
repository: ${{github.event.pull_request.head.repo.full_name}}
persist-credentials: false

- name: Setup Go
uses: actions/setup-go@v3
with:
go-version: 1.19

- name: golangci-lint
uses: golangci/[email protected]
with:
only-new-issues: true
version: v1.50.0

gomodtidy:
name: Enforce go.mod tidiness
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: "${{ github.event.pull_request.head.sha }}"
repository: ${{github.event.pull_request.head.repo.full_name}}
persist-credentials: false

- name: Setup Go
uses: actions/setup-go@v3
with:
go-version: 1.19

- name: Execute go mod tidy and check the outcome
working-directory: ./
run: |
go mod tidy
exit_code=$(git diff --exit-code)
exit ${exit_code}
markdownlint:
name: Lint markdown files
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v3
with:
ref: "${{ github.event.pull_request.head.sha }}"
repository: ${{github.event.pull_request.head.repo.full_name}}
persist-credentials: false

- name: Lint markdown files
uses: avto-dev/markdown-lint@v1
with:
config: '.markdownlint.yml'
args: '**/*.md'
41 changes: 41 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Terraform Provider release workflow.
name: Release

# This GitHub action creates a release when a tag that matches the pattern
# "v*" (e.g. v0.1.0) is created.
on:
push:
tags:
- 'v*'

# Releases need permissions to read and write the repository contents.
# GitHub considers creating releases and uploading assets as writing contents.
permissions:
contents: write

jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
# Allow goreleaser to access older tag information.
fetch-depth: 0
- uses: actions/setup-go@v3
with:
go-version-file: 'go.mod'
cache: true
- name: Import GPG key
uses: crazy-max/ghaction-import-gpg@v5
id: import_gpg
with:
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.PASSPHRASE }}
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v4
with:
args: release --rm-dist
env:
# GitHub sets the GITHUB_TOKEN secret automatically.
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }}
133 changes: 133 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
run:
timeout: 10m
skip-files:
- "zz_generated.*.go"

linters-settings:
exhaustive:
check-generated: false
default-signifies-exhaustive: true

lll:
line-length: 150
gomodguard:
blocked:
modules:
- github.com/go-logr/logr:
recommendations:
- k8s.io/klog/v2
gci:
sections:
- standard # Captures all standard packages if they do not match another section.
- default # Contains all imports that could not be matched to another section type.
- prefix(github.com/liqotech) # Groups all imports with the specified Prefix.
goconst:
min-len: 2
min-occurrences: 2
gocritic:
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
disabled-checks:
# Conflicts with govet check-shadowing
- sloppyReassign
goimports:
local-prefixes: github.com/liqotech
govet:
check-shadowing: true
misspell:
locale: US
nolintlint:
allow-leading-space: true # don't require machine-readable nolint directives (i.e. with no leading space)
allow-unused: false # report any unused nolint directives
require-explanation: true # require an explanation for nolint directives
require-specific: true # require nolint directives to be specific about which linter is being skipped
dupl:
threshold: 300

linters:
disable-all: true
enable:
- asciicheck
- bodyclose
- depguard
- dogsled
- dupl
- errcheck
- errorlint
- exhaustive
- exportloopref
# - funlen
# - gochecknoglobals
# - gochecknoinits
# - gocognit
- gci
- goconst
- gocritic
- gocyclo
- godot
# - godox
# - goerr113
- gofmt
- goheader
- goimports
- gomodguard
# - gomnd
- goprintffuncname
- gosec
- gosimple
- govet
- ineffassign
- lll
# - maligned
- misspell
- nakedret
# - nestif
- noctx
- nolintlint
# - prealloc
- revive
- rowserrcheck
- staticcheck
- stylecheck
# - testpackage
- typecheck
- unconvert
- unparam
- unused
- whitespace
# - wsl

issues:
#fix: true

max-issues-per-linter: 0
max-same-issues: 0

# Disable the default exclude patterns (as they disable the mandatory comments)
exclude-use-default: false
exclude:
# errcheck: Almost all programs ignore errors on these functions and in most cases it's ok
- Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*printf?|os\.(Un)?Setenv). is not checked

exclude-rules:
- linters:
- govet
text: 'declaration of "(err|ctx)" shadows declaration at'
- linters:
- gosec
# Disable the check to test that HTTP clients are not using an insecure TLS connection.
# We need it to contact the remote authentication services exposing a self-signed certificate
text: TLS InsecureSkipVerify set true.
- linters:
- errorlint
# Disable the check to test errors type assertion on switches.
text: type switch on error will fail on wrapped errors. Use errors.As to check for specific errors

# Exclude the following linters from running on tests files.
- path: _test\.go
linters:
- whitespace
60 changes: 60 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# 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:
extra_files:
- glob: 'terraform-registry-manifest.json'
name_template: '{{ .ProjectName }}_{{ .Version }}_manifest.json'
name_template: '{{ .ProjectName }}_{{ .Version }}_SHA256SUMS'
algorithm: sha256
signs:
- artifacts: checksum
args:
# if you are using this in 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:
extra_files:
- glob: 'terraform-registry-manifest.json'
name_template: '{{ .ProjectName }}_{{ .Version }}_manifest.json'
# If you want to manually examine the release before its live, uncomment this line:
# draft: true
changelog:
skip: true
3 changes: 3 additions & 0 deletions .markdownlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
default: true
line-length: false
no-inline-html: false
1 change: 1 addition & 0 deletions .markdownlintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
docs
30 changes: 14 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,44 +1,42 @@
# Liqo provider

Provider for Terraform to perform Liqo operations.
> Provider for Terraform to perform Liqo operations.
## Getting Started

Follow this example steps to test locally the implemented provider.

### Prerequisites

- [Terraform](https://developer.hashicorp.com/terraform/downloads)
- [Liqo CLI tool](https://docs.liqo.io/en/v0.6.1/installation/liqoctl.html)
- [go](https://go.dev/doc/install)

### Installation
1. in ***.terraform.d*** folder (you should have it in home/\<usr\>/) make directory with this command replacing _architecture_ with your architecture (example: linux_arm64 or linux_amd64):

``` mkdir -p /plugins/liqo-provider/liqo/liqo/0.0.1/<architecture>/ ```
1. in ***.terraform.d*** folder (you should have it in home/\<usr\>/) make directory with this command replacing *architecture* with your architecture (example: linux_arm64 or linux_amd64):

`mkdir -p /plugins/liqo-provider/liqo/liqo/0.0.1/<architecture>/`

my complete path is the following:
```home/<usr>/.terraform.d/plugins/liqo-provider/liqo/liqo/0.0.1/linux_arm64/```
`home/<usr>/.terraform.d/plugins/liqo-provider/liqo/liqo/0.0.1/linux_arm64/`

2. from root run command replacing _path_ with the one created in first step:
2. from root run command replacing *path* with the one created in first step:

```go build -o <path>/terraform-provider-liqo ```
`go build -o <path>/terraform-provider-liqo`

3. in your main.tf tell to Terraform to use provider implemented locally by yoursel with this directive in required_providers:
3. in your main.tf tell to Terraform to use provider implemented locally
by yourself with this directive in *required_providers*:

```source = "liqo-provider/liqo/liqo"```

for example:
```hcl

```terraform
terraform {
required_providers {
liqo = {
source = "liqo-provider/liqo/liqo"
source = "liqo-provider/liqo/liqo"
}
}
}
```
4. run command:
```terraform init ```
```terraform apply -auto-approve```
Loading

0 comments on commit e17359b

Please sign in to comment.