What Terraform has described here is not to delete the policy JSON, but to update it in place:
~ json = jsonencode(...) -> (known after apply)
Notice that the annotation on the whole attribute is ~
, rather than -
, which means that it's being updated in place.
The (known after apply)
part of this is the interesting part: it's telling you that Terraform doesn't yet know what the final policy document JSON will be. That typically happens if any of the values that are contributing to the document are values that won't be known until the apply step, which is what the note at the top of the plan is trying to say:
# (config refers to values not yet known)
During the apply phase Terraform will again try to evaluate this data resource, at which point all of the values should be known and so it will be able to read it. It should then produce a valid policy document to use, which will probably be similar to the old one but Terraform itself doesn't know that yet.
If you want to see the new policy in full before you apply it to any other resources then you could use the -target
option to ask Terraform to focus only on making the changes that will allow deciding the JSON document, like this:
terraform apply -target=aws_s3_bucket.some-bucket.arn -target=aws_cloudwatch_log_group.some_lambda.arn
With those -target
options Terraform will skip planning the data resource and anything else that depends on it, and so you won't see any mention of data "aws_iam_policy_document" "my_policy"
in the plan. Once you've applied that partial change, you can then run terraform apply
without any arguments as normal and then Terraform should be able to evaluate the JSON policy document during the planning phase, because all of the input values will already be known.
The changes from [] -> null
for those not_actions
and not_resources
arguments seem to just be minor bugs in the provider: the provider seems to be inconsistent about whether unset is represented as an empty list or as null
, and so Terraform CLI is rendering that difference on-screen. The provider ought to be consistent about how it represents that to avoid showing this confusing extra noise.