Skip to content

Commit

Permalink
Feat/add spaces data source (#1)
Browse files Browse the repository at this point in the history
* Add bonsai_space (GetByPath) and bonsai_spaces (List) data sources.

* Add docs gen tooling; refactor spaces and examples a bit.

* Add Space Acceptance tests.

* Add pre-commit task for docs

* Bump timeout-minutes on build

* Add details about usage

* Update commented out test output
  • Loading branch information
momer authored May 13, 2024
1 parent c88c60b commit 918655c
Show file tree
Hide file tree
Showing 22 changed files with 855 additions and 50 deletions.
1 change: 0 additions & 1 deletion .github/CODEOWNERS

This file was deleted.

5 changes: 0 additions & 5 deletions .github/CODE_OF_CONDUCT.md

This file was deleted.

111 changes: 82 additions & 29 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,48 +11,89 @@ on:
paths-ignore:
- 'README.md'

# Testing only needs permissions to read the repository contents.
permissions:
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}

env:
GOPRIVATE: github.com/omc

jobs:
# Ensure project builds before running testing matrix
build:
name: Build
runs-on: ubuntu-latest
timeout-minutes: 5
timeout-minutes: 15
steps:
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
- uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
- uses: actions/[email protected].5
- uses: actions/[email protected].1
with:
go-version-file: 'go.mod'
cache: true
- name: Install Task
uses: arduino/setup-task@v2
with:
version: "3.x"
- name: Check out code into the Go module directory
uses: actions/[email protected]
- name: Add SSH Go Module Private Key
env:
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
run: |
mkdir -p ~/.ssh
ssh-keyscan github.com >> ~/.ssh/known_hosts
ssh-agent -a $SSH_AUTH_SOCK > /dev/null
ssh-add - <<< "${{ secrets.GO_MODULE_PRIVATE_KEY }}"
echo "SSH_AUTH_SOCK=$SSH_AUTH_SOCK" >> $GITHUB_ENV
- name: Setup access for private go modules
run: |
git config --global url."ssh://[email protected]/".insteadOf https://github.com/
- run: go mod download
- run: go build -v .
- name: Run linters
- name: Build
run: task build
- name: Run golangci-lint
uses: golangci/golangci-lint-action@82d40c283aeb1f2b6595839195e95c2d6a49081b # v5.0.0
with:
version: latest
- name: Run additional linters
run: task lint

generate:
# source: https://github.com/vercel/terraform-provider-vercel
# source license: MPL-2.0
docs:
name: Docs Test
timeout-minutes: 5
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
- uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
- name: Set up Go
uses: actions/[email protected].1
with:
go-version-file: 'go.mod'
cache: true
# Temporarily download Terraform 1.8 prerelease for function documentation support.
# When Terraform 1.8.0 final is released, this can be removed.
- uses: hashicorp/setup-terraform@651471c36a6092792c552e8b1bef71e592b462d8 # v3.1.1
go-version: "1.22"
id: go
- name: Install Task
uses: arduino/setup-task@v2
with:
terraform_version: '1.8.0-alpha20240216'
terraform_wrapper: false
- run: go generate ./...
- name: git diff
version: "3.x"
- name: Add SSH Go Module Private Key
env:
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
run: |
mkdir -p ~/.ssh
ssh-keyscan github.com >> ~/.ssh/known_hosts
ssh-agent -a $SSH_AUTH_SOCK > /dev/null
ssh-add - <<< "${{ secrets.GO_MODULE_PRIVATE_KEY }}"
echo "SSH_AUTH_SOCK=$SSH_AUTH_SOCK" >> $GITHUB_ENV
- name: Setup access for private go modules
run: |
git diff --compact-summary --exit-code || \
(echo; echo "Unexpected difference in directories after code generation. Run 'go generate ./...' command and commit."; exit 1)
git config --global url."ssh://[email protected]/".insteadOf https://github.com/
- name: Check out code into the Go module directory
uses: actions/[email protected]
- name: Check if docs are up-to-date
run: |
task docs
git diff
BADDOCS=$(git status --porcelain)
test -z "$BADDOCS" || (echo -e "documentation needs regenerating using task docs: $BADDOCS"; exit 1)
# Run acceptance tests in a matrix with Terraform CLI versions
test:
Expand All @@ -63,23 +104,35 @@ jobs:
strategy:
fail-fast: false
matrix:
opentofu:
- '1.6.*'
- '1.7.*'
# list whatever Terraform versions here you would like to support
terraform:
- '1.0.*'
- '1.1.*'
- '1.2.*'
- '1.3.*'
- '1.4.*'
- '1.7.*'
- '1.8.*'
steps:
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
- uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
- uses: actions/[email protected].5
- uses: actions/[email protected].1
with:
go-version-file: 'go.mod'
cache: true
- uses: hashicorp/setup-terraform@651471c36a6092792c552e8b1bef71e592b462d8 # v3.1.1
with:
terraform_version: ${{ matrix.terraform }}
terraform_wrapper: false
- name: Add SSH Go Module Private Key
env:
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
run: |
mkdir -p ~/.ssh
ssh-keyscan github.com >> ~/.ssh/known_hosts
ssh-agent -a $SSH_AUTH_SOCK > /dev/null
ssh-add - <<< "${{ secrets.GO_MODULE_PRIVATE_KEY }}"
echo "SSH_AUTH_SOCK=$SSH_AUTH_SOCK" >> $GITHUB_ENV
- name: Setup access for private go modules
run: |
git config --global url."ssh://[email protected]/".insteadOf https://github.com/
- run: go mod download
- env:
TF_ACC: "1"
Expand Down
13 changes: 12 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,15 @@ repos:
rev: v1.89.1 # Get the latest from: https://github.com/antonbabenko/pre-commit-terraform/releases
hooks:
- id: terraform_fmt
- id: terraform_docs
args: [ --hook-config=--parallelism-ci-cpu-cores=8 ]
- id: terraform_docs
- repo: local
hooks:
- id: task-docs
name: task-docs
description: Run the docs task for documentation generation
entry: task docs
types: [ go ]
language: system
require_serial: true
pass_filenames: false
1 change: 1 addition & 0 deletions .task/checksum/docs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
30130b5de9de24c4ab560530998ab6f4
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

![Bonsai | Fully Managed Elasticsearch & OpenSearch](docs/assets/bonsai.png)

This is the Go API Client for [Bonsai Cloud](https://bonsai.io/) - The only
This is the Terraform Provider for [Bonsai Cloud](https://bonsai.io/) - The only
managed Elasticsearch, OpenSearch, and SolrCloud platform that provides the
support of a search engineering team, but at a fraction of the cost!

Expand All @@ -12,3 +12,13 @@ support of a search engineering team, but at a fraction of the cost!
- [Go](https://golang.org/doc/install) >= 1.21

## Using the provider

Details on usage can be found at:

- [Markdown documentation](./docs/index.md)
- [Provider documentation @ Terraform Registry](https://registry.terraform.io/providers/omc/terraform-provider-bonsai/latest/docs)
- [Examples](./examples)

## Contributing

See [CONTRIBUTING.md](CONTRIBUTING.md)
108 changes: 108 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# source: https://github.com/vercel/terraform-provider-vercel
# source license: MPL-2.0

# https://taskfile.dev
version: "3"

tasks:
build:
desc: "Build the provider binary"
deps:
- install-goreleaser
cmds:
- goreleaser build --single-target --skip=validate --clean --snapshot
sources:
- "**/*.go"
- go.mod
- go.sum
generates:
- terraform-provider-bonsai

test:
desc: "Run acceptance tests against the provider"
env:
TF_ACC: "1"
cmds:
- go test ./... {{.CLI_ARGS}}

install-tfplugindocs:
desc: "Install the tfplugindocs tool"
cmds:
- go install github.com/hashicorp/terraform-plugin-docs/cmd/[email protected]
status:
- which tfplugindocs

install-goreleaser:
desc: "Install goreleaser"
cmds:
- go install github.com/goreleaser/goreleaser@latest
status:
- which goreleaser

docs:
desc: "Update the docs generated from description fields"
deps:
- install-tfplugindocs
cmds:
- tfplugindocs
- sed -i.bak 's/bonsai Provider/Bonsai Provider/g' docs/index.md
- rm docs/index.md.bak
sources:
- "internal/**/*.go"
- "main.go"
- "examples/**/*.tf"
- "examples/**/*.sh"
generates:
- docs/**/*.md

install-staticcheck:
desc: "Install the staticheck tool"
cmds:
- go install honnef.co/go/tools/cmd/[email protected]
status:
- which staticcheck

install-providerlint:
desc: "Install tfproviderlint tool"
cmds:
- go install github.com/bflad/tfproviderlint/cmd/tfproviderlint@latest
status:
- which tfproviderlint

lint:
desc: "Run linters against the provider"
deps:
- install-staticcheck
- install-providerlint
cmds:
- staticcheck -tags it ./...
- tfproviderlint -R018=false ./...
- cmd: |
export BADFMT=$(gofmt -s -l .)
test -z "$BADFMT" || (echo -e "invalid gofmt: $BADFMT"; exit 1)
silent: true
- go vet ./...

install:
desc: "Set up an override allowing a local version of the provider to be used"
cmds:
- cmd: |-
cat << EOF > ~/.terraformrc
provider_installation {
dev_overrides {
"omc/bonsai" = "$(pwd)/dist/terraform-provider-vercel_{{ OS }}_{{ ARCH }}"
}
direct {}
}
EOF
uninstall:
desc: "Remove any local overrides for local development"
cmds:
- rm ~/.terraformrc

sweep:
desc: "Remove any leftover resources from failed test runs"
dir: "sweep"
cmds:
- go run .
39 changes: 39 additions & 0 deletions docs/data-sources/space.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "bonsai_space Data Source - terraform-provider-bonsai"
subcategory: ""
description: |-
A Space represents the server groups and geographic regions available to a Bonsai.io https://bonsai.io account, where clusters may be provisioned.
---

# bonsai_space (Data Source)

A Space represents the server groups and geographic regions available to a [Bonsai.io](https://bonsai.io) account, where clusters may be provisioned.

## Example Usage

```terraform
data "bonsai_space" "example" {
path = "omc/websolr/us-east-1/common"
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Optional

- `path` (String) A machine-readable name for the server group.

### Read-Only

- `cloud` (Attributes) Details about the cloud provider and region attributes. (see [below for nested schema](#nestedatt--cloud))
- `private_network` (Boolean) Indicates whether the space is isolated and inaccessible from the public Internet. A VPC connection will be needed to communicate with a private cluster.

<a id="nestedatt--cloud"></a>
### Nested Schema for `cloud`

Read-Only:

- `provider` (String) A machine-readable name for the cloud provider in which this space is deployed.
- `region` (String) A machine-readable name for the geographic region of the server group.
Loading

0 comments on commit 918655c

Please sign in to comment.