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

Add error if boot disk specified on non-first disk in instance template #5491

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
Empty file removed .changelog/2877.txt
Empty file.
3 changes: 3 additions & 0 deletions .changelog/2996.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
compute: `google_compute_instance_template` add plan time check for any disks marked `boot` outside of the first disk
```
15 changes: 15 additions & 0 deletions google/resource_compute_instance_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func resourceComputeInstanceTemplate() *schema.Resource {
CustomizeDiff: customdiff.All(
resourceComputeInstanceTemplateSourceImageCustomizeDiff,
resourceComputeInstanceTemplateScratchDiskCustomizeDiff,
resourceComputeInstanceTemplateBootDiskCustomizeDiff,
),
MigrateState: resourceComputeInstanceTemplateMigrateState,

Expand Down Expand Up @@ -577,6 +578,20 @@ func resourceComputeInstanceTemplateScratchDiskCustomizeDiffFunc(diff TerraformR
return nil
}

func resourceComputeInstanceTemplateBootDiskCustomizeDiff(diff *schema.ResourceDiff, meta interface{}) error {
numDisks := diff.Get("disk.#").(int)
// No disk except the first can be the boot disk
for i := 1; i < numDisks; i++ {
key := fmt.Sprintf("disk.%d.boot", i)
if v, ok := diff.GetOk(key); ok {
if v.(bool) {
return fmt.Errorf("Only the first disk specified in instance_template can be the boot disk. %s was true", key)
}
}
}
return nil
}

func buildDisks(d *schema.ResourceData, config *Config) ([]*computeBeta.AttachedDisk, error) {
project, err := getProject(d, config)
if err != nil {
Expand Down
1 change: 0 additions & 1 deletion google/resource_sql_database_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/terraform"

sqladmin "google.golang.org/api/sqladmin/v1beta4"
)

Expand Down