Skip to content

Commit

Permalink
Remove subnets module (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
SweetOps authored and const-bon committed Oct 27, 2017
1 parent 0fac6a2 commit 2942da7
Show file tree
Hide file tree
Showing 4 changed files with 160 additions and 41 deletions.
74 changes: 73 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,78 @@
# terraform-aws-vpc

Terraform module that defines a VPC with public/private subnets across multiple AZs with Internet Gateways
Terraform module that defines a VPC with Internet Gateway.


## Usage

* Quick start example:

```terraform
module "vpc" {
source = "git::https://github.com/cloudposse/terraform-aws-vpc.git?ref=master"
name = "${var.name}"
namespace = "${var.namespace}"
stage = "${var.stage}"
}
```

* Full example with [`terraform-aws-dynamic-subnets`](https://github.com/cloudposse/terraform-aws-dynamic-subnets.git):

```terraform
module "vpc" {
source = "git::https://github.com/cloudposse/terraform-aws-vpc.git?ref=master"
name = "${var.name}"
namespace = "${var.namespace}"
stage = "${var.stage}"
}
module "dynamic_subnets" {
source = "git::https://github.com/cloudposse/terraform-aws-dynamic-subnets.git?ref=master"
availability_zones = "${var.availability_zones}"
namespace = "${var.namespace}"
name = "${var.name}"
stage = "${var.stage}"
region = "${var.region}"
vpc_id = "${module.vpc.vpc_id}"
igw_id = "${module.vpc.igw_id}"
cidr_block = "${module.vpc.vpc_cidr_block}"
}
```

## Inputs

| Name | Default | Description | Required |
|:-----------------------------------|:-------------:|:---------------------------------------------------------------------------------|:--------:|
| `assign_generated_ipv6_cidr_block` | `false` | Requests an Amazon-provided IPv6 CIDR block with a /56 prefix length for the VPC | No |
| `cidr_block` | `10.0.0.0/16` | CIDR for the VPC | No |
| `enable_classiclink` | `false` | A boolean flag to enable/disable ClassicLink for the VPC | No |
| `enable_classiclink_dns_support` | `false` | A boolean flag to enable/disable ClassicLink DNS Support for the VPC | No |
| `enable_dns_hostnames` | `true` | A boolean flag to enable/disable DNS hostnames in the VPC | No |
| `enable_dns_support` | `true` | A boolean flag to enable/disable DNS support in the VPC | No |
| `instance_tenancy` | `` | A tenancy option for instances launched into the VPC | No |
| `namespace` | `` | Namespace (e.g. `cp` or `cloudposse`) | Yes |
| `stage` | `` | Stage (e.g. `prod`, `dev`, `staging`) | Yes |
| `name` | `` | Name (e.g. `bastion` or `db`) | Yes |
| `attributes` | `[]` | Additional attributes (e.g. `policy` or `role`) | No |
| `tags` | `{}` | Additional tags (e.g. `map("BusinessUnit","XYZ")` | No |
| `delimiter` | `-` | Delimiter to be used between `name`, `namespace`, `stage`, etc. | No |



## Outputs

| Name | Description |
|:--------------------------------|:----------------------------------------------------------------|
| `igw_id` | The ID of the Internet Gateway |
| `ipv6_cidr_block` | The IPv6 CIDR block |
| `vpc_cidr_block` | The CIDR block of the VPC |
| `vpc_default_network_acl_id` | The ID of the network ACL created by default on VPC creation |
| `vpc_default_route_table_id` | The ID of the route table created by default on VPC creation |
| `vpc_default_security_group_id` | The ID of the security group created by default on VPC creation |
| `vpc_id` | The ID of the VPC |
| `vpc_ipv6_association_id` | The association ID for the IPv6 CIDR block |
| `vpc_main_route_table_id` | The ID of the main route table associated with this VPC. |



## License
Expand Down
26 changes: 8 additions & 18 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,15 @@ module "label" {
tags = "${var.tags}"
}

module "subnets" {
source = "git::https://github.com/cloudposse/terraform-aws-dynamic-subnets.git?ref=tags/0.2.3"
availability_zones = "${var.availability_zones}"
namespace = "${var.namespace}"
name = "${var.name}"
stage = "${var.stage}"
region = "${var.region}"
vpc_id = "${aws_vpc.default.id}"
cidr_block = "${aws_vpc.default.cidr_block}"
igw_id = "${aws_internet_gateway.default.id}"
delimiter = "${var.delimiter}"
attributes = ["${compact(concat(var.attributes, list("subnets")))}"]
tags = "${var.tags}"
}

resource "aws_vpc" "default" {
cidr_block = "${var.cidr_block}"
enable_dns_hostnames = true
tags = "${module.label.tags}"
cidr_block = "${var.cidr_block}"
instance_tenancy = "${var.instance_tenancy}"
enable_dns_hostnames = "${var.enable_dns_hostnames}"
enable_dns_support = "${var.enable_dns_support}"
enable_classiclink = "${var.enable_classiclink}"
enable_classiclink_dns_support = "${var.enable_classiclink_dns_support}"
assign_generated_ipv6_cidr_block = "${var.assign_generated_ipv6_cidr_block}"
tags = "${module.label.tags}"
}

resource "aws_internet_gateway" "default" {
Expand Down
43 changes: 38 additions & 5 deletions outputs.tf
Original file line number Diff line number Diff line change
@@ -1,11 +1,44 @@
output "igw_id" {
value = "${aws_internet_gateway.default.id}"
description = "The ID of the Internet Gateway"
}

output "vpc_id" {
value = "${aws_vpc.default.id}"
value = "${aws_vpc.default.id}"
description = "The ID of the VPC"
}

output "vpc_cidr_block" {
value = "${aws_vpc.default.cidr_block}"
description = "The CIDR block of the VPC"
}

output "vpc_main_route_table_id" {
value = "${aws_vpc.default.main_route_table_id}"
description = "The ID of the main route table associated with this VPC."
}

output "vpc_default_network_acl_id" {
value = "${aws_vpc.default.default_network_acl_id}"
description = "The ID of the network ACL created by default on VPC creation"
}

output "vpc_default_security_group_id" {
value = "${aws_vpc.default.default_security_group_id}"
description = "The ID of the security group created by default on VPC creation"
}

output "vpc_default_route_table_id" {
value = "${aws_vpc.default.default_route_table_id}"
description = "The ID of the route table created by default on VPC creation"
}

output "public_subnet_ids" {
value = ["${module.subnets.public_subnet_ids}"]
output "vpc_ipv6_association_id" {
value = "${aws_vpc.default.ipv6_association_id}"
description = "The association ID for the IPv6 CIDR block"
}

output "private_subnet_ids" {
value = ["${module.subnets.private_subnet_ids}"]
output "ipv6_cidr_block" {
value = "${aws_vpc.default.ipv6_cidr_block}"
description = "The IPv6 CIDR block"
}
58 changes: 41 additions & 17 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -1,28 +1,16 @@
variable "namespace" {
type = "string"
description = "Namespace (e.g. `cp` or `cloudposse`)"
type = "string"
}

variable "stage" {
type = "string"
description = "Stage (e.g. `prod`, `dev`, `staging`)"
type = "string"
}

variable "name" {
type = "string"
}

variable "availability_zones" {
description = "List of Availability Zones"
type = "list"
}

variable "cidr_block" {
description = "Name (e.g. `bastion` or `db`)"
type = "string"
description = "CIDR for the VPC"
default = "10.0.0.0/16"
}

variable "region" {
type = "string"
}

variable "delimiter" {
Expand All @@ -42,3 +30,39 @@ variable "tags" {
default = {}
description = "Additional tags (e.g. `map('BusinessUnit`,`XYZ`)"
}

variable "cidr_block" {
type = "string"
description = "CIDR for the VPC"
default = "10.0.0.0/16"
}

variable "instance_tenancy" {
description = "A tenancy option for instances launched into the VPC"
default = ""
}

variable "enable_dns_hostnames" {
description = "A boolean flag to enable/disable DNS hostnames in the VPC"
default = "true"
}

variable "enable_dns_support" {
description = "A boolean flag to enable/disable DNS support in the VPC"
default = "true"
}

variable "enable_classiclink" {
description = "A boolean flag to enable/disable ClassicLink for the VPC"
default = "false"
}

variable "enable_classiclink_dns_support" {
description = "A boolean flag to enable/disable ClassicLink DNS Support for the VPC"
default = "false"
}

variable "assign_generated_ipv6_cidr_block" {
description = "Requests an Amazon-provided IPv6 CIDR block with a /56 prefix length for the VPC"
default = "false"
}

0 comments on commit 2942da7

Please sign in to comment.