How do I tell a Windows ec2 instance to use the entire disk?

105 views
Skip to first unread message

Amedee Van Gasse

unread,
Apr 7, 2021, 10:41:48 AM4/7/21
to Terraform
I have a Windows and a Linux AWS instance that are started in a near-identical way:

resource "aws_instance" "test-instance" {
  key_name = var.key_name
  subnet_id = var.subnet_id
  instance_type = var.instance_type
  security_groups = var.security_groups
  associate_public_ip_address = "true"
  disable_api_termination = "false"
  monitoring = "false"
  tags = {
    Name = "test-instance-linux-${local.timestamp}"
  }
  root_block_device {
    volume_size = var.root_volume_size
  }
  lifecycle {
    ignore_changes = [
      tags.Name
    ]
  }
}

* test-instance-linux-${local.timestamp} for the Linux instance
* test-instance-windows-${local.timestamp} for the Windows instance
* var.root_volume_size equals '200' (GiB).

When I use this, then I see in the AWS console that both instances, Windows and Linux, have a 200 GiB volume as device /dev/sda1. Great.

However, while the Linux instance uses the entire 200 GiB, on Windows I only have 30 GiB available, which is probably the size of the original Windows_Server-2019-English-Full-Base-... AMI I started from (customized with Packer).

How do I tell the Windows instance to use the entire disk?

Sam Flint

unread,
Apr 7, 2021, 10:43:14 AM4/7/21
to terrafo...@googlegroups.com
--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/hashicorp/terraform/issues
IRC: #terraform-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Terraform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to terraform-too...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/a1c4039f-d151-44bb-88be-019b29c1580bn%40googlegroups.com.

Amedee Van Gasse

unread,
Apr 7, 2021, 10:51:41 AM4/7/21
to Terraform
To summarize: your reply is that I should run the powershell script at the bottom of that page when the instance starts?

Can you confirm or correct?

Amedee Van Gasse

unread,
Apr 8, 2021, 4:15:46 AM4/8/21
to Terraform
I added this to the resource "aws_instance" "test-instance":

   user_data = file("userdata.txt")

And this is in userdata.txt:

<powershell>
# Variable specifying the drive you want to extend
$drive_letter = "C"

# Script to get the partition sizes and then resize the volume
$size = (Get-PartitionSupportedSize -DriveLetter $drive_letter)
Resize-Partition -DriveLetter $drive_letter -Size $size.SizeMax
</powershell>


However, actual free disk space is ~8 GiB (of 30), instead of expected ~178 GiB.

So the given solution didn't work.

Amedee Van Gasse

unread,
Apr 8, 2021, 4:49:37 AM4/8/21
to Terraform
FYI
* the PowerShell script itself works, when I login manually over SSH and run the command manually, then I get the desired result
* It's the part where Terraform tells the Windows instance to run the PowerShell command, that did not work.

Sam Flint

unread,
Apr 8, 2021, 8:58:51 AM4/8/21
to terrafo...@googlegroups.com
Terraform doesn’t tell windows to run the script.  You are passing in user_data.  Terraform is just the method you are using to pass the user_data. 





Sam Flint | Director of Solutions

Reply all
Reply to author
Forward
0 new messages