mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-09-06 17:16:44 +00:00
![Shane O'Grady](/assets/img/avatar_default.png)
The description field for a managed-zone is now a required field when using the Cloud API. This commit defaults the field to use the text "Managed by Terraform" to minimize required boilerplate for Terraform users. Ref: https://cloud.google.com/sdk/gcloud/reference/dns/managed-zones/create
84 lines
1.8 KiB
Go
84 lines
1.8 KiB
Go
package google
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/hashicorp/terraform/helper/acctest"
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
"github.com/hashicorp/terraform/terraform"
|
|
"google.golang.org/api/dns/v1"
|
|
)
|
|
|
|
func TestAccDnsManagedZone_basic(t *testing.T) {
|
|
var zone dns.ManagedZone
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
Providers: testAccProviders,
|
|
CheckDestroy: testAccCheckDnsManagedZoneDestroy,
|
|
Steps: []resource.TestStep{
|
|
resource.TestStep{
|
|
Config: testAccDnsManagedZone_basic,
|
|
Check: resource.ComposeTestCheckFunc(
|
|
testAccCheckDnsManagedZoneExists(
|
|
"google_dns_managed_zone.foobar", &zone),
|
|
),
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
func testAccCheckDnsManagedZoneDestroy(s *terraform.State) error {
|
|
config := testAccProvider.Meta().(*Config)
|
|
|
|
for _, rs := range s.RootModule().Resources {
|
|
if rs.Type != "google_dns_zone" {
|
|
continue
|
|
}
|
|
|
|
_, err := config.clientDns.ManagedZones.Get(
|
|
config.Project, rs.Primary.ID).Do()
|
|
if err == nil {
|
|
return fmt.Errorf("DNS ManagedZone still exists")
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func testAccCheckDnsManagedZoneExists(n string, zone *dns.ManagedZone) 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 ID is set")
|
|
}
|
|
|
|
config := testAccProvider.Meta().(*Config)
|
|
|
|
found, err := config.clientDns.ManagedZones.Get(
|
|
config.Project, rs.Primary.ID).Do()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if found.Name != rs.Primary.ID {
|
|
return fmt.Errorf("DNS Zone not found")
|
|
}
|
|
|
|
*zone = *found
|
|
|
|
return nil
|
|
}
|
|
}
|
|
|
|
var testAccDnsManagedZone_basic = fmt.Sprintf(`
|
|
resource "google_dns_managed_zone" "foobar" {
|
|
name = "mzone-test-%s"
|
|
dns_name = "terraform.test."
|
|
}`, acctest.RandString(10))
|