Skip to content

Commit

Permalink
Code refactoring for the VPC module
Browse files Browse the repository at this point in the history
  • Loading branch information
pvarentsov committed Jan 10, 2020
1 parent 72af856 commit b82f810
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
3 changes: 0 additions & 3 deletions src/free-tier/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,4 @@ provider "aws" {

module "vpc" {
source = "../modules/vpc"

create_vpc = true
vpc_name = "Free Tier VPC"
}
6 changes: 4 additions & 2 deletions src/modules/vpc/main.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
resource "aws_vpc" vpc {
count = var.create_vpc ? 1 : 0
cidr_block = var.vpc_cidr_block
count = var.vpc_should_be_created ? 1 : 0
cidr_block = var.vpc_cidr_block
enable_dns_hostnames = var.vpc_enable_dns_hostnames
enable_dns_support = var.vpc_enable_dns_support

tags = {
Name = var.vpc_name
Expand Down
5 changes: 5 additions & 0 deletions src/modules/vpc/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,9 @@ output "vpc_id" {
output "vpc_arn" {
description = "The ARN of the VPC"
value = concat(aws_vpc.vpc.*.arn, [""])[0]
}

output "vpc_cidr_block" {
description = "The CIDR block of the VPC"
value = concat(aws_vpc.vpc.*.cidr_block, [""])[0]
}
14 changes: 13 additions & 1 deletion src/modules/vpc/variables.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
variable "create_vpc" {
variable "vpc_should_be_created" {
description = "Should the VPC be created?"
type = bool
default = true
Expand All @@ -15,3 +15,15 @@ variable "vpc_cidr_block" {
type = string
default = "10.0.0.0/16"
}

variable "vpc_enable_dns_hostnames" {
description = "Should instances in the VPC get public DNS hostnames?"
type = bool
default = true
}

variable "vpc_enable_dns_support" {
description = "Should the DNS resolution be supported?"
type = bool
default = true
}

0 comments on commit b82f810

Please sign in to comment.