From b4ace3bd62dadc269d2a0d3c13f991596055d507 Mon Sep 17 00:00:00 2001
From: Tracy Zhang <41708846+tzfromaz@users.noreply.github.com>
Date: Mon, 25 Jul 2022 09:32:29 -0700
Subject: [PATCH] fix: Replace local-exec sleep with time_sleep (#22)
---
.pre-commit-config.yaml | 2 +-
README.md | 3 +++
main.tf | 38 ++++++++++++++------------------------
versions.tf | 4 ++++
4 files changed, 22 insertions(+), 25 deletions(-)
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 4ab192b..727e21c 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/antonbabenko/pre-commit-terraform
- rev: v1.72.2
+ rev: v1.74.1
hooks:
- id: terraform_fmt
- id: terraform_validate
diff --git a/README.md b/README.md
index f95d8e5..ec938d0 100644
--- a/README.md
+++ b/README.md
@@ -304,12 +304,14 @@ Examples codified under the [`examples`](https://github.com/terraform-aws-module
|------|---------|
| [terraform](#requirement\_terraform) | >= 0.13.1 |
| [aws](#requirement\_aws) | >= 4.6 |
+| [time](#requirement\_time) | >=0.7.2 |
## Providers
| Name | Version |
|------|---------|
| [aws](#provider\_aws) | >= 4.6 |
+| [time](#provider\_time) | >=0.7.2 |
## Modules
@@ -328,6 +330,7 @@ No modules.
| [aws_iam_role.dms_access_for_endpoint](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role) | resource |
| [aws_iam_role.dms_cloudwatch_logs_role](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role) | resource |
| [aws_iam_role.dms_vpc_role](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role) | resource |
+| [time_sleep.wait_for_dependency_resources](https://registry.terraform.io/providers/hashicorp/time/latest/docs/resources/sleep) | resource |
| [aws_iam_policy_document.dms_assume_role](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
| [aws_iam_policy_document.dms_assume_role_redshift](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
| [aws_partition.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/partition) | data source |
diff --git a/main.tf b/main.tf
index e97e099..5f94291 100644
--- a/main.tf
+++ b/main.tf
@@ -41,6 +41,18 @@ data "aws_iam_policy_document" "dms_assume_role_redshift" {
}
}
+# Time Sleep
+resource "time_sleep" "wait_for_dependency_resources" {
+ depends_on = [
+ aws_iam_role.dms_access_for_endpoint,
+ aws_iam_role.dms_cloudwatch_logs_role,
+ aws_iam_role.dms_vpc_role
+ ]
+
+ create_duration = "10s"
+ destroy_duration = "10s"
+}
+
# DMS Endpoint
resource "aws_iam_role" "dms_access_for_endpoint" {
count = var.create && var.create_iam_roles ? 1 : 0
@@ -52,11 +64,6 @@ resource "aws_iam_role" "dms_access_for_endpoint" {
managed_policy_arns = ["arn:${local.partition}:iam::aws:policy/service-role/AmazonDMSRedshiftS3Role"]
force_detach_policies = true
- # https://github.com/hashicorp/terraform-provider-aws/issues/11025#issuecomment-660059684
- provisioner "local-exec" {
- command = "sleep 10"
- }
-
tags = merge(var.tags, var.iam_role_tags)
}
@@ -71,11 +78,6 @@ resource "aws_iam_role" "dms_cloudwatch_logs_role" {
managed_policy_arns = ["arn:${local.partition}:iam::aws:policy/service-role/AmazonDMSCloudWatchLogsRole"]
force_detach_policies = true
- # https://github.com/hashicorp/terraform-provider-aws/issues/11025#issuecomment-660059684
- provisioner "local-exec" {
- command = "sleep 10"
- }
-
tags = merge(var.tags, var.iam_role_tags)
}
@@ -90,11 +92,6 @@ resource "aws_iam_role" "dms_vpc_role" {
managed_policy_arns = ["arn:${local.partition}:iam::aws:policy/service-role/AmazonDMSVPCManagementRole"]
force_detach_policies = true
- # https://github.com/hashicorp/terraform-provider-aws/issues/11025#issuecomment-660059684
- provisioner "local-exec" {
- command = "sleep 10"
- }
-
tags = merge(var.tags, var.iam_role_tags)
}
@@ -111,9 +108,7 @@ resource "aws_dms_replication_subnet_group" "this" {
tags = merge(var.tags, var.repl_subnet_group_tags)
- depends_on = [
- aws_iam_role.dms_vpc_role
- ]
+ depends_on = [time_sleep.wait_for_dependency_resources]
}
################################################################################
@@ -146,12 +141,7 @@ resource "aws_dms_replication_instance" "this" {
delete = lookup(var.repl_instance_timeouts, "delete", null)
}
- # https://github.com/hashicorp/terraform-provider-aws/issues/11025#issuecomment-660059684
- depends_on = [
- aws_iam_role.dms_access_for_endpoint,
- aws_iam_role.dms_cloudwatch_logs_role,
- aws_iam_role.dms_vpc_role,
- ]
+ depends_on = [time_sleep.wait_for_dependency_resources]
}
################################################################################
diff --git a/versions.tf b/versions.tf
index f916e39..bf8eefd 100644
--- a/versions.tf
+++ b/versions.tf
@@ -6,5 +6,9 @@ terraform {
source = "hashicorp/aws"
version = ">= 4.6"
}
+ time = {
+ source = "hashicorp/time"
+ version = ">=0.7.2"
+ }
}
}