Skip to content

Commit ebeabf3

Browse files
authored
fix: force vpc flow logs to wait for auth policy (#949)
1 parent ceb680d commit ebeabf3

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

atracker.tf

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,11 @@ resource "ibm_atracker_target" "atracker_target" {
2424
cos_endpoint {
2525
endpoint = "s3.private.${var.region}.cloud-object-storage.appdomain.cloud"
2626
target_crn = local.bucket_to_instance_map[var.atracker.collector_bucket_name].id
27-
bucket = ibm_cos_bucket.buckets[replace(var.atracker.collector_bucket_name, var.prefix, "")].bucket_name
27+
bucket = time_sleep.wait_for_authorization_policy_buckets[replace(var.atracker.collector_bucket_name, var.prefix, "")].triggers["bucket_name"]
2828
service_to_service_enabled = true
2929
}
3030
name = "${var.prefix}-atracker"
3131
target_type = "cloud_object_storage"
32-
33-
# Wait for buckets and auth policies to ensure successful provision
34-
depends_on = [ibm_cos_bucket.buckets, ibm_iam_authorization_policy.policy, ibm_iam_authorization_policy.cos_bucket_policy]
3532
}
3633

3734
resource "ibm_atracker_route" "atracker_route" {

main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ module "vpc" {
5858
existing_subnets = each.value.existing_subnets
5959
enable_vpc_flow_logs = (each.value.flow_logs_bucket_name != null) ? true : false
6060
create_authorization_policy_vpc_to_cos = false
61-
existing_storage_bucket_name = (each.value.flow_logs_bucket_name != null) ? ibm_cos_bucket.buckets[each.value.flow_logs_bucket_name].bucket_name : null
61+
existing_storage_bucket_name = (each.value.flow_logs_bucket_name != null) ? time_sleep.wait_for_authorization_policy_buckets[each.value.flow_logs_bucket_name].triggers["bucket_name"] : null
6262
clean_default_sg_acl = (each.value.clean_default_sg_acl == null) ? false : each.value.clean_default_sg_acl
6363
dns_binding_name = each.value.dns_binding_name
6464
dns_instance_name = each.value.dns_instance_name

service_authorizations.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,20 @@ resource "time_sleep" "wait_for_authorization_policy" {
168168
create_duration = "30s"
169169
}
170170

171+
# This time_sleep is a for_each, and will have one instance per bucket we are creating,
172+
# and dependent (timer start) on the bucket authorization creations.
173+
# The triggers serve two purposes:
174+
# - the create timer will be used again if the bucket itself is changed (the crn changes)
175+
# - if we need to reference any bucket attributes from this sleep directly, to create implicity dependency on this wait
171176
resource "time_sleep" "wait_for_authorization_policy_buckets" {
177+
for_each = ibm_cos_bucket.buckets
172178
depends_on = [ibm_iam_authorization_policy.cos_bucket_policy]
173179

180+
triggers = {
181+
bucket_name = each.value.bucket_name
182+
bucket_crn = each.value.crn
183+
}
184+
174185
create_duration = "30s"
175186
}
176187

0 commit comments

Comments
 (0)