Skip to content

Commit b357bbf

Browse files
author
Kanji Yomoda
authored
Add Github actions workflow (#169)
* Add github actions workflow * Format tf code & regenerate docs * Use latest terraform version * Fix to use make build * Run workflow on pull_request too * Fix not to install terraform wrapper * Use shared elasticsearch password * Set ELASTIC_PASSWORD to elasticsearch container
1 parent 8c1a4d6 commit b357bbf

File tree

4 files changed

+125
-4
lines changed

4 files changed

+125
-4
lines changed

.github/workflows/test.yml

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
name: Build/Lint/Test
2+
on:
3+
push:
4+
paths-ignore:
5+
- 'README.md'
6+
- 'CHANGELOG.md'
7+
pull_request:
8+
paths-ignore:
9+
- 'README.md'
10+
- 'CHANGELOG.md'
11+
12+
permissions:
13+
contents: read
14+
15+
jobs:
16+
build:
17+
name: Build
18+
runs-on: ubuntu-latest
19+
timeout-minutes: 5
20+
steps:
21+
- uses: actions/checkout@v3
22+
- uses: actions/setup-go@v3
23+
with:
24+
go-version-file: 'go.mod'
25+
cache: true
26+
27+
- name: Get dependencies
28+
run: go mod download
29+
30+
- name: Build
31+
run: make build
32+
33+
lint:
34+
name: Lint
35+
runs-on: ubuntu-latest
36+
steps:
37+
- uses: actions/checkout@v3
38+
- uses: actions/setup-go@v3
39+
with:
40+
go-version-file: 'tools/go.mod'
41+
cache: true
42+
cache-dependency-path: tools/go.sum
43+
- uses: hashicorp/setup-terraform@v2
44+
with:
45+
terraform_wrapper: false
46+
47+
- name: Lint
48+
run: make lint
49+
50+
test:
51+
name: Matrix Acceptance Test
52+
needs: build
53+
runs-on: ubuntu-latest
54+
env:
55+
ELASTIC_PASSWORD: password
56+
services:
57+
elasticsearch:
58+
image: docker.elastic.co/elasticsearch/elasticsearch:${{ matrix.elasticsearch }}
59+
env:
60+
discovery.type: single-node
61+
xpack.security.enabled: true
62+
repositories.url.allowed_urls: https://example.com/*
63+
path.repo: /tmp
64+
ELASTIC_PASSWORD: ${{ env.ELASTIC_PASSWORD }}
65+
ports:
66+
- 9200:9200
67+
options: --health-cmd="curl http://localhost:9200/_cluster/health" --health-interval=10s --health-timeout=5s --health-retries=10
68+
timeout-minutes: 15
69+
strategy:
70+
fail-fast: false
71+
matrix:
72+
elasticsearch:
73+
- '7.11.2'
74+
- '7.12.1'
75+
- '7.13.4'
76+
- '7.14.2'
77+
- '7.15.2'
78+
- '7.16.3'
79+
- '7.17.4'
80+
- '8.0.1'
81+
- '8.1.3'
82+
- '8.2.2'
83+
steps:
84+
- uses: actions/checkout@v3
85+
- uses: actions/setup-go@v3
86+
with:
87+
go-version-file: 'go.mod'
88+
cache: true
89+
- uses: hashicorp/setup-terraform@v2
90+
with:
91+
terraform_wrapper: false
92+
93+
- name: Get dependencies
94+
run: go mod download
95+
96+
- name: TF acceptance tests
97+
timeout-minutes: 10
98+
run: make testacc
99+
env:
100+
TF_ACC: "1"
101+
ELASTICSEARCH_VERSION: ${{ matrix.elasticsearch }}
102+
ELASTICSEARCH_ENDPOINTS: "http://localhost:9200"
103+
ELASTICSEARCH_USERNAME: "elastic"
104+
ELASTICSEARCH_PASSWORD: ${{ env.ELASTIC_PASSWORD }}

Makefile

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ build: lint ## build the terraform provider
2525

2626

2727
.PHONY: testacc
28-
testacc: lint ## Run acceptance tests
28+
testacc: ## Run acceptance tests
2929
TF_ACC=1 go test -v ./... -count $(ACCTEST_COUNT) -parallel $(ACCTEST_PARALLELISM) $(TESTARGS) -timeout $(ACCTEST_TIMEOUT)
3030

3131

@@ -75,7 +75,24 @@ golangci-lint:
7575

7676

7777
.PHONY: lint
78-
lint: setup misspell golangci-lint ## Run lints to check the spelling and common go patterns
78+
lint: setup misspell golangci-lint check-fmt check-docs ## Run lints to check the spelling and common go patterns
79+
80+
.PHONY: fmt
81+
fmt: ## Format code
82+
go fmt ./...
83+
terraform fmt --recursive
84+
85+
.PHONY:check-fmt
86+
check-fmt: fmt ## Check if code is formatted
87+
@if [ "`git status --porcelain `" ]; then \
88+
echo "Unformatted files were detected. Please run 'make fmt' to format code, and commit the changes" && echo `git status --porcelain docs/` && exit 1; \
89+
fi
90+
91+
.PHONY: check-docs
92+
check-docs: docs-generate ## Check uncommitted changes on docs
93+
@if [ "`git status --porcelain docs/`" ]; then \
94+
echo "Uncommitted changes were detected in the docs folder. Please run 'make docs-generate' to autogenerate the docs, and commit the changes" && echo `git status --porcelain docs/` && exit 1; \
95+
fi
7996

8097

8198
.PHONY: setup

docs/resources/elasticsearch_index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ resource "elasticstack_elasticsearch_index" "my_index" {
2525
}
2626
2727
alias {
28-
name = "my_alias_2"
28+
name = "my_alias_2"
2929
filter = jsonencode({
3030
term = { "user.id" = "developer" }
3131
})

examples/resources/elasticstack_elasticsearch_index/resource.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ resource "elasticstack_elasticsearch_index" "my_index" {
1010
}
1111

1212
alias {
13-
name = "my_alias_2"
13+
name = "my_alias_2"
1414
filter = jsonencode({
1515
term = { "user.id" = "developer" }
1616
})

0 commit comments

Comments
 (0)