Page MenuHomePhabricator

[terraform] Refactor search lambda IAM role policy attachments
ClosedPublic

Authored by bartek on Tue, Jun 18, 4:58 AM.
Tags
None
Referenced Files
Unknown Object (File)
Sun, Jun 30, 2:46 AM
Unknown Object (File)
Sat, Jun 29, 10:32 PM
Unknown Object (File)
Sat, Jun 29, 5:19 PM
Unknown Object (File)
Sat, Jun 29, 9:12 AM
Unknown Object (File)
Fri, Jun 28, 10:39 AM
Unknown Object (File)
Fri, Jun 28, 9:46 AM
Unknown Object (File)
Thu, Jun 27, 7:15 PM
Unknown Object (File)
Thu, Jun 27, 5:17 PM
Subscribers

Details

Summary

Noticed that each terraform plan shows this change:

Terraform will perform the following actions:

  # aws_iam_role.search_index_lambda will be updated in-place
  ~ resource "aws_iam_role" "search_index_lambda" {
        id                    = "search_index_lambda"
      ~ managed_policy_arns   = [
          - "arn:aws:iam::[CENSORED]:policy/opensearch-domain-access-policy",
            # (3 unchanged elements hidden)
        ]
        name                  = "search_index_lambda"
        tags                  = {}
        # (8 unchanged attributes hidden)
    }

  # aws_iam_role_policy_attachment.AWSLambdaVPCAccessExecutionRole will be created
  + resource "aws_iam_role_policy_attachment" "AWSLambdaVPCAccessExecutionRole" {
      + id         = (known after apply)
      + policy_arn = "arn:aws:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole"
      + role       = "search_index_lambda"
    }

This is because we use both managed_policy_arns field in "aws_iam_role" as well as "aws_iam_role_policy_attachment" resource.
When reading state, terraform doesn't know that managed_policy_arns list is not exhaustive and shows the diff when encountered value added by aws_iam_role_policy_attachment.

Deciding to use either managed_policy_arns or "aws_iam_role_policy_attachment", solves the issue. I chose the latter (better flexibility at the cost of verbosity)

Test Plan

terraform plan, after applying this, no longer suggests updating IAM role policies

Diff Detail

Repository
rCOMM Comm
Lint
Lint Not Applicable
Unit
Tests Not Applicable