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

[Compute_Disk] - Add beta multi-writer support #2822

Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions .changelog/3911.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
compute: added field `multiwriter` to resource `disk` (beta)
```
23 changes: 23 additions & 0 deletions google-beta/resource_compute_disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,12 @@ These images can be referred by family name here.`,
Description: `Labels to apply to this disk. A list of key->value pairs.`,
Elem: &schema.Schema{Type: schema.TypeString},
},
"multi_writer": {
Type: schema.TypeBool,
Optional: true,
ForceNew: true,
Description: `Indicates whether or not the disk can be read/write attached to more than one instance.`,
},
"physical_block_size_bytes": {
Type: schema.TypeInt,
Computed: true,
Expand Down Expand Up @@ -635,6 +641,12 @@ func resourceComputeDiskCreate(d *schema.ResourceData, meta interface{}) error {
} else if v, ok := d.GetOkExists("resource_policies"); !isEmptyValue(reflect.ValueOf(resourcePoliciesProp)) && (ok || !reflect.DeepEqual(v, resourcePoliciesProp)) {
obj["resourcePolicies"] = resourcePoliciesProp
}
multiWriterProp, err := expandComputeDiskMultiWriter(d.Get("multi_writer"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("multi_writer"); !isEmptyValue(reflect.ValueOf(multiWriterProp)) && (ok || !reflect.DeepEqual(v, multiWriterProp)) {
obj["multiWriter"] = multiWriterProp
}
zoneProp, err := expandComputeDiskZone(d.Get("zone"), d, config)
if err != nil {
return err
Expand Down Expand Up @@ -805,6 +817,9 @@ func resourceComputeDiskRead(d *schema.ResourceData, meta interface{}) error {
if err := d.Set("resource_policies", flattenComputeDiskResourcePolicies(res["resourcePolicies"], d, config)); err != nil {
return fmt.Errorf("Error reading Disk: %s", err)
}
if err := d.Set("multi_writer", flattenComputeDiskMultiWriter(res["multiWriter"], d, config)); err != nil {
return fmt.Errorf("Error reading Disk: %s", err)
}
if err := d.Set("zone", flattenComputeDiskZone(res["zone"], d, config)); err != nil {
return fmt.Errorf("Error reading Disk: %s", err)
}
Expand Down Expand Up @@ -1141,6 +1156,10 @@ func flattenComputeDiskResourcePolicies(v interface{}, d *schema.ResourceData, c
return convertAndMapStringArr(v.([]interface{}), ConvertSelfLinkToV1)
}

func flattenComputeDiskMultiWriter(v interface{}, d *schema.ResourceData, config *Config) interface{} {
return v
}

func flattenComputeDiskZone(v interface{}, d *schema.ResourceData, config *Config) interface{} {
if v == nil {
return v
Expand Down Expand Up @@ -1331,6 +1350,10 @@ func expandComputeDiskResourcePolicies(v interface{}, d TerraformResourceData, c
return req, nil
}

func expandComputeDiskMultiWriter(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}

func expandComputeDiskZone(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
f, err := parseGlobalFieldValue("zones", v.(string), "project", d, config, true)
if err != nil {
Expand Down
64 changes: 64 additions & 0 deletions google-beta/resource_compute_disk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,27 @@ func TestAccComputeDisk_interface(t *testing.T) {
})
}

func TestAccComputeDisk_multiWriter(t *testing.T) {
t.Parallel()
instanceName := fmt.Sprintf("tf-test-%s", randString(t, 10))
diskName := fmt.Sprintf("tf-testd-%s", randString(t, 10))

vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccComputeDisk_multiWriter(instanceName, diskName, true),
},
{
ResourceName: "google_compute_disk.foobar",
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testAccCheckComputeDiskExists(t *testing.T, n, p string, disk *compute.Disk) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
Expand Down Expand Up @@ -808,3 +829,46 @@ resource "google_compute_disk" "foobar" {
}
`, diskName)
}

func testAccComputeDisk_multiWriter(instance string, diskName string, enableMultiwriter bool) string {
return fmt.Sprintf(`
data "google_compute_image" "my_image" {
family = "debian-9"
project = "debian-cloud"
}

resource "google_compute_disk" "foobar" {
name = "%s"
size = 10
type = "pd-ssd"
zone = "us-central1-a"
multi_writer = %t
}

resource "google_compute_instance" "foobar" {
name = "%s"
machine_type = "n2-standard-2"
zone = "us-central1-a"
can_ip_forward = false
tags = ["foo", "bar"]

boot_disk {
initialize_params {
image = data.google_compute_image.my_image.self_link
}
}

attached_disk {
source = google_compute_disk.foobar.name
}

network_interface {
network = "default"
}

metadata = {
foo = "bar"
}
}
`, diskName, enableMultiwriter, instance)
}
4 changes: 4 additions & 0 deletions website/docs/r/compute_disk.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ The following arguments are supported:
[`google_compute_disk_resource_policy_attachment`](https://www.terraform.io/docs/providers/google/r/compute_disk_resource_policy_attachment.html)
to allow for updating the resource policy attached to the disk.

* `multi_writer` -
(Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html))
Indicates whether or not the disk can be read/write attached to more than one instance.

* `zone` -
(Optional)
A reference to the zone where the disk resides.
Expand Down