Skip to content

Commit

Permalink
Fixing Case Handling for Volume Resource (#1074)
Browse files Browse the repository at this point in the history
* Apply toLower on region_slug before send it to API

* Acceptance testing for the region_slug process with uppercase characters.
  • Loading branch information
T-jegou committed Nov 14, 2023
1 parent b152e95 commit c643845
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
4 changes: 2 additions & 2 deletions digitalocean/volume/resource_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func resourceDigitalOceanVolumeCreate(ctx context.Context, d *schema.ResourceDat
}

if v, ok := d.GetOk("region"); ok {
opts.Region = v.(string)
opts.Region = strings.ToLower(v.(string))
}
if v, ok := d.GetOk("size"); ok {
opts.SizeGigaBytes = int64(v.(int))
Expand Down Expand Up @@ -168,7 +168,7 @@ func resourceDigitalOceanVolumeUpdate(ctx context.Context, d *schema.ResourceDat
client := meta.(*config.CombinedConfig).GodoClient()

id := d.Id()
region := d.Get("region").(string)
region := strings.ToLower(d.Get("region").(string))

if d.HasChange("size") {
size := d.Get("size").(int)
Expand Down
44 changes: 44 additions & 0 deletions digitalocean/volume/resource_volume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,3 +381,47 @@ resource "digitalocean_volume" "foobar" {
description = "peace makes plenty"
tags = ["foo", "bar", "baz"]
}`

func TestAccDigitalOceanVolume_createWithRegionSlugUpperCase(t *testing.T) {
name := acceptance.RandomTestName("volume")

expectedURNRegEx, _ := regexp.Compile(`do:volume:[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}`)

volume := godo.Volume{
Name: name,
}

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.TestAccPreCheck(t) },
ProviderFactories: acceptance.TestAccProviderFactories,
CheckDestroy: testAccCheckDigitalOceanVolumeDestroy,
Steps: []resource.TestStep{
{
Config: fmt.Sprintf(testAccCheckDigitalOceanVolumeConfig_createWithRegionSlugUpperCase, name),
Check: resource.ComposeTestCheckFunc(
testAccCheckDigitalOceanVolumeExists("digitalocean_volume.foobar", &volume),
resource.TestCheckResourceAttr(
"digitalocean_volume.foobar", "name", name),
resource.TestCheckResourceAttr(
"digitalocean_volume.foobar", "size", "100"),
resource.TestCheckResourceAttr(
"digitalocean_volume.foobar", "region", "nyc3"),
resource.TestCheckResourceAttr(
"digitalocean_volume.foobar", "description", "peace makes plenty"),
resource.TestCheckResourceAttr(
"digitalocean_volume.foobar", "tags.#", "2"),
resource.TestMatchResourceAttr("digitalocean_volume.foobar", "urn", expectedURNRegEx),
),
},
},
})
}

const testAccCheckDigitalOceanVolumeConfig_createWithRegionSlugUpperCase = `
resource "digitalocean_volume" "foobar" {
region = "NYC3"
name = "%s"
size = 100
description = "peace makes plenty"
tags = ["foo", "bar"]
}`

0 comments on commit c643845

Please sign in to comment.