mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-10-01 16:21:06 +00:00
Add DNS PTR record to Compute Instance (#1349)
This commit is contained in:
parent
a90d920e6e
commit
d3bbfbd22b
@ -51,6 +51,9 @@ func flattenAccessConfigs(accessConfigs []*computeBeta.AccessConfig) ([]map[stri
|
||||
"nat_ip": ac.NatIP,
|
||||
"assigned_nat_ip": ac.NatIP,
|
||||
}
|
||||
if ac.SetPublicPtr {
|
||||
flattened[i]["public_ptr_domain_name"] = ac.PublicPtrDomainName
|
||||
}
|
||||
if natIP == "" {
|
||||
natIP = ac.NatIP
|
||||
}
|
||||
@ -103,6 +106,10 @@ func expandAccessConfigs(configs []interface{}) []*computeBeta.AccessConfig {
|
||||
Type: "ONE_TO_ONE_NAT",
|
||||
NatIP: data["nat_ip"].(string),
|
||||
}
|
||||
if ptr, ok := data["public_ptr_domain_name"]; ok {
|
||||
acs[i].SetPublicPtr = true
|
||||
acs[i].PublicPtrDomainName = ptr.(string)
|
||||
}
|
||||
}
|
||||
return acs
|
||||
}
|
||||
|
@ -365,6 +365,11 @@ func resourceComputeInstance() *schema.Resource {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
|
||||
"public_ptr_domain_name": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -1120,6 +1125,10 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err
|
||||
Type: "ONE_TO_ONE_NAT",
|
||||
NatIP: d.Get(acPrefix + ".nat_ip").(string),
|
||||
}
|
||||
if ptr, ok := d.GetOk(acPrefix + ".public_ptr_domain_name"); ok {
|
||||
ac.SetPublicPtr = true
|
||||
ac.PublicPtrDomainName = ptr.(string)
|
||||
}
|
||||
op, err := config.clientCompute.Instances.AddAccessConfig(
|
||||
project, zone, d.Id(), networkName, ac).Do()
|
||||
if err != nil {
|
||||
|
@ -186,6 +186,41 @@ func TestAccComputeInstance_IP(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestAccComputeInstance_PTRRecord(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var instance compute.Instance
|
||||
var ptrName = fmt.Sprintf("instance-test-%s", acctest.RandString(10))
|
||||
var ipName = fmt.Sprintf("instance-test-%s", acctest.RandString(10))
|
||||
var instanceName = fmt.Sprintf("instance-test-%s", acctest.RandString(10))
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testAccCheckComputeInstanceDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testAccComputeInstance_PTRRecord(ptrName, instanceName),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckComputeInstanceExists(
|
||||
"google_compute_instance.foobar", &instance),
|
||||
testAccCheckComputeInstanceAccessConfigHasPTR(&instance),
|
||||
),
|
||||
},
|
||||
computeInstanceImportStep("us-central1-a", instanceName, []string{"metadata.baz", "metadata.foo"}),
|
||||
resource.TestStep{
|
||||
Config: testAccComputeInstance_ip(ipName, instanceName),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckComputeInstanceExists(
|
||||
"google_compute_instance.foobar", &instance),
|
||||
testAccCheckComputeInstanceAccessConfigHasIP(&instance),
|
||||
),
|
||||
},
|
||||
computeInstanceImportStep("us-central1-a", instanceName, []string{"metadata.baz", "metadata.foo"}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestAccComputeInstance_GenerateIP(t *testing.T) {
|
||||
var instance compute.Instance
|
||||
var instanceName = fmt.Sprintf("instance-test-%s", acctest.RandString(10))
|
||||
@ -1148,6 +1183,20 @@ func testAccCheckComputeInstanceAccessConfigHasIP(instance *compute.Instance) re
|
||||
}
|
||||
}
|
||||
|
||||
func testAccCheckComputeInstanceAccessConfigHasPTR(instance *compute.Instance) resource.TestCheckFunc {
|
||||
return func(s *terraform.State) error {
|
||||
for _, i := range instance.NetworkInterfaces {
|
||||
for _, c := range i.AccessConfigs {
|
||||
if c.PublicPtrDomainName == "" {
|
||||
return fmt.Errorf("no PTR Record")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func testAccCheckComputeInstanceDisk(instance *compute.Instance, source string, delete bool, boot bool) resource.TestCheckFunc {
|
||||
return func(s *terraform.State) error {
|
||||
if instance.Disks == nil {
|
||||
@ -1750,6 +1799,34 @@ resource "google_compute_instance" "foobar" {
|
||||
`, ip, instance)
|
||||
}
|
||||
|
||||
func testAccComputeInstance_PTRRecord(record, instance string) string {
|
||||
return fmt.Sprintf(`
|
||||
resource "google_compute_instance" "foobar" {
|
||||
name = "%s"
|
||||
machine_type = "n1-standard-1"
|
||||
zone = "us-central1-a"
|
||||
tags = ["foo", "bar"]
|
||||
|
||||
boot_disk {
|
||||
initialize_params{
|
||||
image = "debian-8-jessie-v20160803"
|
||||
}
|
||||
}
|
||||
|
||||
network_interface {
|
||||
network = "default"
|
||||
access_config {
|
||||
public_ptr_domain_name = "test-record.%s.hashicorptest.com."
|
||||
}
|
||||
}
|
||||
|
||||
metadata {
|
||||
foo = "bar"
|
||||
}
|
||||
}
|
||||
`, instance, record)
|
||||
}
|
||||
|
||||
func testAccComputeInstance_generateIp(instance string) string {
|
||||
return fmt.Sprintf(`
|
||||
resource "google_compute_instance" "foobar" {
|
||||
|
1282
vendor/google.golang.org/api/compute/v0.beta/compute-api.json
generated
vendored
1282
vendor/google.golang.org/api/compute/v0.beta/compute-api.json
generated
vendored
File diff suppressed because it is too large
Load Diff
6331
vendor/google.golang.org/api/compute/v0.beta/compute-gen.go
generated
vendored
6331
vendor/google.golang.org/api/compute/v0.beta/compute-gen.go
generated
vendored
File diff suppressed because it is too large
Load Diff
58344
vendor/google.golang.org/api/compute/v1/compute-api.json
generated
vendored
58344
vendor/google.golang.org/api/compute/v1/compute-api.json
generated
vendored
File diff suppressed because it is too large
Load Diff
4366
vendor/google.golang.org/api/compute/v1/compute-gen.go
generated
vendored
4366
vendor/google.golang.org/api/compute/v1/compute-gen.go
generated
vendored
File diff suppressed because it is too large
Load Diff
12
vendor/vendor.json
vendored
12
vendor/vendor.json
vendored
@ -1274,16 +1274,16 @@
|
||||
"revisionTime": "2017-09-12T00:03:44Z"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "kasq8gGLFuCh5Li1MgvYSOr1C20=",
|
||||
"checksumSHA1": "gMu2KulO+2hJ4Bd00LqoQbIlVQU=",
|
||||
"path": "google.golang.org/api/compute/v0.beta",
|
||||
"revision": "8dd9492f46214d3ecd264e970de1cf530c51c12e",
|
||||
"revisionTime": "2018-03-07T00:03:37Z"
|
||||
"revision": "e4126357c891acdef6dcd7805daa4c6533be6544",
|
||||
"revisionTime": "2018-03-26T00:03:39Z"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "mAsa+xKdihWif0c4tJ6hOwpDuhk=",
|
||||
"checksumSHA1": "aAUKwislYt7nWiu0O9UTKZz9Xnc=",
|
||||
"path": "google.golang.org/api/compute/v1",
|
||||
"revision": "7219ace1c3535de1864b2706ea9397ad2d269f07",
|
||||
"revisionTime": "2017-12-14T00:03:52Z"
|
||||
"revision": "e4126357c891acdef6dcd7805daa4c6533be6544",
|
||||
"revisionTime": "2018-03-26T00:03:39Z"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "acuDPZa9rxUvFhdijdVfG4jy+rw=",
|
||||
|
@ -220,6 +220,11 @@ The `access_config` block supports:
|
||||
* `nat_ip` - (Optional) The IP address that will be 1:1 mapped to the instance's
|
||||
network ip. If not given, one will be generated.
|
||||
|
||||
* `public_ptr_domain_name` - (Optional) The DNS domain name for the public PTR record.
|
||||
To set this field on an instance, you must be verified as the owner of the domain.
|
||||
See [the docs](https://cloud.google.com/compute/docs/instances/create-ptr-record) for how
|
||||
to become verified as a domain owner.
|
||||
|
||||
The `alias_ip_range` block supports:
|
||||
|
||||
* `ip_cidr_range` - The IP CIDR range represented by this alias IP range. This IP CIDR range
|
||||
|
Loading…
Reference in New Issue
Block a user