forked from opetch/terraform-aws-cli-resource
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
43 lines (34 loc) · 1.17 KB
/
main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
variable "cmd" {
description = "The command used to create the resource."
}
variable "role_arn" {
description = "The role arn to assume in order to run the cli command."
}
variable "dependency_ids" {
description = "IDs or ARNs of any resources that are a dependency of the resource created by this module."
type = list(string)
default = []
}
data "aws_caller_identity" "id" {
}
locals {
assume_role_cmd = "source ${path.module}/assume_role.sh ${var.role_arn}"
}
resource "null_resource" "cli_resource" {
provisioner "local-exec" {
when = create
command = "/bin/bash -c '${local.assume_role_cmd} && ${var.cmd}'"
}
# By depending on the null_resource, the cli resource effectively depends on the existance
# of the resources identified by the ids provided via the dependency_ids list variable.
depends_on = [null_resource.dependencies]
}
resource "null_resource" "dependencies" {
triggers = {
dependencies = join(",", var.dependency_ids)
}
}
output "id" {
description = "The ID of the null_resource used to provison the resource via cli. Useful for creating dependencies between cli resources"
value = null_resource.cli_resource.id
}