Skip to content

Commit

Permalink
fix(managedobjectstorage): public network validation
Browse files Browse the repository at this point in the history
  • Loading branch information
villevsv-upcloud committed Oct 24, 2023
1 parent d0d5b2d commit 23f5cf7
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ See updating [Changelog example here](https://keepachangelog.com/en/1.0.0/)

## [Unreleased]

### Fixed
- managed_object_storage: `managed_object_storage` resource public network validation

## [3.0.1] - 2023-10-23

Expand Down
19 changes: 13 additions & 6 deletions internal/service/managedobjectstorage/managed_object_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,14 +302,21 @@ func networksFromResourceData(d *schema.ResourceData) ([]upcloud.ManagedObjectSt
Name: n["name"].(string),
Type: n["type"].(string),
Family: n["family"].(string),
UUID: upcloud.StringPtr(n["uuid"].(string)),
}
if r.Type == "private" && *r.UUID == "" {
return req, fmt.Errorf("private network (#%d) UUID is required", i)
}
if r.Type == "public" && *r.UUID != "" {
return req, fmt.Errorf("setting UUID for a public network (#%d) is not supported", i)
uuid := n["uuid"].(string)

switch r.Type {
case "public":
if uuid != "" {
return req, fmt.Errorf("setting UUID for a public network (#%d) is not supported", i)
}
case "private":
if uuid == "" {
return req, fmt.Errorf("private network (#%d) UUID is required", i)
}
r.UUID = upcloud.StringPtr(uuid)
}

req = append(req, r)
}
}
Expand Down
5 changes: 3 additions & 2 deletions upcloud/resource_upcloud_managed_object_storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ func TestAccUpcloudManagedObjectStorage(t *testing.T) {
Config: testDataS1,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(name, "region", "europe-1"),
resource.TestCheckResourceAttr(name, "configured_status", "stopped"),
resource.TestCheckResourceAttr(name, "configured_status", "started"),
resource.TestCheckResourceAttr(name, "labels.%", "2"),
resource.TestCheckResourceAttr(name, "labels.test", "objsto2-tf"),
resource.TestCheckResourceAttr(name, "network.#", "1"),
resource.TestCheckResourceAttr(name, "network.#", "2"),
),
},
{
Expand All @@ -37,6 +37,7 @@ func TestAccUpcloudManagedObjectStorage(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(name, "configured_status", "started"),
resource.TestCheckResourceAttr(name, "labels.owned-by", "team-devex"),
resource.TestCheckResourceAttr(name, "network.#", "1"),
),
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ resource "upcloud_network" "this" {
resource "upcloud_managed_object_storage" "this" {
region = var.region

configured_status = "stopped"
configured_status = "started"

network {
family = "IPv4"
Expand All @@ -42,6 +42,12 @@ resource "upcloud_managed_object_storage" "this" {
uuid = upcloud_network.this.id
}

network {
family = "IPv4"
name = "${var.prefix}net2"
type = "public"
}

labels = {
test = "objsto2-tf"
owned-by = "team-services"
Expand Down

0 comments on commit 23f5cf7

Please sign in to comment.