diff --git a/digitalocean/dropletautoscale/datasource_droplet_autoscale_test.go b/digitalocean/dropletautoscale/datasource_droplet_autoscale_test.go index a20043630..2e10f1df5 100644 --- a/digitalocean/dropletautoscale/datasource_droplet_autoscale_test.go +++ b/digitalocean/dropletautoscale/datasource_droplet_autoscale_test.go @@ -61,9 +61,9 @@ data "digitalocean_droplet_autoscale" "foo" { resource.TestCheckResourceAttr( "data.digitalocean_droplet_autoscale.foo", "droplet_template.0.size", "c-2"), resource.TestCheckResourceAttr( - "data.digitalocean_droplet_autoscale.foo", "droplet_template.0.region", "s2r1"), - resource.TestCheckResourceAttr( - "data.digitalocean_droplet_autoscale.foo", "droplet_template.0.image", "547864"), + "data.digitalocean_droplet_autoscale.foo", "droplet_template.0.region", "nyc3"), + resource.TestCheckResourceAttrSet( + "data.digitalocean_droplet_autoscale.foo", "droplet_template.0.image"), resource.TestCheckResourceAttr( "data.digitalocean_droplet_autoscale.foo", "droplet_template.0.with_droplet_agent", "true"), resource.TestCheckResourceAttr( @@ -109,9 +109,9 @@ data "digitalocean_droplet_autoscale" "foo" { resource.TestCheckResourceAttr( "data.digitalocean_droplet_autoscale.foo", "droplet_template.0.size", "c-2"), resource.TestCheckResourceAttr( - "data.digitalocean_droplet_autoscale.foo", "droplet_template.0.region", "s2r1"), - resource.TestCheckResourceAttr( - "data.digitalocean_droplet_autoscale.foo", "droplet_template.0.image", "547864"), + "data.digitalocean_droplet_autoscale.foo", "droplet_template.0.region", "nyc3"), + resource.TestCheckResourceAttrSet( + "data.digitalocean_droplet_autoscale.foo", "droplet_template.0.image"), resource.TestCheckResourceAttr( "data.digitalocean_droplet_autoscale.foo", "droplet_template.0.with_droplet_agent", "true"), resource.TestCheckResourceAttr( @@ -187,9 +187,9 @@ data "digitalocean_droplet_autoscale" "foo" { resource.TestCheckResourceAttr( "data.digitalocean_droplet_autoscale.foo", "droplet_template.0.size", "c-2"), resource.TestCheckResourceAttr( - "data.digitalocean_droplet_autoscale.foo", "droplet_template.0.region", "s2r1"), - resource.TestCheckResourceAttr( - "data.digitalocean_droplet_autoscale.foo", "droplet_template.0.image", "547864"), + "data.digitalocean_droplet_autoscale.foo", "droplet_template.0.region", "nyc3"), + resource.TestCheckResourceAttrSet( + "data.digitalocean_droplet_autoscale.foo", "droplet_template.0.image"), resource.TestCheckResourceAttr( "data.digitalocean_droplet_autoscale.foo", "droplet_template.0.with_droplet_agent", "true"), resource.TestCheckResourceAttr( @@ -235,9 +235,9 @@ data "digitalocean_droplet_autoscale" "foo" { resource.TestCheckResourceAttr( "data.digitalocean_droplet_autoscale.foo", "droplet_template.0.size", "c-2"), resource.TestCheckResourceAttr( - "data.digitalocean_droplet_autoscale.foo", "droplet_template.0.region", "s2r1"), - resource.TestCheckResourceAttr( - "data.digitalocean_droplet_autoscale.foo", "droplet_template.0.image", "547864"), + "data.digitalocean_droplet_autoscale.foo", "droplet_template.0.region", "nyc3"), + resource.TestCheckResourceAttrSet( + "data.digitalocean_droplet_autoscale.foo", "droplet_template.0.image"), resource.TestCheckResourceAttr( "data.digitalocean_droplet_autoscale.foo", "droplet_template.0.with_droplet_agent", "true"), resource.TestCheckResourceAttr( diff --git a/digitalocean/dropletautoscale/resource_droplet_autoscale.go b/digitalocean/dropletautoscale/resource_droplet_autoscale.go index 0dfefc02c..077305ec7 100644 --- a/digitalocean/dropletautoscale/resource_droplet_autoscale.go +++ b/digitalocean/dropletautoscale/resource_droplet_autoscale.go @@ -37,6 +37,7 @@ func ResourceDigitalOceanDropletAutoscale() *schema.Resource { }, "config": { Type: schema.TypeList, + MaxItems: 1, Required: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ @@ -81,6 +82,7 @@ func ResourceDigitalOceanDropletAutoscale() *schema.Resource { }, "droplet_template": { Type: schema.TypeList, + MaxItems: 1, Required: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ @@ -268,12 +270,23 @@ func resourceDigitalOceanDropletAutoscaleRead(ctx context.Context, d *schema.Res d.Set("name", pool.Name) d.Set("config", flattenConfig(pool.Config)) - d.Set("droplet_template", flattenTemplate(pool.DropletTemplate)) d.Set("current_utilization", flattenUtilization(pool.CurrentUtilization)) d.Set("status", pool.Status) d.Set("created_at", pool.CreatedAt.UTC().String()) d.Set("updated_at", pool.UpdatedAt.UTC().String()) + // Persist existing image specification (id/slug) if it exists + if t, ok := d.GetOk("droplet_template"); ok { + tList := t.([]interface{}) + if len(tList) > 0 { + tMap := tList[0].(map[string]interface{}) + if tMap["image"] != "" { + pool.DropletTemplate.Image = tMap["image"].(string) + } + } + } + d.Set("droplet_template", flattenTemplate(pool.DropletTemplate)) + return nil } diff --git a/digitalocean/dropletautoscale/resource_droplet_autoscale_test.go b/digitalocean/dropletautoscale/resource_droplet_autoscale_test.go index afc06f4e2..95565edaf 100644 --- a/digitalocean/dropletautoscale/resource_droplet_autoscale_test.go +++ b/digitalocean/dropletautoscale/resource_droplet_autoscale_test.go @@ -53,9 +53,9 @@ func TestAccDigitalOceanDropletAutoscale_Static(t *testing.T) { resource.TestCheckResourceAttr( "digitalocean_droplet_autoscale.foobar", "droplet_template.0.size", "c-2"), resource.TestCheckResourceAttr( - "digitalocean_droplet_autoscale.foobar", "droplet_template.0.region", "s2r1"), - resource.TestCheckResourceAttr( - "digitalocean_droplet_autoscale.foobar", "droplet_template.0.image", "547864"), + "digitalocean_droplet_autoscale.foobar", "droplet_template.0.region", "nyc3"), + resource.TestCheckResourceAttrSet( + "digitalocean_droplet_autoscale.foobar", "droplet_template.0.image"), resource.TestCheckResourceAttr( "digitalocean_droplet_autoscale.foobar", "droplet_template.0.with_droplet_agent", "true"), resource.TestCheckResourceAttr( @@ -101,9 +101,9 @@ func TestAccDigitalOceanDropletAutoscale_Static(t *testing.T) { resource.TestCheckResourceAttr( "digitalocean_droplet_autoscale.foobar", "droplet_template.0.size", "c-2"), resource.TestCheckResourceAttr( - "digitalocean_droplet_autoscale.foobar", "droplet_template.0.region", "s2r1"), - resource.TestCheckResourceAttr( - "digitalocean_droplet_autoscale.foobar", "droplet_template.0.image", "547864"), + "digitalocean_droplet_autoscale.foobar", "droplet_template.0.region", "nyc3"), + resource.TestCheckResourceAttrSet( + "digitalocean_droplet_autoscale.foobar", "droplet_template.0.image"), resource.TestCheckResourceAttr( "digitalocean_droplet_autoscale.foobar", "droplet_template.0.with_droplet_agent", "true"), resource.TestCheckResourceAttr( @@ -165,9 +165,9 @@ func TestAccDigitalOceanDropletAutoscale_Dynamic(t *testing.T) { resource.TestCheckResourceAttr( "digitalocean_droplet_autoscale.foobar", "droplet_template.0.size", "c-2"), resource.TestCheckResourceAttr( - "digitalocean_droplet_autoscale.foobar", "droplet_template.0.region", "s2r1"), - resource.TestCheckResourceAttr( - "digitalocean_droplet_autoscale.foobar", "droplet_template.0.image", "547864"), + "digitalocean_droplet_autoscale.foobar", "droplet_template.0.region", "nyc3"), + resource.TestCheckResourceAttrSet( + "digitalocean_droplet_autoscale.foobar", "droplet_template.0.image"), resource.TestCheckResourceAttr( "digitalocean_droplet_autoscale.foobar", "droplet_template.0.with_droplet_agent", "true"), resource.TestCheckResourceAttr( @@ -213,9 +213,9 @@ func TestAccDigitalOceanDropletAutoscale_Dynamic(t *testing.T) { resource.TestCheckResourceAttr( "digitalocean_droplet_autoscale.foobar", "droplet_template.0.size", "c-2"), resource.TestCheckResourceAttr( - "digitalocean_droplet_autoscale.foobar", "droplet_template.0.region", "s2r1"), - resource.TestCheckResourceAttr( - "digitalocean_droplet_autoscale.foobar", "droplet_template.0.image", "547864"), + "digitalocean_droplet_autoscale.foobar", "droplet_template.0.region", "nyc3"), + resource.TestCheckResourceAttrSet( + "digitalocean_droplet_autoscale.foobar", "droplet_template.0.image"), resource.TestCheckResourceAttr( "digitalocean_droplet_autoscale.foobar", "droplet_template.0.with_droplet_agent", "true"), resource.TestCheckResourceAttr( @@ -319,8 +319,8 @@ resource "digitalocean_droplet_autoscale" "foobar" { droplet_template { size = "c-2" - region = "s2r1" - image = "547864" + region = "nyc3" + image = "ubuntu-24-04-x64" tags = [digitalocean_tag.foo.id, digitalocean_tag.bar.id] ssh_keys = [digitalocean_ssh_key.foo.id, digitalocean_ssh_key.bar.id] with_droplet_agent = true @@ -380,8 +380,8 @@ resource "digitalocean_droplet_autoscale" "foobar" { droplet_template { size = "c-2" - region = "s2r1" - image = "547864" + region = "nyc3" + image = "ubuntu-24-04-x64" tags = [digitalocean_tag.foo.id, digitalocean_tag.bar.id] ssh_keys = [digitalocean_ssh_key.foo.id, digitalocean_ssh_key.bar.id] with_droplet_agent = true