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

Add new data source: google_dns_managed_zone #268

Merged
merged 3 commits into from
Jul 31, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
47 changes: 47 additions & 0 deletions google/data_source_dns_managed_zone.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package google

import "github.com/hashicorp/terraform/helper/schema"

func dataSourceDnsManagedZone() *schema.Resource {
return &schema.Resource{
Read: dataSourceDnsManagedZoneRead,

Schema: map[string]*schema.Schema{
"dns_name": &schema.Schema{
Type: schema.TypeString,
Computed: true,
},

"name": &schema.Schema{
Type: schema.TypeString,
Required: true,
},

"description": &schema.Schema{
Type: schema.TypeString,
Computed: true,
},

"name_servers": &schema.Schema{
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},

// Google Cloud DNS ManagedZone resources do not have a SelfLink attribute.

"project": &schema.Schema{
Type: schema.TypeString,
Optional: true,
},
},
}
}

func dataSourceDnsManagedZoneRead(d *schema.ResourceData, meta interface{}) error {
d.SetId(d.Get("name").(string))

return resourceDnsManagedZoneRead(d, meta)
}
70 changes: 70 additions & 0 deletions google/data_source_dns_managed_zone_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package google

import (
"fmt"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
"testing"
)

func TestAccDataSourceDnsManagedZone_basic(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckDnsManagedZoneDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccDataSourceDnsManagedZone_basic,
Check: testAccDataSourceDnsManagedZoneCheck("qa", "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]
if !ok {
return fmt.Errorf("root module has no resource called %s", dsFullName)
}

rs, ok := s.RootModule().Resources[rsFullName]
if !ok {
return fmt.Errorf("can't find %s in state", rsFullName)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason to have different wording for the two error messages?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than that I copied and pasted this snippet from another test. No ;)

Fixed

}

dsAttr := ds.Primary.Attributes
rsAttr := rs.Primary.Attributes

attrsToTest := []string{
"id",
"name",
"description",
"dns_name",
"name_servers",
}

for _, attrToTest := range attrsToTest {
if dsAttr[attrToTest] != rsAttr[attrToTest] {
return fmt.Errorf("%s is %s; want %s", attrToTest, dsAttr[attrToTest], rsAttr[attrToTest])
}
}

return nil
}
}

var testAccDataSourceDnsManagedZone_basic = fmt.Sprintf(`
resource "google_dns_managed_zone" "foo" {
name = "qa-zone-%s"
dns_name = "qa.test.com."
description = "QA DNS zone"
}

data "google_dns_managed_zone" "qa" {
name = "${google_dns_managed_zone.foo.name}"
}
`, acctest.RandString(10))
1 change: 1 addition & 0 deletions google/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func Provider() terraform.ResourceProvider {
},

DataSourcesMap: map[string]*schema.Resource{
"google_dns_managed_zone": dataSourceDnsManagedZone(),
"google_compute_network": dataSourceGoogleComputeNetwork(),
"google_compute_subnetwork": dataSourceGoogleComputeSubnetwork(),
"google_compute_zones": dataSourceGoogleComputeZones(),
Expand Down
50 changes: 50 additions & 0 deletions website/docs/d/dns_managed_zone.html.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
layout: "google"
page_title: "Google: google_dns_managed_zone"
sidebar_current: "docs-google-datasource-dns-managed-zone"
description: |-
Provides access to the attributes of a zone within Google Cloud DNS
---

# google\_dns\_managed\_zone

Provides access to a zone's attributes within Google Cloud DNS.
For more information see
[the official documentation](https://cloud.google.com/dns/zones/)
and
[API](https://cloud.google.com/dns/api/v1/managedZones).
```
Copy link
Contributor

@danawillow danawillow Jul 29, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be ```tf or ```hcl

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

data "google_dns_managed_zone" "env_dns_zone" {
name = "qa-zone"
}

resource "google_dns_record_set" "dns" {
name = "my-address.${data.google_dns_managed_zone.env_dns_zone.dns_name}"
type = "TXT"
ttl = 300

managed_zone = "${data.google_dns_managed_zone.env_dns_zone.name}"

rrdatas = ["test"]
}
```

## Argument Reference

* `name` - (Required) A unique name for the resource, required by GCE.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GCE isn't relevant here, is it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oupps. I meant to clean up these descriptions before opening the PR... Forgot about it ;)

Changing this forces a new resource to be created.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not for a data source

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed


* `project` (optional) - ID of the project to list available cluster versions for. Should match the project the cluster will be deployed to.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like it needs to be updated from what this page was copied from

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Defaults to the project that the provider is authenticated with.

## Attributes Reference

The following attributes are exported:

* `dns_name` - The DNS name of this zone, e.g. "terraform.io".

* `description` - A textual description field. Defaults to 'Managed by Terraform'.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Defaults aren't really relevant for data sources

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed


* `name_servers` - The list of nameservers that will be authoritative for this
domain. Use NS records to redirect from your DNS provider to these names,
thus making Google Cloud DNS authoritative for this zone.
3 changes: 2 additions & 1 deletion website/docs/r/dns_managed_zone.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ description: |-

# google\_dns\_managed_zone

Manages a zone within Google Cloud DNS.
Manages a zone within Google Cloud DNS. For more information see [the official documentation](https://cloud.google.com/dns/zones/) and
[API](https://cloud.google.com/dns/api/v1/managedZones).

## Example Usage

Expand Down
3 changes: 3 additions & 0 deletions website/google.erb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
<li<%= sidebar_current("docs-google-datasource-container-versions") %>>
<a href="/docs/providers/google/d/google_container_engine_versions.html">google_container_engine_versions</a>
</li>
<li<%= sidebar_current("docs-google-datasource-dns-managed-zone") %>>
<a href="/docs/providers/google/d/dns_managed_zone.html">dns_managed_zone</a>
</li>
<li<%= sidebar_current("docs-google-datasource-iam-policy") %>>
<a href="/docs/providers/google/d/google_iam_policy.html">google_iam_policy</a>
</li>
Expand Down