terraform-provider-greenhost/digitalocean/datasource_digitalocean_con...

72 lines
1.8 KiB
Go
Raw Normal View History

adding Container Registry support (#383) * adding Container Registry support * adding endpoint and docker_credentials as attributes to datasource * updating documentation on how to use the endpoint attribute * adding a server_url attribute * adding tests, exporting attributes from resources, fixing go.sum, updating docs * adding update function and splitting out generateDockerCreds into a separate function * updating acceptance tests and docs * Update website/docs/d/container_registry.html.md Co-Authored-By: Andrew Starr-Bochicchio <andrewsomething@users.noreply.github.com> * Update website/docs/d/container_registry.html.md Co-Authored-By: Andrew Starr-Bochicchio <andrewsomething@users.noreply.github.com> * Update website/docs/d/container_registry.html.md Co-Authored-By: Andrew Starr-Bochicchio <andrewsomething@users.noreply.github.com> * adding kubernetes example * adding note about container registry beta * removing TODOs * partial push * almost done, odd error in import test and waiting for final default value * setting default for expiry_seconds and creating custom importer * creating new resource for docker credentials * fixed tiny bug in testing * Update website/docs/r/container_registry_docker_credentials.html.markdown Co-authored-by: Andrew Starr-Bochicchio <andrewsomething@users.noreply.github.com> * Update website/docs/r/container_registry_docker_credentials.html.markdown Co-authored-by: Andrew Starr-Bochicchio <andrewsomething@users.noreply.github.com> * Final tweaks as requested Co-authored-by: Andrew Starr-Bochicchio <andrewsomething@users.noreply.github.com>
2020-06-03 21:30:15 +00:00
package digitalocean
import (
"context"
"fmt"
"testing"
"github.com/digitalocean/godo"
"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
)
func TestAccDataSourceDigitalOceanContainerRegistry_Basic(t *testing.T) {
var reg godo.Registry
regName := fmt.Sprintf("foo-%s", acctest.RandString(10))
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: fmt.Sprintf(testAccCheckDataSourceDigitalOceanContainerRegistryConfig_basic, regName),
Check: resource.ComposeTestCheckFunc(
testAccCheckDataSourceDigitalOceanContainerRegistryExists("data.digitalocean_container_registry.foobar", &reg),
resource.TestCheckResourceAttr(
"data.digitalocean_container_registry.foobar", "name", regName),
),
},
},
})
}
func testAccCheckDataSourceDigitalOceanContainerRegistryExists(n string, reg *godo.Registry) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
if !ok {
return fmt.Errorf("Not found: %s", n)
}
if rs.Primary.ID == "" {
return fmt.Errorf("No registry ID is set")
}
client := testAccProvider.Meta().(*CombinedConfig).godoClient()
foundReg, _, err := client.Registry.Get(context.Background())
if err != nil {
return err
}
if foundReg.Name != rs.Primary.ID {
return fmt.Errorf("Registry not found")
}
*reg = *foundReg
return nil
}
}
const testAccCheckDataSourceDigitalOceanContainerRegistryConfig_basic = `
resource "digitalocean_container_registry" "foo" {
name = "%s"
}
data "digitalocean_container_registry" "foobar" {
name = "${digitalocean_container_registry.foo.name}"
}`