Skip to content

Commit

Permalink
Add hack for module depend on
Browse files Browse the repository at this point in the history
  • Loading branch information
c19 committed Apr 2, 2019
1 parent 4dcc108 commit 062187c
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
31 changes: 31 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
provider "aws" {}

# Part of a hack for module-to-module dependencies.
# https://github.com/hashicorp/terraform/issues/1178#issuecomment-449158607
# and
# https://github.com/hashicorp/terraform/issues/1178#issuecomment-473091030
# Make sure to add this null_resource.dependency_getter to the `depends_on`
# attribute to all resource(s) that will be constructed first within this
# module:
resource "null_resource" "dependency_getter" {
triggers {
my_dependencies = "${join(",", var.dependencies)}"
}
}

resource "aws_security_group" "bastion" {
count = "${var.enabled}"
name = "${var.name}"
Expand Down Expand Up @@ -145,3 +160,19 @@ resource "aws_autoscaling_group" "bastion" {
create_before_destroy = true
}
}

# Part of a hack for module-to-module dependencies.
# https://github.com/hashicorp/terraform/issues/1178#issuecomment-449158607
resource "null_resource" "dependency_setter" {
# Part of a hack for module-to-module dependencies.
# https://github.com/hashicorp/terraform/issues/1178#issuecomment-449158607
# List resource(s) that will be constructed last within the module.
depends_on = [
"aws_security_group.bastion",
"aws_security_group_rule.ssh_ingress",
"aws_security_group_rule.ssh_sg_ingress",
"aws_security_group_rule.bastion_all_egress",
"aws_launch_configuration.bastion",
"aws_autoscaling_group.bastion",
]
}
8 changes: 8 additions & 0 deletions outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,11 @@ output "security_group_id" {
output "asg_id" {
value = "${element(concat(aws_autoscaling_group.bastion.*.id, list("")), 0)}"
}

# Part of a hack for module-to-module dependencies.
# https://github.com/hashicorp/terraform/issues/1178#issuecomment-449158607
# and
# https://github.com/hashicorp/terraform/issues/1178#issuecomment-473091030
output "depended_on" {
value = "${null_resource.dependency_setter.id}-${timestamp()}"
}
4 changes: 4 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,7 @@ variable "enabled" {
default = true
description = "Whether to create bastion or not."
}

variable "dependencies" {
type = "list"
}

0 comments on commit 062187c

Please sign in to comment.