Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

d/dns_managed_zone: Error out if zone is not found #560

Merged
merged 1 commit into from
Oct 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion google/data_source_dns_managed_zone.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,25 @@ func dataSourceDnsManagedZone() *schema.Resource {
}

func dataSourceDnsManagedZoneRead(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)

d.SetId(d.Get("name").(string))

return resourceDnsManagedZoneRead(d, meta)
project, err := getProject(d, config)
if err != nil {
return err
}

zone, err := config.clientDns.ManagedZones.Get(
project, d.Id()).Do()
if err != nil {
return err
}

d.Set("name_servers", zone.NameServers)
d.Set("name", zone.Name)
d.Set("dns_name", zone.DnsName)
d.Set("description", zone.Description)

return nil
}
12 changes: 5 additions & 7 deletions google/data_source_dns_managed_zone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,22 @@ func TestAccDataSourceDnsManagedZone_basic(t *testing.T) {
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccDataSourceDnsManagedZone_basic,
Check: testAccDataSourceDnsManagedZoneCheck("qa", "foo"),
Check: testAccDataSourceDnsManagedZoneCheck("data.google_dns_managed_zone.qa", "google_dns_managed_zone.foo"),
},
},
})
}

func testAccDataSourceDnsManagedZoneCheck(dsName, rsName string) resource.TestCheckFunc {
return func(s *terraform.State) error {
dsFullName := "data.google_dns_managed_zone." + dsName
rsFullName := "google_dns_managed_zone." + rsName
ds, ok := s.RootModule().Resources[dsFullName]
ds, ok := s.RootModule().Resources[rsName]
if !ok {
return fmt.Errorf("cant' find resource called %s in state", dsFullName)
return fmt.Errorf("can't find resource called %s in state", rsName)
}

rs, ok := s.RootModule().Resources[rsFullName]
rs, ok := s.RootModule().Resources[dsName]
if !ok {
return fmt.Errorf("can't find data source called %s in state", rsFullName)
return fmt.Errorf("can't find data source called %s in state", dsName)
}

dsAttr := ds.Primary.Attributes
Expand Down