-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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) | ||
} |
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) | ||
} | ||
|
||
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)) |
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). | ||
``` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should probably be ```tf or ```hcl There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. GCE isn't relevant here, is it? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not for a data source There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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'. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Defaults aren't really relevant for data sources There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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