使用Terraform创建Google Compute Disk时物理块大小不支持错误的修复方法
The Problem
You're trying to create a Google Compute Disk with Terraform using this configuration:
resource "google_compute_disk" "default2" { name = "test-disk" type = "pd-balanced" zone = "us-central1-a" image = "centos-7-v20210609" physical_block_size_bytes = 20480 }
When running terraform apply, you hit this error:
requested physical block size 2048 is not supported by this disk
The Root Cause
Google Cloud enforces strict limits on allowed physical block sizes based on your disk type. For pd-balanced disks, the only supported physical block size is 4096 bytes (4KB). The 20480-byte (20KB) value you specified doesn't fall into the allowed range for this disk type.
The Fix
You have two simple, valid options to resolve this:
Option 1: Use the supported block size for pd-balanced
Update the physical_block_size_bytes value to 4096, the only valid size for pd-balanced disks:
resource "google_compute_disk" "default2" { name = "test-disk" type = "pd-balanced" zone = "us-central1-a" image = "centos-7-v20210609" physical_block_size_bytes = 4096 # Valid for pd-balanced disks }
Option 2: Remove the block size parameter entirely
If you don’t have a specific need for a custom block size, just delete the physical_block_size_bytes line. GCP will automatically use the default supported size (4096 bytes) for pd-balanced disks:
resource "google_compute_disk" "default2" { name = "test-disk" type = "pd-balanced" zone = "us-central1-a" image = "centos-7-v20210609" # Default 4KB block size will be applied automatically }
Quick Reference for All GCP Disk Types
To avoid similar issues later, here’s the supported physical block sizes for each disk type:
- pd-standard / pd-balanced: Only 4096 bytes (4KB)
- pd-ssd: 4096 bytes (4KB) or 1048576 bytes (1MB)
- Local SSD: 512 bytes
内容的提问来源于stack exchange,提问作者Rohan jangid

