Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: managed object storage support #418

Merged
merged 9 commits into from
Oct 20, 2023
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ See updating [Changelog example here](https://keepachangelog.com/en/1.0.0/)
- dbaas: `upcloud_managed_database_mysql_sessions`, `upcloud_managed_database_postgresql_sessions` and `upcloud_managed_database_redis_sessions` data sources
- network: `dhcp_routes` field to `ip_network` block in `upcloud_network` resource
- router: `static_routes` block to `upcloud_router` resource
- managed_object_storage: `managed_object_storage` & `managed_object_storage_user_access_key` resources and `managed_object_storage_regions` data source

### Changed
- kubernetes: remove node group maximum value validation. The maximum number of nodes (in the cluster) is determined by the cluster plan and the validation is done on the API side.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
data "upcloud_Managed_object_storage" "this" {}
36 changes: 36 additions & 0 deletions examples/resources/upcloud_managed_object_storage/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Create router for the network
resource "upcloud_router" "this" {
name = "object-storage-example-router"
}

// Create network for the Managed Object Storage
resource "upcloud_network" "this" {
name = "object-storage-example-net"
zone = "fi-hel1"

ip_network {
address = "172.16.2.0/24"
dhcp = true
family = "IPv4"
}

router = upcloud_router.this.id
}

resource "upcloud_managed_object_storage" "this" {
region = "europe-1"
configured_status = "started"

network {
family = "IPv4"
name = "example-private-net"
type = "private"
uuid = upcloud_network.this.id
}

users = ["example"]

labels = {
managed-by = "terraform"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
resource "upcloud_managed_object_storage" "this" {
region = "europe-1"
configured_status = "started"
users = ["example"]
}

resource "upcloud_managed_object_storage_user_access_key" "this" {
name = "accesskey"
enabled = true
username = "example"
service_uuid = upcloud_managed_object_storage.this.id
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/UpCloudLtd/terraform-provider-upcloud
go 1.20

require (
github.com/UpCloudLtd/upcloud-go-api/v6 v6.7.1
github.com/UpCloudLtd/upcloud-go-api/v6 v6.8.1
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
github.com/hashicorp/go-retryablehttp v0.6.8
github.com/hashicorp/go-uuid v1.0.3
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk=
github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow=
github.com/ProtonMail/go-crypto v0.0.0-20230717121422-5aa5874ade95 h1:KLq8BE0KwCL+mmXnjLWEAOYO+2l2AE4YMmqG1ZpZHBs=
github.com/ProtonMail/go-crypto v0.0.0-20230717121422-5aa5874ade95/go.mod h1:EjAoLdwvbIOoOQr3ihjnSoLZRtE8azugULFRteWMNc0=
github.com/UpCloudLtd/upcloud-go-api/v6 v6.7.1 h1:5LWCVMt59kOKlNA6XafC0qIfDv5aUQ1BIGv40YCL2fM=
github.com/UpCloudLtd/upcloud-go-api/v6 v6.7.1/go.mod h1:I8rWmBBl+OhiY3AGzKbrobiE5TsLCLNYkCQxE4eJcTg=
github.com/UpCloudLtd/upcloud-go-api/v6 v6.8.1 h1:w/LgBDHRMSM9wLTsfqbN3ulqZIp0sUEUGH+g9LGLm0Q=
github.com/UpCloudLtd/upcloud-go-api/v6 v6.8.1/go.mod h1:I8rWmBBl+OhiY3AGzKbrobiE5TsLCLNYkCQxE4eJcTg=
github.com/acomagu/bufpipe v1.0.4 h1:e3H4WUzM3npvo5uv95QuJM3cQspFNtFBzvJ2oNjKIDQ=
github.com/agext/levenshtein v1.2.3 h1:YB2fHEn0UJagG8T1rrWknE3ZQzWM06O8AMAatNn7lmo=
github.com/agext/levenshtein v1.2.3/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558=
Expand Down
82 changes: 82 additions & 0 deletions internal/service/managedobjectstorage/data_sources.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package managedobjectstorage

import (
"context"
"time"

"github.com/UpCloudLtd/upcloud-go-api/v6/upcloud"
"github.com/UpCloudLtd/upcloud-go-api/v6/upcloud/request"
"github.com/UpCloudLtd/upcloud-go-api/v6/upcloud/service"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func DataSourceManagedObjectStorageRegions() *schema.Resource {
return &schema.Resource{
Description: `Returns a list of available Managed Object Storage regions.`,
ReadContext: dataSourceHostsRead,
Schema: map[string]*schema.Schema{
"regions": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Description: "Name of the region.",
Computed: true,
},
"primary_zone": {
Type: schema.TypeString,
Description: "Primary zone of the region.",
Computed: true,
},
"zones": {
Type: schema.TypeSet,
Description: "List of zones in the region.",
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
},
},
},
},
}
}

func dataSourceHostsRead(ctx context.Context, d *schema.ResourceData, meta interface{}) (diags diag.Diagnostics) {
svc := meta.(*service.Service)

regions, err := svc.GetManagedObjectStorageRegions(ctx, &request.GetManagedObjectStorageRegionsRequest{})
if err != nil {
return diag.FromErr(err)
}

d.SetId(time.Now().UTC().String())

err = d.Set("regions", buildManagedObjectStorageRegions(regions))
if err != nil {
return diag.FromErr(err)
}

return diags
}

func buildManagedObjectStorageRegions(regions []upcloud.ManagedObjectStorageRegion) []map[string]interface{} {
maps := make([]map[string]interface{}, 0)
for _, region := range regions {
zones := make([]string, 0)
for _, zone := range region.Zones {
zones = append(zones, zone.Name)
}
maps = append(maps, map[string]interface{}{
"name": region.Name,
"primary_zone": region.PrimaryZone,
"zones": zones,
})
}

return maps
}
Loading
Loading