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

(CLOUDDEV-354): v2 init #34

Merged
merged 26 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
810e156
(CLOUDDEV-354): v2 init
anaxaim Nov 22, 2023
cc9f262
(CLOUDDEV-354): floating ips
anaxaim Nov 24, 2023
5b5ba71
(CLOUDDEV-354): volumes
anaxaim Nov 28, 2023
ce67c9b
(CLOUDDEV-354): instances
anaxaim Nov 28, 2023
9784171
(CLOUDDEV-354): instances
anaxaim Dec 4, 2023
e8975ae
(CLOUDDEV-354): instances (refactor)
anaxaim Dec 7, 2023
80a12ea
feat(CLOUDDEV-374): lb allowed cidrs
anaxaim Dec 7, 2023
a7118cc
feat(CLOUDDEV-374): lb allowed cidrs
anaxaim Dec 7, 2023
ab0b983
Merge pull request #35 from Edge-Center/feat/CLOUDDEV-374-lb-allowed-…
anaxaim Dec 7, 2023
fab3b1a
(CLOUDDEV-354): loadbalancers
anaxaim Dec 12, 2023
f6656b1
(CLOUDDEV-354): listeners
anaxaim Dec 12, 2023
6eba8de
(CLOUDDEV-354): lb pools
anaxaim Dec 13, 2023
f8a9b3d
(CLOUDDEV-354): v2 init
anaxaim Nov 22, 2023
ee27f75
(CLOUDDEV-354): floating ips
anaxaim Nov 24, 2023
2a25d09
(CLOUDDEV-354): volumes
anaxaim Nov 28, 2023
504b32e
(CLOUDDEV-354): instances
anaxaim Nov 28, 2023
ffa57bd
(CLOUDDEV-354): instances
anaxaim Dec 4, 2023
9df89cb
(CLOUDDEV-354): instances (refactor)
anaxaim Dec 7, 2023
5216655
(CLOUDDEV-354): loadbalancers
anaxaim Dec 12, 2023
9bc209d
(CLOUDDEV-354): listeners
anaxaim Dec 12, 2023
c4f80a9
(CLOUDDEV-354): lb pools
anaxaim Dec 13, 2023
a473b86
Merge branch 'fix/CLOUDDEV-354-new-client' of ssh://github.com/Edge-C…
anaxaim Dec 13, 2023
d7e162f
(CLOUDDEV-354): lb pool members
anaxaim Dec 14, 2023
252f540
(CLOUDDEV-354): docs and examples
anaxaim Dec 14, 2023
5d84d62
(CLOUDDEV-354): fmt
anaxaim Dec 15, 2023
b3c3af0
(CLOUDDEV-354): docs and examples
anaxaim Dec 15, 2023
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
  •  
  •  
  •  
28 changes: 9 additions & 19 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,34 +1,24 @@
name: build

on:
push:
branches: [ master ]
pull_request:
branches: [ master, main ]
branches: [ master ]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v3
uses: actions/setup-go@v4
with:
go-version: 1.20.2
go-version: 1.21.3

- name: Linters
run: make linters
run: make lint

- name: Build
run: go build -v ./...

- name: Tests data_source
env:
EC_USERNAME: ${{ secrets.EC_USERNAME }}
EC_PASSWORD: ${{ secrets.EC_PASSWORD }}
run: make test_cloud_data_source

- name: Tests resource
env:
EC_USERNAME: ${{ secrets.EC_USERNAME }}
EC_PASSWORD: ${{ secrets.EC_PASSWORD }}
run: make test_cloud_resource
- name: Tests
run: make test
49 changes: 0 additions & 49 deletions .github/workflows/release.yml

This file was deleted.

58 changes: 23 additions & 35 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,19 @@
run:
timeout: 10m
go: "1.20"
go: "1.21.3"

issues:
max-per-linter: 0
max-same-issues: 0
exclude:
# revive, stylecheck: ignore constants in all caps
- don't use ALL_CAPS in Go names; use CamelCase
- ST1003
# gosec
- G401
- G501
exclude-rules:
- path: \.go
- path: (.+)_test.go
linters:
- nolintlint
text: should be written without leading space
- text: lifecyclepolicy.CreateScheduleOpts
linters:
- ireturn
- path: utils|_test
linters:
- wrapcheck
- funlen

linters:
enable-all: true
disable:
# deprecated
- deadcode
- maligned
- varcheck
Expand All @@ -40,37 +27,38 @@ linters:
- rowserrcheck
- sqlclosecheck
- wastedassign
# skip
- gochecknoglobals # check that no global variables exist
- nilnil # Checks that there is no simultaneous return of nil error and an invalid value.
- gomnd # An analyzer to detect magic numbers.
- goerr113 # Golang linter to check the errors handling expressions
- exhaustruct # Checks if all structure fields are initialized
- lll # Reports long lines
# skip: dubious benefit
- gochecknoglobals # Checks that no global variables exist.
- exhaustruct # Checks if all structure fields are initialized.
- lll # Reports long lines.
- godox # Tool for detection of FIXME, TODO and other comment keywords
- wsl # Whitespace Linter - Forces you to use empty lines!
- tagliatelle # Checks the struct tags.
- nonamedreturns # Reports all named returns.
- wrapcheck # Checks that errors returned from external packages are wrapped.
- ireturn # Accept Interfaces, Return Concrete Types.
- tagalign # Checks that struct tags are well aligned
- depguard # Checks if package imports are in a list of acceptable packages
- musttag # Enforce field tags in (un)marshaled structs.
- dupl # Tool for code clone detection.
- cyclop # Checks function and package cyclomatic complexity.
- forcetypeassert # finds forced type assertions
# complexity: need to refactor
- cyclop
- goerr113 # Golang linter to check the errors handling expressions
- funlen
- gocognit
- gocyclo
- maintidx
- nestif
- dupl
- depguard
# tests
- testpackage # Makes you use a separate _test package.
- paralleltest # Detects missing usage of t.Parallel() method in your Go test.

linters-settings:
nlreturn:
block-size: 10
block-size: 5
gci:
sections:
- standard # Standard section: captures all standard packages.
- default # Default section: contains all imports that could not be matched to another section type.
- prefix(github.com/Edge-Center)
errcheck:
ignore: github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema:ForceNew|Set,fmt:.*,io:Close,io:WriteString
nakedret:
max-func-lines: 40
ignore: github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema:ForceNew|Set,fmt
varnamelen:
min-name-length: 1
51 changes: 2 additions & 49 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,60 +1,13 @@
# 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 }}'
- skip: true
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
skip: true
103 changes: 26 additions & 77 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,98 +1,47 @@
# ENVS
ifeq ($(OS),Windows_NT)
PROJECT_DIR = $(shell cd)
OS := windows
ifeq ($(PROCESSOR_ARCHITECTURE),AMD64)
ARCH := amd64
endif
ifeq ($(PROCESSOR_ARCHITECTURE),x86)
ARCH := 386
endif
else
PROJECT_DIR = $(shell pwd)
OS := $(shell uname | tr '[:upper:]' '[:lower:]')
ARCH := $(shell uname -m)
endif
BIN_DIR = $(PROJECT_DIR)/bin
TEST_DIR = $(PROJECT_DIR)/edgecenter/test
ENV_TESTS_FILE = $(TEST_DIR)/.env
PROJECT_DIR=$(shell pwd)
GOFMT_FILES?=$$(find . -name '*.go' |grep -v vendor)
BIN_DIR=$(PROJECT_DIR)/bin

# BINARY
BINARY_NAME = terraform-provider-edgecenter
TAG_PREFIX = "v"
TAG = $(shell git describe --tags)
VERSION = $(shell git describe --tags $(LAST_TAG_COMMIT) | sed "s/^$(TAG_PREFIX)//")
PLUGIN_PATH = ~/.terraform.d/plugins/local.edgecenter.ru/repo/edgecenter/$(VERSION)/$(OS)_$(ARCH)
BINARY_NAME=terraform-provider-edgecenter
TAG_PREFIX="v"
TAG=$(shell git describe --tags)
VERSION=$(shell git describe --tags $(LAST_TAG_COMMIT) | sed "s/^$(TAG_PREFIX)//")
PLUGIN_PATH=~/.terraform.d/plugins/local.edgecenter.ru/repo/edgecenter/$(VERSION)/$(OS)_$(ARCH)

.PHONY: tidy
tidy:
go mod tidy

# BUILD
build: tidy
.PHONY: build
build: fmtcheck
mkdir -p $(PLUGIN_PATH)
go build -o $(PLUGIN_PATH)/$(BINARY_NAME)_v$(VERSION)
go build -o bin/$(BINARY_NAME)

build_debug: tidy
mkdir -p $(PLUGIN_PATH)
go build -o $(PLUGIN_PATH)/$(BINARY_NAME)_v$(VERSION) -gcflags '-N -l'
go build -o bin/$(BINARY_NAME) -gcflags '-N -l'

# CHECKS
err_check:
@sh -c "'$(PROJECT_DIR)/scripts/errcheck.sh'"

linters:
@test -f $(BIN_DIR)/golangci-lint || curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.54.2
@$(BIN_DIR)/golangci-lint run

linters_docker: # for windows
docker run --rm -v $(PROJECT_DIR):/app -w /app golangci/golangci-lint:v1.54.2 golangci-lint run -v

# TESTS
envs_reader:
go install github.com/joho/godotenv/cmd/godotenv@latest

test_cloud_data_source: envs_reader
godotenv -f $(ENV_TESTS_FILE) go test $(TEST_DIR) -tags cloud_data_source -short -timeout=20m
.PHONY: lint
lint:
@go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
@golangci-lint run -v ./...

test_cloud_resource: envs_reader
godotenv -f $(ENV_TESTS_FILE) go test $(TEST_DIR) -tags cloud_resource -short -timeout=20m
.PHONY: test
test:
go test -v -timeout=2m

test_not_cloud: envs_reader
godotenv -f $(ENV_TESTS_FILE) go test $(TEST_DIR) -tags dns storage cdn -v -timeout=5m
fmt:
gofmt -s -w $(GOFMT_FILES)

# local test run (need to export VAULT_TOKEN env)
install_jq:
if test "$(OS)" = "linux"; then \
curl -L -o $(BIN_DIR)/jq https://github.com/stedolan/jq/releases/download/jq-1.6/jq-linux64; \
else \
curl -L -o $(BIN_DIR)/jq https://github.com/stedolan/jq/releases/download/jq-1.6/jq-osx-amd64; \
fi
chmod +x $(BIN_DIR)/jq

install_vault:
curl -L -o vault.zip https://releases.hashicorp.com/vault/1.13.3/vault_1.13.3_$(OS)_$(ARCH).zip
unzip vault.zip && rm -f vault.zip && chmod +x vault
mv vault $(BIN_DIR)/

download_env_file: envs_reader
godotenv -f $(ENV_TESTS_FILE) $(BIN_DIR)/vault login -method=token $(VAULT_TOKEN)
godotenv -f $(ENV_TESTS_FILE) $(BIN_DIR)/vault kv get -format=json --field data /CLOUD/terraform | $(BIN_DIR)/jq -r 'to_entries|map("\(.key)=\(.value)")|.[]' >> $(ENV_TESTS_FILE)

test_local_data_source: envs_reader
godotenv -f .local.env go test $(TEST_DIR) -tags cloud_data_source -short -timeout=5m -v

test_local_resource: envs_reader
godotenv -f .local.env go test $(TEST_DIR) -tags cloud_resource -short -timeout=10m -v
.PHONY: fmtcheck
fmtcheck:
@sh -c "'$(PROJECT_DIR)/scripts/gofmtcheck.sh'"

# DOCS
.PHONY: docs_fmt
docs_fmt:
terraform fmt -recursive ./examples/

.PHONY: docs
docs: docs_fmt
go get github.com/hashicorp/terraform-plugin-docs/cmd/[email protected]
make tidy
tfplugindocs --tf-version=1.5.0 --provider-name=edgecenter

.PHONY: tidy build build_debug err_check linters linters_docker envs_reader test_cloud_data_source test_cloud_resource test_not_cloud install_jq install_vault download_env_file test_local_data_source test_local_resource docs_fmt docs
tfplugindocs --tf-version=1.6.5 --provider-name=edgecenter
Loading