Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions docs/data-sources/objectstorage_bucket.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,25 @@ description: |-

ObjectStorage bucket data source schema.

## Example Usage

```terraform
data "stackit_objectstorage_bucket" "example" {
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
name = "example-name"
}
```

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

### Required

- `bucket_name` (String) The bucket name. It must be DNS conform.
- `name` (String) The bucket name. It must be DNS conform.
- `project_id` (String) STACKIT Project ID to which the bucket is associated.

### Read-Only

- `id` (String) Terraform's internal data source identifier. It is structured as "`project_id`,`bucket_name`".
- `id` (String) Terraform's internal data source identifier. It is structured as "`project_id`,`name`".
- `url_path_style` (String)
- `url_virtual_hosted_style` (String)
10 changes: 9 additions & 1 deletion docs/data-sources/objectstorage_credential.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,15 @@ description: |-

ObjectStorage credential data source schema.


## Example Usage

```terraform
data "stackit_objectstorage_credentials_group" "example" {
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
credentials_group_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
credential_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
}
```

<!-- schema generated by tfplugindocs -->
## Schema
Expand Down
9 changes: 8 additions & 1 deletion docs/data-sources/objectstorage_credentials_group.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@ description: |-

ObjectStorage credentials group data source schema.


## Example Usage

```terraform
data "stackit_objectstorage_credentials_group" "example" {
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
credentials_group_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
}
```

<!-- schema generated by tfplugindocs -->
## Schema
Expand Down
11 changes: 9 additions & 2 deletions docs/resources/objectstorage_bucket.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,25 @@ description: |-

ObjectStorage bucket resource schema.

## Example Usage

```terraform
resource "stackit_objectstorage_bucket" "example" {
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
name = "example-bucket"
}
```

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

### Required

- `bucket_name` (String) The bucket name. It must be DNS conform.
- `name` (String) The bucket name. It must be DNS conform.
- `project_id` (String) STACKIT Project ID to which the bucket is associated.

### Read-Only

- `id` (String) Terraform's internal resource identifier. It is structured as "`project_id`,`bucket_name`".
- `id` (String) Terraform's internal resource identifier. It is structured as "`project_id`,`name`".
- `url_path_style` (String)
- `url_virtual_hosted_style` (String)
10 changes: 9 additions & 1 deletion docs/resources/objectstorage_credential.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,15 @@ description: |-

ObjectStorage credential resource schema.


## Example Usage

```terraform
resource "stackit_objectstorage_credential" "example" {
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
credentials_group_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
expiration_timestamp = "2027-01-02T03:04:05Z"
}
```

<!-- schema generated by tfplugindocs -->
## Schema
Expand Down
9 changes: 8 additions & 1 deletion docs/resources/objectstorage_credentials_group.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@ description: |-

ObjectStorage credentials group resource schema.


## Example Usage

```terraform
resource "stackit_objectstorage_credentials_group" "example" {
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
name = "example-credentials-group"
}
```

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

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
data "stackit_objectstorage_bucket" "example" {
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
name = "example-name"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
data "stackit_objectstorage_credentials_group" "example" {
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
credentials_group_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
credential_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
}

This file was deleted.

4 changes: 4 additions & 0 deletions examples/resources/stackit_objectstorage_bucket/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resource "stackit_objectstorage_bucket" "example" {
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
name = "example-bucket"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
resource "stackit_objectstorage_credential" "example" {
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
credentials_group_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
expiration_timestamp = "2027-01-02T03:04:05Z"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
resource "stackit_object_storage_credentials_group" "example" {
resource "stackit_objectstorage_credentials_group" "example" {
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
name = "example-credentials-group"
}
12 changes: 6 additions & 6 deletions stackit/internal/services/objectstorage/bucket/datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ func (r *bucketDataSource) Configure(ctx context.Context, req datasource.Configu
func (r *bucketDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
descriptions := map[string]string{
"main": "ObjectStorage bucket data source schema.",
"id": "Terraform's internal data source identifier. It is structured as \"`project_id`,`bucket_name`\".",
"bucket_name": "The bucket name. It must be DNS conform.",
"id": "Terraform's internal data source identifier. It is structured as \"`project_id`,`name`\".",
"name": "The bucket name. It must be DNS conform.",
"project_id": "STACKIT Project ID to which the bucket is associated.",
"url_path_style": "URL in path style.",
"url_virtual_hosted_style": "URL in virtual hosted style.",
Expand All @@ -89,8 +89,8 @@ func (r *bucketDataSource) Schema(_ context.Context, _ datasource.SchemaRequest,
Description: descriptions["id"],
Computed: true,
},
"bucket_name": schema.StringAttribute{
Description: descriptions["bucket_name"],
"name": schema.StringAttribute{
Description: descriptions["name"],
Required: true,
Validators: []validator.String{
validate.NoSeparator(),
Expand Down Expand Up @@ -123,9 +123,9 @@ func (r *bucketDataSource) Read(ctx context.Context, req datasource.ReadRequest,
return
}
projectId := model.ProjectId.ValueString()
bucketName := model.BucketName.ValueString()
bucketName := model.Name.ValueString()
ctx = tflog.SetField(ctx, "project_id", projectId)
ctx = tflog.SetField(ctx, "bucket_name", bucketName)
ctx = tflog.SetField(ctx, "name", bucketName)

bucketResp, err := r.client.GetBucket(ctx, projectId, bucketName).Execute()
if err != nil {
Expand Down
30 changes: 15 additions & 15 deletions stackit/internal/services/objectstorage/bucket/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var (

type Model struct {
Id types.String `tfsdk:"id"` // needed by TF
BucketName types.String `tfsdk:"bucket_name"`
Name types.String `tfsdk:"name"`
ProjectId types.String `tfsdk:"project_id"`
URLPathStyle types.String `tfsdk:"url_path_style"`
URLVirtualHostedStyle types.String `tfsdk:"url_virtual_hosted_style"`
Expand Down Expand Up @@ -92,8 +92,8 @@ func (r *bucketResource) Configure(ctx context.Context, req resource.ConfigureRe
func (r *bucketResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
descriptions := map[string]string{
"main": "ObjectStorage bucket resource schema.",
"id": "Terraform's internal resource identifier. It is structured as \"`project_id`,`bucket_name`\".",
"bucket_name": "The bucket name. It must be DNS conform.",
"id": "Terraform's internal resource identifier. It is structured as \"`project_id`,`name`\".",
"name": "The bucket name. It must be DNS conform.",
"project_id": "STACKIT Project ID to which the bucket is associated.",
"url_path_style": "URL in path style.",
"url_virtual_hosted_style": "URL in virtual hosted style.",
Expand All @@ -109,8 +109,8 @@ func (r *bucketResource) Schema(_ context.Context, _ resource.SchemaRequest, res
stringplanmodifier.UseStateForUnknown(),
},
},
"bucket_name": schema.StringAttribute{
Description: descriptions["bucket_name"],
"name": schema.StringAttribute{
Description: descriptions["name"],
Required: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.RequiresReplace(),
Expand Down Expand Up @@ -151,9 +151,9 @@ func (r *bucketResource) Create(ctx context.Context, req resource.CreateRequest,
return
}
projectId := model.ProjectId.ValueString()
bucketName := model.BucketName.ValueString()
bucketName := model.Name.ValueString()
ctx = tflog.SetField(ctx, "project_id", projectId)
ctx = tflog.SetField(ctx, "bucket_name", bucketName)
ctx = tflog.SetField(ctx, "name", bucketName)

// Handle project init
err := enableProject(ctx, &model, r.client)
Expand Down Expand Up @@ -203,9 +203,9 @@ func (r *bucketResource) Read(ctx context.Context, req resource.ReadRequest, res
return
}
projectId := model.ProjectId.ValueString()
bucketName := model.BucketName.ValueString()
bucketName := model.Name.ValueString()
ctx = tflog.SetField(ctx, "project_id", projectId)
ctx = tflog.SetField(ctx, "bucket_name", bucketName)
ctx = tflog.SetField(ctx, "name", bucketName)

bucketResp, err := r.client.GetBucket(ctx, projectId, bucketName).Execute()
if err != nil {
Expand Down Expand Up @@ -244,9 +244,9 @@ func (r *bucketResource) Delete(ctx context.Context, req resource.DeleteRequest,
return
}
projectId := model.ProjectId.ValueString()
bucketName := model.BucketName.ValueString()
bucketName := model.Name.ValueString()
ctx = tflog.SetField(ctx, "project_id", projectId)
ctx = tflog.SetField(ctx, "bucket_name", bucketName)
ctx = tflog.SetField(ctx, "name", bucketName)

// Delete existing bucket
_, err := r.client.DeleteBucket(ctx, projectId, bucketName).Execute()
Expand All @@ -262,19 +262,19 @@ func (r *bucketResource) Delete(ctx context.Context, req resource.DeleteRequest,
}

// ImportState imports a resource into the Terraform state on success.
// The expected format of the resource import identifier is: project_id,bucket_name
// The expected format of the resource import identifier is: project_id,name
func (r *bucketResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
idParts := strings.Split(req.ID, core.Separator)
if len(idParts) != 2 || idParts[0] == "" || idParts[1] == "" {
core.LogAndAddError(ctx, &resp.Diagnostics,
"Error importing bucket",
fmt.Sprintf("Expected import identifier with format [project_id],[bucket_name], got %q", req.ID),
fmt.Sprintf("Expected import identifier with format [project_id],[name], got %q", req.ID),
)
return
}

resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("project_id"), idParts[0])...)
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("bucket_name"), idParts[1])...)
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("name"), idParts[1])...)
tflog.Info(ctx, "ObjectStorage bucket state imported")
}

Expand All @@ -292,7 +292,7 @@ func mapFields(bucketResp *objectstorage.GetBucketResponse, model *Model) error

idParts := []string{
model.ProjectId.ValueString(),
model.BucketName.ValueString(),
model.Name.ValueString(),
}
model.Id = types.StringValue(
strings.Join(idParts, core.Separator),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestMapFields(t *testing.T) {
},
Model{
Id: types.StringValue("pid,bname"),
BucketName: types.StringValue("bname"),
Name: types.StringValue("bname"),
ProjectId: types.StringValue("pid"),
URLPathStyle: types.StringNull(),
URLVirtualHostedStyle: types.StringNull(),
Expand All @@ -56,7 +56,7 @@ func TestMapFields(t *testing.T) {
},
Model{
Id: types.StringValue("pid,bname"),
BucketName: types.StringValue("bname"),
Name: types.StringValue("bname"),
ProjectId: types.StringValue("pid"),
URLPathStyle: types.StringValue("url/path/style"),
URLVirtualHostedStyle: types.StringValue("url/virtual/hosted/style"),
Expand All @@ -73,7 +73,7 @@ func TestMapFields(t *testing.T) {
},
Model{
Id: types.StringValue("pid,bname"),
BucketName: types.StringValue("bname"),
Name: types.StringValue("bname"),
ProjectId: types.StringValue("pid"),
URLPathStyle: types.StringValue(""),
URLVirtualHostedStyle: types.StringValue(""),
Expand All @@ -96,8 +96,8 @@ func TestMapFields(t *testing.T) {
for _, tt := range tests {
t.Run(tt.description, func(t *testing.T) {
model := &Model{
ProjectId: tt.expected.ProjectId,
BucketName: tt.expected.BucketName,
ProjectId: tt.expected.ProjectId,
Name: tt.expected.Name,
}
err := mapFields(tt.input, model)
if !tt.isValid && err == nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import (

// Bucket resource data
var bucketResource = map[string]string{
"project_id": testutil.ProjectId,
"bucket_name": fmt.Sprintf("acc-test-%s", acctest.RandStringFromCharSet(20, acctest.CharSetAlpha)),
"project_id": testutil.ProjectId,
"name": fmt.Sprintf("acc-test-%s", acctest.RandStringFromCharSet(20, acctest.CharSetAlpha)),
}

// Credentials group resource data
Expand All @@ -41,7 +41,7 @@ func resourceConfig() string {

resource "stackit_objectstorage_bucket" "bucket" {
project_id = "%s"
bucket_name = "%s"
name = "%s"
}

resource "stackit_objectstorage_credentials_group" "credentials_group" {
Expand All @@ -57,7 +57,7 @@ func resourceConfig() string {
`,
testutil.ObjectStorageProviderConfig(),
bucketResource["project_id"],
bucketResource["bucket_name"],
bucketResource["name"],
credentialsGroupResource["project_id"],
credentialsGroupResource["name"],
credentialResource["expiration_timestamp"],
Expand All @@ -76,7 +76,7 @@ func TestAccObjectStorageResource(t *testing.T) {
Check: resource.ComposeAggregateTestCheckFunc(
// Bucket data
resource.TestCheckResourceAttr("stackit_objectstorage_bucket.bucket", "project_id", bucketResource["project_id"]),
resource.TestCheckResourceAttr("stackit_objectstorage_bucket.bucket", "bucket_name", bucketResource["bucket_name"]),
resource.TestCheckResourceAttr("stackit_objectstorage_bucket.bucket", "name", bucketResource["name"]),
resource.TestCheckResourceAttrSet("stackit_objectstorage_bucket.bucket", "url_path_style"),
resource.TestCheckResourceAttrSet("stackit_objectstorage_bucket.bucket", "url_virtual_hosted_style"),

Expand Down Expand Up @@ -109,7 +109,7 @@ func TestAccObjectStorageResource(t *testing.T) {

data "stackit_objectstorage_bucket" "bucket" {
project_id = stackit_objectstorage_bucket.bucket.project_id
bucket_name = stackit_objectstorage_bucket.bucket.bucket_name
name = stackit_objectstorage_bucket.bucket.name
}

data "stackit_objectstorage_credentials_group" "credentials_group" {
Expand All @@ -128,8 +128,8 @@ func TestAccObjectStorageResource(t *testing.T) {
// Bucket data
resource.TestCheckResourceAttr("data.stackit_objectstorage_bucket.bucket", "project_id", bucketResource["project_id"]),
resource.TestCheckResourceAttrPair(
"stackit_objectstorage_bucket.bucket", "bucket_name",
"data.stackit_objectstorage_bucket.bucket", "bucket_name",
"stackit_objectstorage_bucket.bucket", "name",
"data.stackit_objectstorage_bucket.bucket", "name",
),
resource.TestCheckResourceAttrPair(
"stackit_objectstorage_bucket.bucket", "url_path_style",
Expand Down Expand Up @@ -244,7 +244,7 @@ func testAccCheckObjectStorageDestroy(s *terraform.State) error {
if rs.Type != "stackit_objectstorage_bucket" {
continue
}
// bucket terraform ID: "[project_id],[bucket_name]"
// bucket terraform ID: "[project_id],[name]"
bucketName := strings.Split(rs.Primary.ID, core.Separator)[1]
bucketsToDestroy = append(bucketsToDestroy, bucketName)
}
Expand Down