Skip to content

Commit

Permalink
Terraform: Support for (Regional)Disk physicalBlockSizeBytes (#3237)
Browse files Browse the repository at this point in the history
<!-- This change is generated by MagicModules. -->
/cc @drebes
  • Loading branch information
modular-magician authored and rileykarson committed Mar 13, 2019
1 parent 6aabf31 commit 0bb8257
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 0 deletions.
29 changes: 29 additions & 0 deletions google/resource_compute_disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,12 @@ func resourceComputeDisk() *schema.Resource {
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"physical_block_size_bytes": {
Type: schema.TypeInt,
Computed: true,
Optional: true,
ForceNew: true,
},
"size": {
Type: schema.TypeInt,
Computed: true,
Expand Down Expand Up @@ -467,6 +473,12 @@ func resourceComputeDiskCreate(d *schema.ResourceData, meta interface{}) error {
} else if v, ok := d.GetOkExists("size"); !isEmptyValue(reflect.ValueOf(sizeGbProp)) && (ok || !reflect.DeepEqual(v, sizeGbProp)) {
obj["sizeGb"] = sizeGbProp
}
physicalBlockSizeBytesProp, err := expandComputeDiskPhysicalBlockSizeBytes(d.Get("physical_block_size_bytes"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("physical_block_size_bytes"); !isEmptyValue(reflect.ValueOf(physicalBlockSizeBytesProp)) && (ok || !reflect.DeepEqual(v, physicalBlockSizeBytesProp)) {
obj["physicalBlockSizeBytes"] = physicalBlockSizeBytesProp
}
typeProp, err := expandComputeDiskType(d.Get("type"), d, config)
if err != nil {
return err
Expand Down Expand Up @@ -611,6 +623,9 @@ func resourceComputeDiskRead(d *schema.ResourceData, meta interface{}) error {
if err := d.Set("users", flattenComputeDiskUsers(res["users"], d)); err != nil {
return fmt.Errorf("Error reading Disk: %s", err)
}
if err := d.Set("physical_block_size_bytes", flattenComputeDiskPhysicalBlockSizeBytes(res["physicalBlockSizeBytes"], d)); err != nil {
return fmt.Errorf("Error reading Disk: %s", err)
}
if err := d.Set("type", flattenComputeDiskType(res["type"], d)); err != nil {
return fmt.Errorf("Error reading Disk: %s", err)
}
Expand Down Expand Up @@ -893,6 +908,16 @@ func flattenComputeDiskUsers(v interface{}, d *schema.ResourceData) interface{}
return convertAndMapStringArr(v.([]interface{}), ConvertSelfLinkToV1)
}

func flattenComputeDiskPhysicalBlockSizeBytes(v interface{}, d *schema.ResourceData) interface{} {
// Handles the string fixed64 format
if strVal, ok := v.(string); ok {
if intVal, err := strconv.ParseInt(strVal, 10, 64); err == nil {
return intVal
} // let terraform core handle it if we can't convert the string to an int.
}
return v
}

func flattenComputeDiskType(v interface{}, d *schema.ResourceData) interface{} {
if v == nil {
return v
Expand Down Expand Up @@ -1040,6 +1065,10 @@ func expandComputeDiskSize(v interface{}, d TerraformResourceData, config *Confi
return v, nil
}

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

func expandComputeDiskType(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
f, err := parseZonalFieldValue("diskTypes", v.(string), "project", "zone", d, config, true)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions google/resource_compute_disk_generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ resource "google_compute_disk" "default" {
labels = {
environment = "dev"
}
physical_block_size_bytes = 4096
}
`, context)
}
Expand Down
29 changes: 29 additions & 0 deletions google/resource_compute_region_disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ func resourceComputeRegionDisk() *schema.Resource {
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"physical_block_size_bytes": {
Type: schema.TypeInt,
Computed: true,
Optional: true,
ForceNew: true,
},
"region": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -214,6 +220,12 @@ func resourceComputeRegionDiskCreate(d *schema.ResourceData, meta interface{}) e
} else if v, ok := d.GetOkExists("size"); !isEmptyValue(reflect.ValueOf(sizeGbProp)) && (ok || !reflect.DeepEqual(v, sizeGbProp)) {
obj["sizeGb"] = sizeGbProp
}
physicalBlockSizeBytesProp, err := expandComputeRegionDiskPhysicalBlockSizeBytes(d.Get("physical_block_size_bytes"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("physical_block_size_bytes"); !isEmptyValue(reflect.ValueOf(physicalBlockSizeBytesProp)) && (ok || !reflect.DeepEqual(v, physicalBlockSizeBytesProp)) {
obj["physicalBlockSizeBytes"] = physicalBlockSizeBytesProp
}
replicaZonesProp, err := expandComputeRegionDiskReplicaZones(d.Get("replica_zones"), d, config)
if err != nil {
return err
Expand Down Expand Up @@ -352,6 +364,9 @@ func resourceComputeRegionDiskRead(d *schema.ResourceData, meta interface{}) err
if err := d.Set("users", flattenComputeRegionDiskUsers(res["users"], d)); err != nil {
return fmt.Errorf("Error reading RegionDisk: %s", err)
}
if err := d.Set("physical_block_size_bytes", flattenComputeRegionDiskPhysicalBlockSizeBytes(res["physicalBlockSizeBytes"], d)); err != nil {
return fmt.Errorf("Error reading RegionDisk: %s", err)
}
if err := d.Set("replica_zones", flattenComputeRegionDiskReplicaZones(res["replicaZones"], d)); err != nil {
return fmt.Errorf("Error reading RegionDisk: %s", err)
}
Expand Down Expand Up @@ -628,6 +643,16 @@ func flattenComputeRegionDiskUsers(v interface{}, d *schema.ResourceData) interf
return convertAndMapStringArr(v.([]interface{}), ConvertSelfLinkToV1)
}

func flattenComputeRegionDiskPhysicalBlockSizeBytes(v interface{}, d *schema.ResourceData) interface{} {
// Handles the string fixed64 format
if strVal, ok := v.(string); ok {
if intVal, err := strconv.ParseInt(strVal, 10, 64); err == nil {
return intVal
} // let terraform core handle it if we can't convert the string to an int.
}
return v
}

func flattenComputeRegionDiskReplicaZones(v interface{}, d *schema.ResourceData) interface{} {
if v == nil {
return v
Expand Down Expand Up @@ -733,6 +758,10 @@ func expandComputeRegionDiskSize(v interface{}, d TerraformResourceData, config
return v, nil
}

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

func expandComputeRegionDiskReplicaZones(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
l := v.([]interface{})
req := make([]interface{}, 0, len(l))
Expand Down
1 change: 1 addition & 0 deletions google/resource_compute_region_disk_generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ resource "google_compute_region_disk" "regiondisk" {
snapshot = "${google_compute_snapshot.snapdisk.self_link}"
type = "pd-ssd"
region = "us-central1"
physical_block_size_bytes = 4096
replica_zones = ["us-central1-a", "us-central1-f"]
}
Expand Down
9 changes: 9 additions & 0 deletions website/docs/r/compute_disk.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ resource "google_compute_disk" "default" {
labels = {
environment = "dev"
}
physical_block_size_bytes = 4096
}
```

Expand Down Expand Up @@ -107,6 +108,14 @@ The following arguments are supported:
the value of sizeGb must not be less than the size of the sourceImage
or the size of the snapshot.

* `physical_block_size_bytes` -
(Optional)
Physical block size of the persistent disk, in bytes. If not present
in a request, a default value is used. Currently supported sizes
are 4096 and 16384, other sizes may be added in the future.
If an unsupported value is requested, the error message will list
the supported values for the caller's project.

* `type` -
(Optional)
URL of the disk type resource describing which disk type to use to
Expand Down
9 changes: 9 additions & 0 deletions website/docs/r/compute_region_disk.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ resource "google_compute_region_disk" "regiondisk" {
snapshot = "${google_compute_snapshot.snapdisk.self_link}"
type = "pd-ssd"
region = "us-central1"
physical_block_size_bytes = 4096
replica_zones = ["us-central1-a", "us-central1-f"]
}
Expand Down Expand Up @@ -124,6 +125,14 @@ The following arguments are supported:
the value of sizeGb must not be less than the size of the sourceImage
or the size of the snapshot.

* `physical_block_size_bytes` -
(Optional)
Physical block size of the persistent disk, in bytes. If not present
in a request, a default value is used. Currently supported sizes
are 4096 and 16384, other sizes may be added in the future.
If an unsupported value is requested, the error message will list
the supported values for the caller's project.

* `type` -
(Optional)
URL of the disk type resource describing which disk type to use to
Expand Down

0 comments on commit 0bb8257

Please sign in to comment.