# terraform-vpc-info

## Overview

Terraform module for looking up VPC information.

## Usage

```hcl
module "vpc_info" {
  source = "git@github.com:theorchard/terraform-vpc-info.git?ref=X.X.X"

  environment = "prod"

  # Optional: minimum available IPs required when filtering subnets.
  # Set to 0 to skip IP filtering entirely.
  # Default: 25
  available_ip_limit = 25
}

# VPC ID is available as module.vpc_info.vpc_id
# Default private subnet IDs are available as module.vpc_info.default_private_subnet_ids
# Default public subnet IDs are available as module.vpc_info.default_public_subnet_ids
# Private subnet prefix list name is available as module.vpc_info.private_subnet_prefix_list_name
# Private subnet prefix list ID is available as module.vpc_info.private_subnet_prefix_list_id
# Public subnet prefix list name is available as module.vpc_info.public_subnet_prefix_list_name
# Public subnet prefix list ID is available as module.vpc_info.public_subnet_prefix_list_id
```

By default, this module filters out subnets with `available_ip_address_count <= available_ip_limit` and any subnet in excluded AZs.

**Available IP limit behavior:**
- `available_ip_limit = 25` (default) → include only subnets with > 25 free IPs
- `available_ip_limit = 0` → skip IP filtering, include all matching subnets regardless of free IPs
- Any other value → include only subnets with > N free IPs

**Output behavior:**

Note that `default_private_subnet_ids` and `default_public_subnet_ids` will return a random subset of the available subnets (which will be consistent across Terraform applies). They therefore should not be used for configuring security group rules. If you need to include all private/public subnets in a security group rule, use the appropriate prefix lists instead.


## Testing

Tests are defined using the [testing framework](https://developer.hashicorp.com/terraform/language/tests) introduced in Terraform 1.6+. To run the tests, run the following at the module root:

```
terraform init
terraform test
```

Note that the integration tests require a number of AWS profiles to be configured with the appropriate names. For profiles which define roles which require MFA to assume, you will need to ensure the `source_profile` points to a profile which represents an MFA-authenticated session. For example, set `source_profile` to `default` and then run `awsume prod -o default` to generate MFA-authenticated session credentials and export them to the default profile.
