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 scratch_disk property to google_compute_instance and deprecate disk #123

Merged
merged 4 commits into from
Jun 28, 2017

Conversation

danawillow
Copy link
Contributor

This is change 1 in a series of changes to provide a better experience for attaching/detaching disks to/from instances. The end goal is to have a separate resource for attached disks, in order to have some attached disks that are managed by terraform side-by-side with disks that are managed some other way (such as by k8s), and to allow users to attach/detach disks (see #33)

The order of the changes will look roughly like:

  1. Add boot_disk property
  2. (this) Add scratch_disk property and deprecate disk
  3. Remove disk property, make boot_disk Required
  4. Add google_compute_attached_disk resource and deprecate the attached_disk property

Note that this change branches off of #122. It can still be reviewed by only looking at the final two commits.

@@ -480,6 +497,15 @@ func resourceComputeInstanceCreate(d *schema.ResourceData, meta interface{}) err
disks = append(disks, bootDisk)
}

scratchDisks := []*compute.AttachedDisk{}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as #122 (comment), we can keep this element in block scope instead of function scope.

That would mean changing the one other use of scratchDisks from

if len(scratchDisks) > 0 {

to

if d.Get("scratch_disk.#").(int) > 0

which looks a bit grosser, but holds better semantics to me - we are giving a schema error by comparing schema elements.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just went ahead and used a bool again.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That works even better! 👍

@@ -1331,6 +1380,34 @@ func testAccComputeInstance_local_ssd(instance string) string {
}`, instance)
}

func testAccComputeInstance_scratchDisk(instance string) string {
return fmt.Sprintf(`
resource "google_compute_instance" "scratch" {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same nit as #122 (comment) and #122 (comment);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@danawillow
Copy link
Contributor Author

(will address comments later)

Note that this also ends up fixing #24.

@rileykarson
Copy link
Collaborator

Thanks for the changes! LGTM.

Copy link
Contributor

@paddycarver paddycarver left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks awesome. One minor comment to clear up.

@@ -749,7 +813,7 @@ func testAccCheckComputeInstanceDisk(instance *compute.Instance, source string,
}

for _, disk := range instance.Disks {
if strings.LastIndex(disk.Source, "/"+source) == len(disk.Source)-len(source)-1 && disk.AutoDelete == delete && disk.Boot == boot {
if strings.HasSuffix(disk.Source, source) && disk.AutoDelete == delete && disk.Boot == boot {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't stripping the slash prefixing source mean that a disk with name bar would be matched against a disk named foobar? Seems a stretch, but...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup. Fixed.

@paddycarver
Copy link
Contributor

Rebase and LGTM. 👍

@danawillow danawillow merged commit 32bf0df into hashicorp:master Jun 28, 2017
@danawillow danawillow deleted the scratch-disk branch June 28, 2017 22:44
negz pushed a commit to negz/terraform-provider-google that referenced this pull request Oct 17, 2017
…e `disk` (hashicorp#123)

* Add scratch_disk property to google_compute_instance

* docs for scratch_disk

* limit scope of scratchDisks array by using bool, test formatting

* add slash back to disk check
chrisst pushed a commit to chrisst/terraform-provider-google that referenced this pull request Nov 9, 2018
…e `disk` (hashicorp#123)

* Add scratch_disk property to google_compute_instance

* docs for scratch_disk

* limit scope of scratchDisks array by using bool, test formatting

* add slash back to disk check
luis-silva pushed a commit to luis-silva/terraform-provider-google that referenced this pull request May 21, 2019
<!-- This change is generated by MagicModules. -->
/cc @rileykarson
@ghost
Copy link

ghost commented Mar 31, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks!

@ghost ghost locked and limited conversation to collaborators Mar 31, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants