Created
March 18, 2018 19:07
-
-
Save miry/51083c39541a2b034ad863616c79bbf6 to your computer and use it in GitHub Desktop.
REsize Amazon EBS volumes without a reboot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resource "aws_ebs_volume" "mysql" { | |
availability_zone = "us-east-1a" | |
size = 2000 | |
type = "gp2" | |
tags { | |
Name = "mysql" | |
Role = "db" | |
Terraform = "true" | |
FS = "xfs" | |
} | |
} | |
data "aws_instance" "mysql" { | |
filter { | |
name = "block-device-mapping.volume-id" | |
values = ["${aws_ebs_volume.mysql.id}"] | |
} | |
} | |
output "instance_id" { | |
value = "${data.aws_instance.mysql.id}" | |
} | |
locals { | |
mount_point = "${data.aws_instance.mysql.ebs_block_device.0.device_name}" | |
} | |
resource "null_resource" "expand_disk" { | |
connection { | |
type = "ssh" | |
user = "ubuntu" | |
private_key = "${file("~/.ssh/id_rsa")}" | |
host = "${data.aws_instance.mysql.public_ip}" | |
} | |
provisioner "remote-exec" { | |
inline = [ | |
"sudo lsblk", | |
"sudo xfs_growfs ${local.mount_point}", | |
] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment