Skip to content

Commit

Permalink
Merge pull request #4 from OneSignal/initial_bw_client
Browse files Browse the repository at this point in the history
Implement BitWarden Group
  • Loading branch information
niels-s authored Oct 6, 2023
2 parents 9efd86b + c119f19 commit 3814fac
Show file tree
Hide file tree
Showing 30 changed files with 902 additions and 612 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @hashicorp/terraform-devex
* @eng-platform
7 changes: 3 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,8 @@ jobs:
matrix:
# list whatever Terraform versions here you would like to support
terraform:
- '1.0.*'
- '1.1.*'
- '1.2.*'
- '1.3.*'
- '1.4.*'
- '1.5.*'
steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- uses: actions/setup-go@fac708d6674e30b6ba41289acaab6d4b75aa0753 # v4.0.1
Expand All @@ -76,6 +73,8 @@ jobs:
terraform_wrapper: false
- run: go mod download
- env:
BITWARDEN_CLIENT_ID: ${{ secrets.BITWARDEN_CLIENT_ID }}
BITWARDEN_CLIENT_SECRET: ${{ secrets.BITWARDEN_CLIENT_SECRET }}
TF_ACC: "1"
run: go test -v -cover ./internal/provider/
timeout-minutes: 10
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ website/node_modules

website/vendor

# Ignore state files from examples

examples/**/*.tfstate*

# Test exclusions
!command/test-fixtures/**/*.tfstate
!command/test-fixtures/**/.terraform/
Expand Down
3 changes: 2 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ linters:
- forcetypeassert
- godot
- gofmt
- goimports
- gosimple
- ineffassign
- makezero
Expand All @@ -24,4 +25,4 @@ linters:
- unconvert
- unparam
- unused
- vet
- vet
3 changes: 2 additions & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ checksum:
signs:
- artifacts: checksum
args:
# if you are using this in a GitHub action or some other automated pipeline, you
# 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"
Expand All @@ -58,3 +58,4 @@ release:
# draft: true
changelog:
skip: true
use: github
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 0.1.0 (Unreleased)

FEATURES:

- Implement a first pass on a Bitwarden Provider that directly integrates with the Bitwarden API. This initial
release focusses on Group and Group Member management.
65 changes: 38 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
# Terraform Provider Scaffolding (Terraform Plugin Framework)
# Bitwarden Terraform Provider

_This template repository is built on the [Terraform Plugin Framework](https://github.com/hashicorp/terraform-plugin-framework). The template repository built on the [Terraform Plugin SDK](https://github.com/hashicorp/terraform-plugin-sdk) can be found at [terraform-provider-scaffolding](https://github.com/hashicorp/terraform-provider-scaffolding). See [Which SDK Should I Use?](https://developer.hashicorp.com/terraform/plugin/framework-benefits) in the Terraform documentation for additional information._

This repository is a *template* for a [Terraform](https://www.terraform.io) provider. It is intended as a starting point for creating Terraform providers, containing:

- A resource and a data source (`internal/provider/`),
- Examples (`examples/`) and generated documentation (`docs/`),
- Miscellaneous meta files.

These files contain boilerplate code that you will need to edit to create your own Terraform provider. Tutorials for creating Terraform providers can be found on the [HashiCorp Developer](https://developer.hashicorp.com/terraform/tutorials/providers-plugin-framework) platform. _Terraform Plugin Framework specific guides are titled accordingly._

Please see the [GitHub template repository documentation](https://help.github.com/en/github/creating-cloning-and-archiving-repositories/creating-a-repository-from-a-template) for how to create a new repository from this template on GitHub.

Once you've written your provider, you'll want to [publish it on the Terraform Registry](https://developer.hashicorp.com/terraform/registry/providers/publishing) so that others can use it.
_This template repository is built on the [Terraform Plugin Framework](https://github.com/hashicorp/terraform-plugin-framework)._

## Requirements

Expand All @@ -29,29 +17,42 @@ Once you've written your provider, you'll want to [publish it on the Terraform R
go install
```

## Adding Dependencies
## Using the provider

This provider uses [Go modules](https://github.com/golang/go/wiki/Modules).
Please see the Go documentation for the most up to date information about using Go modules.
This provider is intended to manage users and groups in Bitwarden for an organisation.

To add a new dependency `github.com/author/dependency` to your Terraform provider:
```hcl
provider "bitwarden" {
# Configure the authentication values needed to authenticate with Bitwarden API.
# More information can be found here: https://bitwarden.com/help/public-api/#authentication
client_id = "client_id"
client_secret = "client_api_secret"
}
```shell
go get github.com/author/dependency
go mod tidy
resource "bitwarden_group" "example" {
name = "example"
}
```

Then commit the changes to `go.mod` and `go.sum`.

## Using the provider

Fill this in for each provider

## Developing the Provider

If you wish to work on the provider, you'll first need [Go](http://www.golang.org) installed on your machine (see [Requirements](#requirements) above).

To compile the provider, run `go install`. This will build the provider and put the provider binary in the `$GOPATH/bin` directory.
If you like to test it out, you will need to create a `~/.terraformrc` file for the `dev_overrides`
```hcl
provider_installation {
dev_overrides {
"onesignal/bitwarden" = "<PATH>"
}
# For all other providers, install them directly from their origin provider
# registries as normal. If you omit this, Terraform will _only_ use
# the dev_overrides block, and so no other providers will be available.
direct {}
}
```

To generate or update documentation, run `go generate`.

Expand All @@ -60,5 +61,15 @@ In order to run the full suite of Acceptance tests, run `make testacc`.
*Note:* Acceptance tests create real resources, and often cost money to run.

```shell
export BITWARDEN_CLIENT_ID="organization.xxxx"
export BITWARDEN_CLIENT_SECRET="xxx"
make testacc
```


## TODOs

- [ ] implement group members
- [ ] gracefully handle 404 when group is manually deleted? How do we do that?
- [ ] ensure urls don't end on trailing /, use validators?
- [ ] Add docs to group resource
30 changes: 0 additions & 30 deletions docs/data-sources/scaffolding_example.md

This file was deleted.

20 changes: 13 additions & 7 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "scaffolding-framework Provider"
page_title: "bitwarden Provider"
subcategory: ""
description: |-
Bitwarden API Provider, focussing on Group and Group Members for organisations
---

# scaffolding-framework Provider

# bitwarden Provider

Bitwarden API Provider, focussing on Group and Group Members for organisations

## Example Usage

```terraform
provider "scaffolding" {
# example configuration here
provider "bitwarden" {
# Configure the authentication values needed to authenticate with Bitwarden API.
# More information can be found here: https://bitwarden.com/help/public-api/#authentication
client_id = "organization.xxx"
client_secret = "client_api_secret"
}
```

Expand All @@ -23,4 +26,7 @@ provider "scaffolding" {

### Optional

- `endpoint` (String) Example provider attribute
- `api_url` (String) The Bitwarden API URL, defaults to `https://api.bitwarden.com`, can also be configured as `BITWARDEN_API_URL`. See [docs](https://bitwarden.com/help/public-api/#endpoints) for more information
- `authentication_url` (String) The Bitwarden Authentication URL, defaults to `https://identity.bitwarden.com/connect/token`, can also be configured as `BITWARDEN_AUTH_URL`. See [docs](https://bitwarden.com/help/public-api/#authentication-endpoints) for more information
- `client_id` (String) The client_id of your organisation, can also be configured as `BITWARDEN_CLIENT_ID`. See [docs](https://bitwarden.com/help/public-api/#authentication) for more information
- `client_secret` (String, Sensitive) The client_secret of your organisation, can also be configured as `BITWARDEN_CLIENT_SECRET`. See [docs](https://bitwarden.com/help/public-api/#authentication) for more information
37 changes: 37 additions & 0 deletions docs/resources/group.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "bitwarden_group Resource - terraform-provider-bitwarden"
subcategory: ""
description: |-
---

# bitwarden_group (Resource)



## Example Usage

```terraform
resource "bitwarden_group" "example" {
name = "example-group"
access_all = true
}
```

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

### Required

- `name` (String)

### Optional

- `access_all` (Boolean)
- `external_id` (String)

### Read-Only

- `id` (String) The ID of this resource.
- `last_updated` (String)
31 changes: 0 additions & 31 deletions docs/resources/scaffolding_example.md

This file was deleted.

7 changes: 5 additions & 2 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# Examples

This directory contains examples that are mostly used for documentation, but can also be run/tested manually via the Terraform CLI.
This directory contains examples that are mostly used for documentation, but can also be run/tested manually via the
Terraform CLI.

The document generation tool looks for files in the following locations by default. All other *.tf files besides the ones mentioned below are ignored by the documentation tool. This is useful for creating examples that can run and/or ar testable even if some parts are not relevant for the documentation.
The document generation tool looks for files in the following locations by default. All other *.tf files besides the
ones mentioned below are ignored by the documentation tool. This is useful for creating examples that can run and/or are
testable even if some parts are not relevant for the documentation.

* **provider/provider.tf** example file for the provider index page
* **data-sources/`full data source name`/data-source.tf** example file for the named data source page
Expand Down
3 changes: 0 additions & 3 deletions examples/data-sources/scaffolding_example/data-source.tf

This file was deleted.

22 changes: 22 additions & 0 deletions examples/provider-install-verification/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
terraform {
required_providers {
bitwarden = {
source = "onesignal/bitwarden"
}
}
}

# export BITWARDEN_CLIENT_ID=""
# export BITWARDEN_CLIENT_SECRET=""
provider "bitwarden" {
}


resource "bitwarden_group" "example" {
name = "example"
access_all = true
}

output "test" {
value = bitwarden_group.example
}
7 changes: 5 additions & 2 deletions examples/provider/provider.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
provider "scaffolding" {
# example configuration here
provider "bitwarden" {
# Configure the authentication values needed to authenticate with Bitwarden API.
# More information can be found here: https://bitwarden.com/help/public-api/#authentication
client_id = "organization.xxx"
client_secret = "client_api_secret"
}
4 changes: 4 additions & 0 deletions examples/resources/bitwarden_group/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resource "bitwarden_group" "example" {
name = "example-group"
access_all = true
}
3 changes: 0 additions & 3 deletions examples/resources/scaffolding_example/resource.tf

This file was deleted.

Loading

0 comments on commit 3814fac

Please sign in to comment.