Skip to content

Commit

Permalink
Add error if boot disk specified on non-first disk in instance templa…
Browse files Browse the repository at this point in the history
…te (#2996) (#5491)

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

* Move error to plan time rather than apply time

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Jan 24, 2020
1 parent f2e0e00 commit 87ffb97
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
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

0 comments on commit 87ffb97

Please sign in to comment.