Skip to content

Commit

Permalink
Merge pull request #27 from evanstachowiak/master
Browse files Browse the repository at this point in the history
Detect VPC id automatically.
  • Loading branch information
mikael-lindstrom authored Nov 3, 2019
2 parents 28feb8f + 3cee467 commit 68b15cf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ data "aws_iam_policy_document" "placeholder" {
resource "aws_security_group" "main" {
name = "${var.name_prefix}-sg"
description = "Terraformed security group."
vpc_id = var.vpc_id
vpc_id = var.vpc_id != null ? var.vpc_id : data.aws_subnet.selected.vpc_id

tags = merge(
var.tags,
Expand Down
9 changes: 9 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# ------------------------------------------------------------------------------
# Data
# ------------------------------------------------------------------------------

data "aws_subnet" "selected" {
id = var.subnet_ids[0]
}

# ------------------------------------------------------------------------------
# Variables
# ------------------------------------------------------------------------------
Expand All @@ -9,6 +17,7 @@ variable "name_prefix" {
variable "vpc_id" {
description = "The VPC ID."
type = string
default = null
}

variable "subnet_ids" {
Expand Down

0 comments on commit 68b15cf

Please sign in to comment.