Skip to content

Commit

Permalink
enable google_dns_policy to accept network id (#3636) (#6624)
Browse files Browse the repository at this point in the history
* enable google_dns_policy to accept network id

* two  ids in dns_managed_zone example

Co-authored-by: Edward Sun <[email protected]>
Signed-off-by: Modular Magician <[email protected]>

Co-authored-by: Edward Sun <[email protected]>
  • Loading branch information
modular-magician and Edward Sun authored Jun 17, 2020
1 parent 673a2a9 commit 06db597
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 13 deletions.
3 changes: 3 additions & 0 deletions .changelog/3636.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
enable google_dns_policy to accept network id #6577
```
21 changes: 16 additions & 5 deletions google/resource_dns_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"fmt"
"log"
"reflect"
"strings"
"time"

"github.com/hashicorp/terraform-plugin-sdk/helper/hashcode"
Expand Down Expand Up @@ -139,10 +140,11 @@ func dnsPolicyNetworksSchema() *schema.Resource {
return &schema.Resource{
Schema: map[string]*schema.Schema{
"network_url": {
Type: schema.TypeString,
Required: true,
Description: `The fully qualified URL of the VPC network to bind to.
This should be formatted like
Type: schema.TypeString,
Required: true,
DiffSuppressFunc: compareSelfLinkOrResourceName,
Description: `The id or fully qualified URL of the VPC network to forward queries to.
This should be formatted like 'projects/{project}/global/networks/{network}' or
'https://www.googleapis.com/compute/v1/projects/{project}/global/networks/{network}'`,
},
},
Expand Down Expand Up @@ -560,5 +562,14 @@ func expandDNSPolicyNetworks(v interface{}, d TerraformResourceData, config *Con
}

func expandDNSPolicyNetworksNetworkUrl(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
if v == nil || v.(string) == "" {
return "", nil
} else if strings.HasPrefix(v.(string), "https://") {
return v, nil
}
url, err := replaceVars(d, config, "{{ComputeBasePath}}"+v.(string))
if err != nil {
return "", err
}
return ConvertSelfLinkToV1(url), nil
}
4 changes: 2 additions & 2 deletions google/resource_dns_policy_generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ resource "google_dns_policy" "example-policy" {
}
networks {
network_url = google_compute_network.network-1.self_link
network_url = google_compute_network.network-1.id
}
networks {
network_url = google_compute_network.network-2.self_link
network_url = google_compute_network.network-2.id
}
}
Expand Down
4 changes: 2 additions & 2 deletions website/docs/r/dns_managed_zone.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@ resource "google_dns_managed_zone" "private-zone" {
private_visibility_config {
networks {
network_url = google_compute_network.network-1.self_link
network_url = google_compute_network.network-1.id
}
networks {
network_url = google_compute_network.network-2.self_link
network_url = google_compute_network.network-2.id
}
}
Expand Down
8 changes: 4 additions & 4 deletions website/docs/r/dns_policy.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ resource "google_dns_policy" "example-policy" {
}
networks {
network_url = google_compute_network.network-1.self_link
network_url = google_compute_network.network-1.id
}
networks {
network_url = google_compute_network.network-2.self_link
network_url = google_compute_network.network-2.id
}
}
Expand Down Expand Up @@ -138,8 +138,8 @@ The `networks` block supports:

* `network_url` -
(Required)
The fully qualified URL of the VPC network to bind to.
This should be formatted like
The id or fully qualified URL of the VPC network to forward queries to.
This should be formatted like `projects/{project}/global/networks/{network}` or
`https://www.googleapis.com/compute/v1/projects/{project}/global/networks/{network}`

## Attributes Reference
Expand Down

0 comments on commit 06db597

Please sign in to comment.