Skip to content

Commit e6351a3

Browse files
authored
fix: Cloudwatch Log Group deletion db_instance dependency (#423)
* depends_on support for cloudwatch log group * fix s3-import-mysql example Co-authored-by: magreenbaum <magreenbaum>
1 parent e49273b commit e6351a3

File tree

3 files changed

+15
-21
lines changed

3 files changed

+15
-21
lines changed

examples/s3-import-mysql/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ Note that this example may create resources which cost money. Run `terraform des
6464
| Name | Source | Version |
6565
|------|--------|---------|
6666
| <a name="module_db"></a> [db](#module\_db) | ../../ | n/a |
67+
| <a name="module_import_s3_bucket"></a> [import\_s3\_bucket](#module\_import\_s3\_bucket) | terraform-aws-modules/s3-bucket/aws | ~> 3.0 |
6768
| <a name="module_security_group"></a> [security\_group](#module\_security\_group) | terraform-aws-modules/security-group/aws | ~> 4.0 |
6869
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 3.0 |
6970

@@ -73,7 +74,6 @@ Note that this example may create resources which cost money. Run `terraform des
7374
|------|------|
7475
| [aws_iam_role.s3_import](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role) | resource |
7576
| [aws_iam_role_policy.s3_import](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy) | resource |
76-
| [aws_s3_bucket.import](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket) | resource |
7777
| [random_pet.this](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/pet) | resource |
7878
| [aws_iam_policy_document.s3_import](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
7979
| [aws_iam_policy_document.s3_import_assume](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |

examples/s3-import-mysql/main.tf

+12-20
Original file line numberDiff line numberDiff line change
@@ -80,25 +80,17 @@ module "security_group" {
8080
tags = local.tags
8181
}
8282

83-
# Temporary work around until S3 module is updated to support v4.x
84-
resource "aws_s3_bucket" "import" {
83+
module "import_s3_bucket" {
84+
source = "terraform-aws-modules/s3-bucket/aws"
85+
version = "~> 3.0"
86+
8587
bucket = "${local.name}-${random_pet.this.id}"
88+
acl = "private"
8689
force_destroy = true
8790

8891
tags = local.tags
8992
}
9093

91-
# module "import_s3_bucket" {
92-
# source = "terraform-aws-modules/s3-bucket/aws"
93-
# version = "~> 2.0"
94-
95-
# bucket = "${local.name}-${random_pet.this.id}"
96-
# acl = "private"
97-
# force_destroy = true
98-
99-
# tags = local.tags
100-
# }
101-
10294
data "aws_iam_policy_document" "s3_import_assume" {
10395
statement {
10496
actions = [
@@ -129,7 +121,7 @@ data "aws_iam_policy_document" "s3_import" {
129121
]
130122

131123
resources = [
132-
aws_s3_bucket.import.arn
124+
module.import_s3_bucket.s3_bucket_arn
133125
]
134126
}
135127

@@ -139,7 +131,7 @@ data "aws_iam_policy_document" "s3_import" {
139131
]
140132

141133
resources = [
142-
"${aws_s3_bucket.import.arn}/*",
134+
"${module.import_s3_bucket.s3_bucket_arn}/*",
143135
]
144136
}
145137
}
@@ -153,7 +145,7 @@ resource "aws_iam_role_policy" "s3_import" {
153145
# also needs this role so this is an easy way of ensuring the backup is uploaded before
154146
# the instance creation starts
155147
provisioner "local-exec" {
156-
command = "unzip backup.zip && aws s3 sync ${path.module}/backup s3://${aws_s3_bucket.import.id}"
148+
command = "unzip backup.zip && aws s3 sync ${path.module}/backup s3://${module.import_s3_bucket.s3_bucket_id}"
157149
}
158150
}
159151

@@ -168,7 +160,7 @@ module "db" {
168160

169161
# All available versions: http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_MySQL.html#MySQL.Concepts.VersionMgmt
170162
engine = "mysql"
171-
engine_version = "8.0.27"
163+
engine_version = "8.0.28"
172164
family = "mysql8.0" # DB parameter group
173165
major_engine_version = "8.0" # DB option group
174166
instance_class = "db.t4g.large"
@@ -182,13 +174,13 @@ module "db" {
182174

183175
# S3 import https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/MySQL.Procedural.Importing.html
184176
s3_import = {
185-
source_engine_version = "8.0.27"
186-
bucket_name = aws_s3_bucket.import.id
177+
source_engine_version = "8.0.28"
178+
bucket_name = module.import_s3_bucket.s3_bucket_id
187179
ingestion_role = aws_iam_role.s3_import.arn
188180
}
189181

190182
multi_az = true
191-
subnet_ids = module.vpc.database_subnets
183+
db_subnet_group_name = module.vpc.database_subnet_group_name
192184
vpc_security_group_ids = [module.security_group.security_group_id]
193185

194186
maintenance_window = "Mon:00:00-Mon:03:00"

modules/db_instance/main.tf

+2
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ resource "aws_db_instance" "this" {
118118

119119
tags = var.tags
120120

121+
depends_on = [aws_cloudwatch_log_group.this]
122+
121123
timeouts {
122124
create = lookup(var.timeouts, "create", null)
123125
delete = lookup(var.timeouts, "delete", null)

0 commit comments

Comments
 (0)