Skip to content

Commit

Permalink
allow importing dns record sets in any project
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
danawillow authored and modular-magician committed Jun 17, 2019
1 parent d54a95d commit c928bb3
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 12 deletions.
21 changes: 14 additions & 7 deletions google-beta/resource_dns_record_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import (

"strings"

"net"

"github.com/hashicorp/terraform/helper/schema"
"google.golang.org/api/dns/v1"
"net"
)

func resourceDnsRecordSet() *schema.Resource {
Expand Down Expand Up @@ -306,14 +307,20 @@ func resourceDnsRecordSetUpdate(d *schema.ResourceData, meta interface{}) error

func resourceDnsRecordSetImportState(d *schema.ResourceData, _ interface{}) ([]*schema.ResourceData, error) {
parts := strings.Split(d.Id(), "/")
if len(parts) != 3 {
return nil, fmt.Errorf("Invalid dns record specifier. Expecting {zone-name}/{record-name}/{record-type}. The record name must include a trailing '.' at the end.")
if len(parts) == 3 {
d.Set("managed_zone", parts[0])
d.Set("name", parts[1])
d.Set("type", parts[2])
} else if len(parts) == 4 {
d.Set("project", parts[0])
d.Set("managed_zone", parts[1])
d.Set("name", parts[2])
d.Set("type", parts[3])
d.SetId(parts[1] + "/" + parts[2] + "/" + parts[3])
} else {
return nil, fmt.Errorf("Invalid dns record specifier. Expecting {zone-name}/{record-name}/{record-type} or {project}/{zone-name}/{record-name}/{record-type}. The record name must include a trailing '.' at the end.")
}

d.Set("managed_zone", parts[0])
d.Set("name", parts[1])
d.Set("type", parts[2])

return []*schema.ResourceData{d}, nil
}

Expand Down
7 changes: 7 additions & 0 deletions google-beta/resource_dns_record_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ func TestAccDnsRecordSet_basic(t *testing.T) {
ImportState: true,
ImportStateVerify: true,
},
// Check both import formats
{
ResourceName: "google_dns_record_set.foobar",
ImportStateId: fmt.Sprintf("%s/%s/test-record.%s.hashicorptest.com./A", getTestProjectFromEnv(), zoneName, zoneName),
ImportState: true,
ImportStateVerify: true,
},
},
})
}
Expand Down
4 changes: 2 additions & 2 deletions website/docs/r/container_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ resource "google_container_node_pool" "primary_preemptible_nodes" {
preemptible = true
machine_type = "n1-standard-1"
metadata = {
metadata {
disable-legacy-endpoints = "true"
}
Expand Down Expand Up @@ -84,7 +84,7 @@ resource "google_container_cluster" "primary" {
"https://www.googleapis.com/auth/monitoring",
]
metadata = {
metadata {
disable-legacy-endpoints = "true"
}
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/container_node_pool.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ resource "google_container_cluster" "primary" {
"https://www.googleapis.com/auth/monitoring",
]
metadata = {
metadata {
disable-legacy-endpoints = "true"
}
Expand Down
5 changes: 3 additions & 2 deletions website/docs/r/dns_record_set.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,11 @@ Only the arguments listed above are exposed as attributes.

## Import

DNS record set can be imported using the `zone name`, `record name` and record `type`, e.g.
DNS record sets can be imported using either of these accepted formats:

```
$ terraform import google_dns_record_set.frontend prod-zone/frontend.prod.mydomain.com./A
$ terraform import google_dns_record_set.frontend {{project}}/{{zone}}/{{name}}/{{type}}
$ terraform import google_dns_record_set.frontend {{zone}}/{{name}}/{{type}}
```

Note: The record name must include the trailing dot at the end.

0 comments on commit c928bb3

Please sign in to comment.