Skip to content

Commit

Permalink
Merge pull request #527 from MusicDin/cp/storage-bucket
Browse files Browse the repository at this point in the history
Add storage bucket resource
  • Loading branch information
MusicDin authored Sep 20, 2024
2 parents b409862 + 7ab7427 commit ee4297e
Show file tree
Hide file tree
Showing 8 changed files with 1,300 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,23 @@ jobs:
# Add HTTPS remote.
lxc remote add localhost "$(lxc config trust add --name lxd-terraform-provider --quiet)"
- name: Configure MinIO
run: |
arch=$(dpkg --print-architecture)
mkdir -p /opt/minio
# Download the minio server.
curl -sSfL "https://dl.min.io/server/minio/release/linux-${arch}/minio" --output "/opt/minio/minio"
chmod +x "/opt/minio/minio"
# Download the minio client.
curl -sSfL "https://dl.min.io/client/mc/release/linux-${arch}/mc" --output "/opt/minio/mc"
chmod +x "/opt/minio/mc"
# Set the snap config key for minio and reload LXD to have it take effect.
sudo snap set lxd minio.path=/opt/minio
sudo systemctl reload snap.lxd.daemon
- name: Configure OVN
run: |
sudo apt-get update
Expand Down
81 changes: 81 additions & 0 deletions docs/resources/storage_bucket.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# lxd_storage_bucket

Manages an LXD storage bucket.

## Example Usage

```hcl
resource "lxd_storage_pool" "pool" {
name = "mypool"
driver = "zfs"
}
resource "lxd_storage_bucket" "bucket" {
name = "mybucket"
pool = lxd_storage_pool.pool.name
}
```

## Argument Reference

* `name` - **Required** - Name of the storage bucket.

* `pool` - **Required** - Name of storage pool to host the storage bucket.

* `description` - *Optional* - Description of the storage bucket.

* `config` - *Optional* - Map of key/value pairs of
[storage bucket config settings](https://documentation.ubuntu.com/lxd/en/latest/howto/storage_buckets/#configure-storage-bucket-settings).
Note that config settings vary depending on the used storage pool.

* `project` - *Optional* - Name of the project where the storage bucket will be stored.

* `remote` - *Optional* - The remote in which the resource will be created. If
not provided, the provider's default remote will be used.

* `target` - *Optional* - Specify a target node in a cluster.


## Attribute Reference

The following attributes are exported:

* `location` - Name of the node where storage bucket was created.

## Importing

Import ID syntax: `[<remote>:][<project>]/<pool>/<name>`

* `<remote>` - *Optional* - Remote name.
* `<project>` - *Optional* - Project name.
* `<pool>` - **Required** - Storage pool name.
* `<name>` - **Required** - Storage bucket name.

### Import example

Example using terraform import command:

```shell
$ terraform import lxd_storage_bucket.bucket proj/mypool/mybucket
```

Example using the import block (only available in Terraform v1.5.0 and later):

```hcl
resource "lxd_storage_bucket" "bucket" {
name = "mybucket"
pool = "mypool"
project = "proj"
}
import {
to = lxd_storage_bucket.bucket
id = "proj/mypool/mybucket"
}
```

## Notes

* By default, LXD creates each storage bucket with an admin access key and a secret key.
Those keys can be imported using the `lxd_storage_bucket_key` resource.

92 changes: 92 additions & 0 deletions docs/resources/storage_bucket_key.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# lxd_storage_bucket_key

Manages an LXD storage bucket key.

~> **Warning:** The exported attributes `access_key` and `secret_key` are stored in the Terraform state as plain-text.
Read more about [sensitive data in state](https://www.terraform.io/language/state/sensitive-data).

## Example Usage

```hcl
resource "lxd_storage_pool" "pool" {
name = "mypool"
driver = "zfs"
}
resource "lxd_storage_bucket" "bucket" {
name = "mybucket"
pool = lxd_storage_pool.pool1.name
}
resource "lxd_storage_bucket_key" "key" {
name = "mykey"
pool = lxd_storage_bucket.bucket.pool
bucket = lxd_storage_bucket.bucket.name
}
```

## Argument Reference

* `name` - **Required** - Name of the storage bucket key.

* `pool` - **Required** - Name of storage pool to host the storage bucket key.

* `bucket` - **Required** - Name of the storage bucket.

* `description` - *Optional* - Description of the storage bucket key.

* `role` - *Optional* - Name of the role that controls the access rights for the key.
If not specified, the default role is used, as described in the [official documentation](https://documentation.ubuntu.com/lxd/en/latest/howto/storage_buckets/#manage-storage-bucket-keys).

* `project` - *Optional* - Name of the project where the storage bucket key will be stored.

* `remote` - *Optional* - The remote in which the resource will be created. If not provided,
the provider's default remote will be used.


## Attribute Reference

The following attributes are exported:

* `access_key` - Access key of the storage bucket key.

* `secret_key` - Secret key of the storage bucket key.

## Importing

Import ID syntax: `[<remote>:][<project>]/<pool>/<bucket>/<name>`

* `<remote>` - *Optional* - Remote name.
* `<project>` - *Optional* - Project name.
* `<pool>` - **Required** - Storage pool name.
* `<bucket>` - **Required** - Storage bucket name.
* `<name>` - **Required** - Storage bucket key name.

### Import example

Example using terraform import command:

```shell
$ terraform import lxd_storage_bucket_key.key proj/mypool/mybucket/mykey
```

Example using the import block (only available in Terraform v1.5.0 and later):

```hcl
resource "lxd_storage_bucket_key" "key" {
name = "mykey"
project = "proj"
pool = "mypool"
bucket = "mybucket"
}
import {
to = lxd_storage_bucket_key.key
id = "proj/mypool/mybucket/mykey"
}
```

## Notes

* By default, LXD creates each storage bucket with an admin access key and a secret key.
Those keys can be imported if needed.
2 changes: 2 additions & 0 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,8 @@ func (p *LxdProvider) Resources(_ context.Context) []func() resource.Resource {
network.NewNetworkZoneRecordResource,
profile.NewProfileResource,
project.NewProjectResource,
storage.NewStorageBucketResource,
storage.NewStorageBucketKeyResource,
storage.NewStoragePoolResource,
storage.NewStorageVolumeResource,
storage.NewStorageVolumeCopyResource,
Expand Down
Loading

0 comments on commit ee4297e

Please sign in to comment.