Skip to content

Commit

Permalink
Add organization_collection resource (#14)
Browse files Browse the repository at this point in the history
* Add organization_collection resource

* Fix issues with older versions
  • Loading branch information
ottramst authored Nov 20, 2024
1 parent cd517cb commit b181f4a
Show file tree
Hide file tree
Showing 19 changed files with 765 additions and 39 deletions.
49 changes: 49 additions & 0 deletions docs/resources/organization_collection.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "vaultwarden_organization_collection Resource - vaultwarden"
subcategory: ""
description: |-
This resource creates a Vaultwarden organization collection.
---

# vaultwarden_organization_collection (Resource)

This resource creates a Vaultwarden organization collection.

## Example Usage

```terraform
resource "vaultwarden_organization" "example" {
name = "Example"
}
resource "vaultwarden_organization_collection" "example" {
organization_id = vaultwarden_organization.example.id
name = "Example Collection"
}
```

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

### Required

- `name` (String) The name of the organization collection
- `organization_id` (String) ID of the organization that the collection belongs to

### Optional

- `external_id` (String) An optional identifier that can be assigned to the collection for integration with external systems. This identifier is not generated by Vaultwarden and must be provided explicitly. It is typically used to link the collection to external systems, such as directory services (e.g., LDAP, Active Directory) or custom automation workflows.

### Read-Only

- `id` (String) ID of the organization collection
- `last_updated` (String) Timestamp of the last update

## Import

Import is supported using the following syntax:

```shell
terraform import vaultwarden_organization_collection.example <org_id>/<id>
```
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
terraform import vaultwarden_organization_collection.example <org_id>/<id>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
resource "vaultwarden_organization" "example" {
name = "Example"
}

resource "vaultwarden_organization_collection" "example" {
organization_id = vaultwarden_organization.example.id
name = "Example Collection"
}
1 change: 1 addition & 0 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ func (p *VaultwardenProvider) Resources(ctx context.Context) []func() resource.R
return []func() resource.Resource{
UserInviteResource,
OrganizationResource,
OrganizationCollectionResource,
}
}

Expand Down
9 changes: 0 additions & 9 deletions internal/provider/resource_organization.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/hashicorp/terraform-plugin-log/tflog"
"github.com/ottramst/terraform-provider-vaultwarden/internal/vaultwarden"
"github.com/ottramst/terraform-provider-vaultwarden/internal/vaultwarden/models"
"time"
)

// Ensure provider defined types fully satisfy framework interfaces.
Expand All @@ -32,7 +31,6 @@ type Organization struct {
// OrganizationModel describes the resource data model.
type OrganizationModel struct {
ID types.String `tfsdk:"id"`
LastUpdated types.String `tfsdk:"last_updated"`
Name types.String `tfsdk:"name"`
BillingEmail types.String `tfsdk:"billing_email"`
CollectionName types.String `tfsdk:"collection_name"`
Expand All @@ -53,10 +51,6 @@ func (r *Organization) Schema(ctx context.Context, req resource.SchemaRequest, r
stringplanmodifier.UseStateForUnknown(),
},
},
"last_updated": schema.StringAttribute{
Computed: true,
MarkdownDescription: "Timestamp of the last update",
},
"name": schema.StringAttribute{
MarkdownDescription: "The name of the organization",
Required: true,
Expand Down Expand Up @@ -129,7 +123,6 @@ func (r *Organization) Create(ctx context.Context, req resource.CreateRequest, r
data.ID = types.StringValue(orgResp.ID)
data.Name = types.StringValue(orgResp.Name)
data.BillingEmail = types.StringValue(orgResp.BillingEmail)
data.LastUpdated = types.StringValue(time.Now().Format(time.RFC850))

// Write logs using the tflog package
// Documentation: https://terraform.io/plugin/log
Expand Down Expand Up @@ -191,8 +184,6 @@ func (r *Organization) Update(ctx context.Context, req resource.UpdateRequest, r
return
}

data.LastUpdated = types.StringValue(time.Now().Format(time.RFC850))

// Save updated data into Terraform state
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
}
Expand Down
Loading

0 comments on commit b181f4a

Please sign in to comment.