0
resource "aws_instance" "launch-ec2-servers"
{
    ami = "${var.ec2_ami}"
    instance_type = "${var.instance_type}"
    key_name = "${var.key_name}"
    vpc_security_group_ids = ["${var.security_group}"]
    subnet_id = "${var.subnet_id}"
    count= "${var.count}"

    root_block_device
    {
        volume_size = "${var.root_volume_size}"
        volume_type = "${var.root_volume_type}"
    }

    ebs_block_device
    {
        device_name = "${var.ebs_device_name}"
        snapshot_id = "${var.ebs_snapshot_id}"
        volume_type = "${var.ebs_volume_type}"
    }

    tags
    {
        Name = "${var.app_name}"
    }
}

Hey,

I am trying to grab the ebs_block_device block section with regular expression in C#/PowerShell/ASP.Net.

So far, I tried this as my regular expression: (ebs_block_device)(?s)(.[^}]+.)

The block section I'm interested in from the code is:

 ebs_block_device
    {
       device_name = "${var.ebs_device_name}"
       snapshot_id = "${var.ebs_snapshot_id}"
       volume_type = "${var.ebs_volume_type}"
    }

Can you help me to grab that block of text in between the curly brackets correctly?

James
  • 875
  • 2
  • 15
  • 24

1 Answers1

0

Try this regex:

(ebs_block_device)(\s+)(\{[\s\S]*?\}(?!"))
Josh Withee
  • 9,922
  • 3
  • 44
  • 62