@@ -21,6 +21,26 @@ locals {
21
21
quota_code = quota.quota_code != null ? quota.quota_code : data.aws_servicequotas_service_quota.by_name[k].quota_code
22
22
value = quota.value
23
23
} }
24
+
25
+ # Because the API often returns default values rather than configured or applicable values,
26
+ # we have to ignore the value returned by the API or else face perpetual drift.
27
+ # To allow us to change the value in the future, even though we are ignoring it,
28
+ # we encode the value in the resource key, so that a change of value will
29
+ # result in a new resource being created and the old one being destroyed.
30
+ # Destroying the old resource has no actual effect, it does not even close
31
+ # an open request, so it is safe to do.
32
+
33
+ quota_requests = { for k , quota in local . quotas_coded_map :
34
+ format (" %v/%v/%v" , quota. service_code , quota. quota_code , quota. value ) => merge (
35
+ quota, { input_map_key = k }
36
+ )
37
+ }
38
+
39
+ quota_results = { for k , v in local . quota_requests : v . input_map_key => merge (
40
+ { for k , v in aws_servicequotas_service_quota . this [k ] : k => v if k != " value" },
41
+ { " value reported (may be inaccurate)" = aws_servicequotas_service_quota.this[k].value },
42
+ { " value requested" = v.value }
43
+ ) }
24
44
}
25
45
26
46
data "aws_servicequotas_service" "by_name" {
@@ -37,9 +57,15 @@ data "aws_servicequotas_service_quota" "by_name" {
37
57
}
38
58
39
59
resource "aws_servicequotas_service_quota" "this" {
40
- for_each = local. quotas_coded_map
60
+ for_each = local. quota_requests
41
61
42
62
quota_code = each. value . quota_code
43
63
service_code = each. value . service_code
44
64
value = each. value . value
65
+
66
+ lifecycle {
67
+ # Literally about 50% of the time, the actual value set is not available,
68
+ # so the default value is reported instead, resulting in permanent drift.
69
+ ignore_changes = [value ]
70
+ }
45
71
}
0 commit comments