Simplify Spaces bucket importing and test error case when importing non-existent resource.
This commit is contained in:
parent
6b3a641ed9
commit
f03e5252c3
|
@ -2,6 +2,7 @@ package digitalocean
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"regexp"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform/helper/acctest"
|
"github.com/hashicorp/terraform/helper/acctest"
|
||||||
|
@ -25,9 +26,17 @@ func TestAccDigitalOceanBucket_importBasic(t *testing.T) {
|
||||||
ResourceName: resourceName,
|
ResourceName: resourceName,
|
||||||
ImportState: true,
|
ImportState: true,
|
||||||
ImportStateVerify: true,
|
ImportStateVerify: true,
|
||||||
ImportStateIdPrefix: fmt.Sprintf("%s,", "nyc3"),
|
ImportStateIdPrefix: fmt.Sprintf("%s,", "sfo2"),
|
||||||
ImportStateVerifyIgnore: []string{"acl", "force_destroy"},
|
ImportStateVerifyIgnore: []string{"acl", "force_destroy"},
|
||||||
},
|
},
|
||||||
|
// Test importing non-existent resource provides expected error.
|
||||||
|
{
|
||||||
|
ResourceName: resourceName,
|
||||||
|
ImportState: true,
|
||||||
|
ImportStateVerify: false,
|
||||||
|
ImportStateId: "sfo2,nonexistent-bucket",
|
||||||
|
ExpectError: regexp.MustCompile(`(Please verify the ID is correct|Cannot import non-existent remote object)`),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -295,15 +295,7 @@ func resourceDigitalOceanBucketImport(d *schema.ResourceData, meta interface{})
|
||||||
d.Set("region", s[0])
|
d.Set("region", s[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
err := resourceDigitalOceanBucketRead(d, meta)
|
return []*schema.ResourceData{d}, nil
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("unable to import bucket: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
results := make([]*schema.ResourceData, 0)
|
|
||||||
results = append(results, d)
|
|
||||||
|
|
||||||
return results, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func bucketDomainName(bucket string, region string) string {
|
func bucketDomainName(bucket string, region string) string {
|
||||||
|
|
|
@ -276,7 +276,8 @@ resource "digitalocean_spaces_bucket" "bucket" {
|
||||||
func testAccDigitalOceanBucketConfigImport(randInt int) string {
|
func testAccDigitalOceanBucketConfigImport(randInt int) string {
|
||||||
return fmt.Sprintf(`
|
return fmt.Sprintf(`
|
||||||
resource "digitalocean_spaces_bucket" "bucket" {
|
resource "digitalocean_spaces_bucket" "bucket" {
|
||||||
name = "tf-test-bucket-%d"
|
name = "tf-test-bucket-%d"
|
||||||
|
region = "sfo2"
|
||||||
}
|
}
|
||||||
`, randInt)
|
`, randInt)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue