Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Changes planned when no actual changes made #29393

Closed
speller opened this issue Feb 14, 2023 · 9 comments
Closed

[Bug]: Changes planned when no actual changes made #29393

speller opened this issue Feb 14, 2023 · 9 comments
Labels
bug Addresses a defect in current functionality. service/elasticsearch Issues and PRs that pertain to the elasticsearch service. service/iam Issues and PRs that pertain to the iam service. service/sts Issues and PRs that pertain to the sts service. service/vpc Issues and PRs that pertain to the vpc service.

Comments

@speller
Copy link
Contributor

speller commented Feb 14, 2023

Terraform Core Version

1.3.8

AWS Provider Version

4.54.0

Affected Resource(s)

No response

Expected Behavior

No changes planned when no changes made in the configuration.

Actual Behavior

On every plan or apply on the same configuration, I have the following plan and it never disappears:

Terraform will perform the following actions:

  # module.es.aws_elasticsearch_domain.app will be updated in-place
  ~ resource "aws_elasticsearch_domain" "app" {
        id                    = "arn:aws:es:ap-northeast-1:del:domain/dev-local-alex"
        tags                  = {
            "Name"     = "dev-local-alex-elasticsearch"
            "cost:app" = "company2"
            "cost:env" = "review"
        }
        # (9 unchanged attributes hidden)

      ~ cluster_config {
            # (7 unchanged attributes hidden)

          + zone_awareness_config {
              + availability_zone_count = 2
            }

            # (1 unchanged block hidden)
        }

        # (9 unchanged blocks hidden)
    }

  # module.service-srv.data.aws_caller_identity.current will be read during apply
  # (depends on a resource or a module with changes pending)
 <= data "aws_caller_identity" "current" {
      + account_id = (known after apply)
      + arn        = (known after apply)
      + id         = (known after apply)
      + user_id    = (known after apply)
    }

  # module.service-srv.data.aws_vpc.vpc will be read during apply
  # (depends on a resource or a module with changes pending)
 <= data "aws_vpc" "vpc" {
      + arn                                  = (known after apply)
      + cidr_block                           = (known after apply)
      + cidr_block_associations              = (known after apply)
      + default                              = (known after apply)
      + dhcp_options_id                      = (known after apply)
      + enable_dns_hostnames                 = (known after apply)
      + enable_dns_support                   = (known after apply)
      + enable_network_address_usage_metrics = (known after apply)
      + id                                   = "vpc-xxx"
      + instance_tenancy                     = (known after apply)
      + ipv6_association_id                  = (known after apply)
      + ipv6_cidr_block                      = (known after apply)
      + main_route_table_id                  = (known after apply)
      + owner_id                             = (known after apply)
      + state                                = (known after apply)
      + tags                                 = (known after apply)
    }

  # module.service-srv.aws_security_group_rule.vpc-http-srvmust be replaced
-/+ resource "aws_security_group_rule" "vpc-http-srv" {
      ~ cidr_blocks              = [
          - "10.0.0.0/16",
        ] -> (known after apply) # forces replacement
      ~ id                       = "sgrule-954072596" -> (known after apply)
      ~ security_group_rule_id   = "sgr-0181ae7369e331a8c" -> (known after apply)
      + source_security_group_id = (known after apply)
        # (7 unchanged attributes hidden)
    }

  # module.service-foo.data.aws_caller_identity.current will be read during apply
  # (depends on a resource or a module with changes pending)
 <= data "aws_caller_identity" "current" {
      + account_id = (known after apply)
      + arn        = (known after apply)
      + id         = (known after apply)
      + user_id    = (known after apply)
    }

  # module.service-foo.data.aws_vpc.vpc will be read during apply
  # (depends on a resource or a module with changes pending)
 <= data "aws_vpc" "vpc" {
      + arn                                  = (known after apply)
      + cidr_block                           = (known after apply)
      + cidr_block_associations              = (known after apply)
      + default                              = (known after apply)
      + dhcp_options_id                      = (known after apply)
      + enable_dns_hostnames                 = (known after apply)
      + enable_dns_support                   = (known after apply)
      + enable_network_address_usage_metrics = (known after apply)
      + id                                   = "vpc-xxx"
      + instance_tenancy                     = (known after apply)
      + ipv6_association_id                  = (known after apply)
      + ipv6_cidr_block                      = (known after apply)
      + main_route_table_id                  = (known after apply)
      + owner_id                             = (known after apply)
      + state                                = (known after apply)
      + tags                                 = (known after apply)
    }

  # module.service-foo.aws_security_group_rule.vpc-http-foomust be replaced
-/+ resource "aws_security_group_rule" "vpc-http-foo" {
      ~ cidr_blocks              = [
          - "10.0.0.0/16",
        ] -> (known after apply) # forces replacement
      ~ id                       = "sgrule-2688349570" -> (known after apply)
      ~ security_group_rule_id   = "sgr-08b4023480f484dd1" -> (known after apply)
      + source_security_group_id = (known after apply)
        # (7 unchanged attributes hidden)
    }

  # module.service-foo.aws_security_group_rule.vpc-http-sim must be replaced
-/+ resource "aws_security_group_rule" "vpc-http-sim" {
      ~ cidr_blocks              = [
          - "10.0.0.0/16",
        ] -> (known after apply) # forces replacement
      ~ id                       = "sgrule-2830724943" -> (known after apply)
      ~ security_group_rule_id   = "sgr-084e64c7af8357fd2" -> (known after apply)
      + source_security_group_id = (known after apply)
        # (7 unchanged attributes hidden)
    }

  # module.service-foo.aws_security_group_rule.vpc-http-sim-ui must be replaced
-/+ resource "aws_security_group_rule" "vpc-http-sim-ui" {
      ~ cidr_blocks              = [
          - "10.0.0.0/16",
        ] -> (known after apply) # forces replacement
      ~ id                       = "sgrule-359824134" -> (known after apply)
      ~ security_group_rule_id   = "sgr-0ae3b361c67543ae7" -> (known after apply)
      + source_security_group_id = (known after apply)
        # (7 unchanged attributes hidden)
    }

  # module.service-company-front.data.aws_vpc.vpc will be read during apply
  # (depends on a resource or a module with changes pending)
 <= data "aws_vpc" "vpc" {
      + arn                                  = (known after apply)
      + cidr_block                           = (known after apply)
      + cidr_block_associations              = (known after apply)
      + default                              = (known after apply)
      + dhcp_options_id                      = (known after apply)
      + enable_dns_hostnames                 = (known after apply)
      + enable_dns_support                   = (known after apply)
      + enable_network_address_usage_metrics = (known after apply)
      + id                                   = "vpc-xxx"
      + instance_tenancy                     = (known after apply)
      + ipv6_association_id                  = (known after apply)
      + ipv6_cidr_block                      = (known after apply)
      + main_route_table_id                  = (known after apply)
      + owner_id                             = (known after apply)
      + state                                = (known after apply)
      + tags                                 = (known after apply)
    }

  # module.service-company-front.aws_security_group_rule.vpc-http-front must be replaced
-/+ resource "aws_security_group_rule" "vpc-http-front" {
      ~ cidr_blocks              = [
          - "10.0.0.0/16",
        ] -> (known after apply) # forces replacement
      ~ id                       = "sgrule-310547758" -> (known after apply)
      ~ security_group_rule_id   = "sgr-0e3eaa23c5a6db676" -> (known after apply)
      + source_security_group_id = (known after apply)
        # (7 unchanged attributes hidden)
    }

  # module.service-srv.module.srv.data.aws_iam_policy_document.ec2-role will be read during apply
  # (depends on a resource or a module with changes pending)
 <= data "aws_iam_policy_document" "ec2-role" {
      + id   = (known after apply)
      + json = (known after apply)

      + statement {
          + actions = [
              + "sts:AssumeRole",
            ]
          + effect  = "Allow"

          + principals {
              + identifiers = [
                  + "ec2.amazonaws.com",
                ]
              + type        = "Service"
            }
        }
    }

  # module.service-srv.module.srv.data.aws_iam_policy_document.ec2-role-policy will be read during apply
  # (depends on a resource or a module with changes pending)
 <= data "aws_iam_policy_document" "ec2-role-policy" {
      + id   = (known after apply)
      + json = (known after apply)

      + statement {
          + actions   = [
              + "ecr:BatchCheckLayerAvailability",
              + "ecr:BatchGetImage",
              + "ecr:DescribeImages",
              + "ecr:DescribeRepositories",
              + "ecr:GetAuthorizationToken",
              + "ecr:GetDownloadUrlForLayer",
              + "ecr:GetRepositoryPolicy",
              + "ecr:ListImages",
              + "kms:Decrypt",
              + "logs:CreateLogGroup",
              + "logs:CreateLogStream",
              + "logs:DescribeLogStreams",
              + "logs:PutLogEvents",
              + "logs:TagResource",
              + "s3:DeleteObject",
              + "s3:GetObject",
              + "s3:GetObjectAcl",
              + "s3:ListBucket",
              + "s3:PutObject",
              + "secret:(sensitive)
            ]
          + effect    = "Allow"
          + resources = [
              + "*",
            ]
        }
      + statement {
          + actions   = [
              + "s3:GetObject",
            ]
          + effect    = "Allow"
          + resources = [
              + "arn:aws:s3:::amazonlinux.*.amazonaws.com/*",
              + "arn:aws:s3:::packages.*.amazonaws.com/*",
              + "arn:aws:s3:::repo.*.amazonaws.com/*",
            ]
        }
    }

  # module.service-srv.module.srv.aws_iam_policy.ec2-role-policy will be updated in-place
  ~ resource "aws_iam_policy" "ec2-role-policy" {
        id        = "arn:aws:iam::del:policy/dev-local-alex-srv-srv-role-policy"
        name      = "dev-local-alex-srv-srv-role-policy"
      ~ policy    = jsonencode(
            {
              - Statement = [
                  - {
                      - Action   = [
                          - "secret:(sensitive)
                          - "s3:PutObject",
                          - "s3:ListBucket",
                          - "s3:GetObjectAcl",
                          - "s3:GetObject",
                          - "s3:DeleteObject",
                          - "logs:TagResource",
                          - "logs:PutLogEvents",
                          - "logs:DescribeLogStreams",
                          - "logs:CreateLogStream",
                          - "logs:CreateLogGroup",
                          - "kms:Decrypt",
                          - "ecr:ListImages",
                          - "ecr:GetRepositoryPolicy",
                          - "ecr:GetDownloadUrlForLayer",
                          - "ecr:GetAuthorizationToken",
                          - "ecr:DescribeRepositories",
                          - "ecr:DescribeImages",
                          - "ecr:BatchGetImage",
                          - "ecr:BatchCheckLayerAvailability",
                        ]
                      - Effect   = "Allow"
                      - Resource = "*"
                      - Sid      = ""
                    },
                  - {
                      - Action   = "s3:GetObject"
                      - Effect   = "Allow"
                      - Resource = [
                          - "arn:aws:s3:::repo.*.amazonaws.com/*",
                          - "arn:aws:s3:::packages.*.amazonaws.com/*",
                          - "arn:aws:s3:::amazonlinux.*.amazonaws.com/*",
                        ]
                      - Sid      = ""
                    },
                ]
              - Version   = "2012-10-17"
            }
        ) -> (known after apply)
        tags      = {}
        # (4 unchanged attributes hidden)
    }

  # module.service-srv.module.srv.aws_iam_role.ec2-role will be updated in-place
  ~ resource "aws_iam_role" "ec2-role" {
      ~ assume_role_policy    = jsonencode(
            {
              - Statement = [
                  - {
                      - Action    = "sts:AssumeRole"
                      - Effect    = "Allow"
                      - Principal = {
                          - Service = "ec2.amazonaws.com"
                        }
                      - Sid       = ""
                    },
                ]
              - Version   = "2012-10-17"
            }
        ) -> (known after apply)
        id                    = "dev-local-alex-srv-srv-role"
        name                  = "dev-local-alex-srv-srv-role"
        tags                  = {
            "Name"     = "dev-local-alex-srv-srv-iam-role"
            "cost:app" = "company-srv"
            "cost:env" = "review"
        }
        # (8 unchanged attributes hidden)
    }

  # module.service-srv.module.srv-db.data.aws_vpc.vpc will be read during apply
  # (depends on a resource or a module with changes pending)
 <= data "aws_vpc" "vpc" {
      + arn                                  = (known after apply)
      + cidr_block                           = (known after apply)
      + cidr_block_associations              = (known after apply)
      + default                              = (known after apply)
      + dhcp_options_id                      = (known after apply)
      + enable_dns_hostnames                 = (known after apply)
      + enable_dns_support                   = (known after apply)
      + enable_network_address_usage_metrics = (known after apply)
      + id                                   = "vpc-xxx"
      + instance_tenancy                     = (known after apply)
      + ipv6_association_id                  = (known after apply)
      + ipv6_cidr_block                      = (known after apply)
      + main_route_table_id                  = (known after apply)
      + owner_id                             = (known after apply)
      + state                                = (known after apply)
      + tags                                 = (known after apply)
    }

  # module.service-srv.module.srv-db.aws_security_group_rule.app-db must be replaced
-/+ resource "aws_security_group_rule" "app-db" {
      ~ cidr_blocks              = [
          - "10.0.0.0/16",
        ] -> (known after apply) # forces replacement
      ~ id                       = "sgrule-688460087" -> (known after apply)
      ~ security_group_rule_id   = "sgr-0f55b5d09c560b03f" -> (known after apply)
      + source_security_group_id = (known after apply)
        # (7 unchanged attributes hidden)
    }

  # module.service-magento2.module.graphql.data.aws_iam_policy_document.ec2-role will be read during apply
  # (depends on a resource or a module with changes pending)
 <= data "aws_iam_policy_document" "ec2-role" {
      + id   = (known after apply)
      + json = (known after apply)

      + statement {
          + actions = [
              + "sts:AssumeRole",
            ]
          + effect  = "Allow"

          + principals {
              + identifiers = [
                  + "ec2.amazonaws.com",
                ]
              + type        = "Service"
            }
        }
    }

  # module.service-magento2.module.graphql.data.aws_iam_policy_document.ec2-role-policy will be read during apply
  # (depends on a resource or a module with changes pending)
 <= data "aws_iam_policy_document" "ec2-role-policy" {
      + id   = (known after apply)
      + json = (known after apply)

      + statement {
          + actions   = [
              + "ecr:BatchCheckLayerAvailability",
              + "ecr:BatchGetImage",
              + "ecr:DescribeImages",
              + "ecr:DescribeRepositories",
              + "ecr:GetAuthorizationToken",
              + "ecr:GetDownloadUrlForLayer",
              + "ecr:GetRepositoryPolicy",
              + "ecr:ListImages",
              + "kms:Decrypt",
              + "logs:CreateLogGroup",
              + "logs:CreateLogStream",
              + "logs:DescribeLogStreams",
              + "logs:PutLogEvents",
              + "logs:TagResource",
              + "s3:DeleteObject",
              + "s3:GetObject",
              + "s3:GetObjectAcl",
              + "s3:ListBucket",
              + "s3:PutObject",
              + "secret:(sensitive)
            ]
          + effect    = "Allow"
          + resources = [
              + "*",
            ]
        }
      + statement {
          + actions   = [
              + "s3:GetObject",
            ]
          + effect    = "Allow"
          + resources = [
              + "arn:aws:s3:::amazonlinux.*.amazonaws.com/*",
              + "arn:aws:s3:::packages.*.amazonaws.com/*",
              + "arn:aws:s3:::repo.*.amazonaws.com/*",
            ]
        }
    }

  # module.service-magento2.module.graphql.aws_iam_policy.ec2-role-policy will be updated in-place
  ~ resource "aws_iam_policy" "ec2-role-policy" {
        id        = "arn:aws:iam::del:policy/dev-local-alex-magento2-be-role-policy"
        name      = "dev-local-alex-magento2-be-role-policy"
      ~ policy    = jsonencode(
            {
              - Statement = [
                  - {
                      - Action   = [
                          - "secret:(sensitive)
                          - "s3:PutObject",
                          - "s3:ListBucket",
                          - "s3:GetObjectAcl",
                          - "s3:GetObject",
                          - "s3:DeleteObject",
                          - "logs:TagResource",
                          - "logs:PutLogEvents",
                          - "logs:DescribeLogStreams",
                          - "logs:CreateLogStream",
                          - "logs:CreateLogGroup",
                          - "kms:Decrypt",
                          - "ecr:ListImages",
                          - "ecr:GetRepositoryPolicy",
                          - "ecr:GetDownloadUrlForLayer",
                          - "ecr:GetAuthorizationToken",
                          - "ecr:DescribeRepositories",
                          - "ecr:DescribeImages",
                          - "ecr:BatchGetImage",
                          - "ecr:BatchCheckLayerAvailability",
                        ]
                      - Effect   = "Allow"
                      - Resource = "*"
                      - Sid      = ""
                    },
                  - {
                      - Action   = "s3:GetObject"
                      - Effect   = "Allow"
                      - Resource = [
                          - "arn:aws:s3:::repo.*.amazonaws.com/*",
                          - "arn:aws:s3:::packages.*.amazonaws.com/*",
                          - "arn:aws:s3:::amazonlinux.*.amazonaws.com/*",
                        ]
                      - Sid      = ""
                    },
                ]
              - Version   = "2012-10-17"
            }
        ) -> (known after apply)
        tags      = {}
        # (4 unchanged attributes hidden)
    }

  # module.service-magento2.module.graphql.aws_iam_role.ec2-role will be updated in-place
  ~ resource "aws_iam_role" "ec2-role" {
      ~ assume_role_policy    = jsonencode(
            {
              - Statement = [
                  - {
                      - Action    = "sts:AssumeRole"
                      - Effect    = "Allow"
                      - Principal = {
                          - Service = "ec2.amazonaws.com"
                        }
                      - Sid       = ""
                    },
                ]
              - Version   = "2012-10-17"
            }
        ) -> (known after apply)
        id                    = "dev-local-alex-magento2-be-role"
        name                  = "dev-local-alex-magento2-be-role"
        tags                  = {
            "Name"     = "dev-local-alex-magento2-be-iam-role"
            "cost:app" = "company-magento2-backend"
            "cost:env" = "review"
        }
        # (8 unchanged attributes hidden)
    }

  # module.service-foo.module.foo.data.aws_iam_policy_document.ec2-role will be read during apply
  # (depends on a resource or a module with changes pending)
 <= data "aws_iam_policy_document" "ec2-role" {
      + id   = (known after apply)
      + json = (known after apply)

      + statement {
          + actions = [
              + "sts:AssumeRole",
            ]
          + effect  = "Allow"

          + principals {
              + identifiers = [
                  + "ec2.amazonaws.com",
                ]
              + type        = "Service"
            }
        }
    }

  # module.service-foo.module.foo.data.aws_iam_policy_document.ec2-role-policy will be read during apply
  # (depends on a resource or a module with changes pending)
 <= data "aws_iam_policy_document" "ec2-role-policy" {
      + id   = (known after apply)
      + json = (known after apply)

      + statement {
          + actions   = [
              + "ecr:BatchCheckLayerAvailability",
              + "ecr:BatchGetImage",
              + "ecr:DescribeImages",
              + "ecr:DescribeRepositories",
              + "ecr:GetAuthorizationToken",
              + "ecr:GetDownloadUrlForLayer",
              + "ecr:GetRepositoryPolicy",
              + "ecr:ListImages",
              + "kms:Decrypt",
              + "logs:CreateLogGroup",
              + "logs:CreateLogStream",
              + "logs:DescribeLogStreams",
              + "logs:PutLogEvents",
              + "logs:TagResource",
              + "s3:DeleteObject",
              + "s3:GetObject",
              + "s3:GetObjectAcl",
              + "s3:ListBucket",
              + "s3:PutObject",
              + "secret:(sensitive)
            ]
          + effect    = "Allow"
          + resources = [
              + "*",
            ]
        }
      + statement {
          + actions   = [
              + "s3:GetObject",
            ]
          + effect    = "Allow"
          + resources = [
              + "arn:aws:s3:::amazonlinux.*.amazonaws.com/*",
              + "arn:aws:s3:::packages.*.amazonaws.com/*",
              + "arn:aws:s3:::repo.*.amazonaws.com/*",
            ]
        }
    }

  # module.service-foo.module.foo.aws_iam_policy.ec2-role-policy will be updated in-place
  ~ resource "aws_iam_policy" "ec2-role-policy" {
        id        = "arn:aws:iam::del:policy/dev-local-alex-foo-foo-role-policy"
        name      = "dev-local-alex-foo-foo-role-policy"
      ~ policy    = jsonencode(
            {
              - Statement = [
                  - {
                      - Action   = [
                          - "secret:(sensitive)
                          - "s3:PutObject",
                          - "s3:ListBucket",
                          - "s3:GetObjectAcl",
                          - "s3:GetObject",
                          - "s3:DeleteObject",
                          - "logs:TagResource",
                          - "logs:PutLogEvents",
                          - "logs:DescribeLogStreams",
                          - "logs:CreateLogStream",
                          - "logs:CreateLogGroup",
                          - "kms:Decrypt",
                          - "ecr:ListImages",
                          - "ecr:GetRepositoryPolicy",
                          - "ecr:GetDownloadUrlForLayer",
                          - "ecr:GetAuthorizationToken",
                          - "ecr:DescribeRepositories",
                          - "ecr:DescribeImages",
                          - "ecr:BatchGetImage",
                          - "ecr:BatchCheckLayerAvailability",
                        ]
                      - Effect   = "Allow"
                      - Resource = "*"
                      - Sid      = ""
                    },
                  - {
                      - Action   = "s3:GetObject"
                      - Effect   = "Allow"
                      - Resource = [
                          - "arn:aws:s3:::repo.*.amazonaws.com/*",
                          - "arn:aws:s3:::packages.*.amazonaws.com/*",
                          - "arn:aws:s3:::amazonlinux.*.amazonaws.com/*",
                        ]
                      - Sid      = ""
                    },
                ]
              - Version   = "2012-10-17"
            }
        ) -> (known after apply)
        tags      = {}
        # (4 unchanged attributes hidden)
    }

  # module.service-foo.module.foo.aws_iam_role.ec2-role will be updated in-place
  ~ resource "aws_iam_role" "ec2-role" {
      ~ assume_role_policy    = jsonencode(
            {
              - Statement = [
                  - {
                      - Action    = "sts:AssumeRole"
                      - Effect    = "Allow"
                      - Principal = {
                          - Service = "ec2.amazonaws.com"
                        }
                      - Sid       = ""
                    },
                ]
              - Version   = "2012-10-17"
            }
        ) -> (known after apply)
        id                    = "dev-local-alex-foo-foo-role"
        name                  = "dev-local-alex-foo-foo-role"
        tags                  = {
            "Name"     = "dev-local-alex-foo-foo-iam-role"
            "cost:app" = "company-foo"
            "cost:env" = "review"
        }
        # (8 unchanged attributes hidden)
    }

  # module.service-foo.module.foo-db.data.aws_vpc.vpc will be read during apply
  # (depends on a resource or a module with changes pending)
 <= data "aws_vpc" "vpc" {
      + arn                                  = (known after apply)
      + cidr_block                           = (known after apply)
      + cidr_block_associations              = (known after apply)
      + default                              = (known after apply)
      + dhcp_options_id                      = (known after apply)
      + enable_dns_hostnames                 = (known after apply)
      + enable_dns_support                   = (known after apply)
      + enable_network_address_usage_metrics = (known after apply)
      + id                                   = "vpc-xxx"
      + instance_tenancy                     = (known after apply)
      + ipv6_association_id                  = (known after apply)
      + ipv6_cidr_block                      = (known after apply)
      + main_route_table_id                  = (known after apply)
      + owner_id                             = (known after apply)
      + state                                = (known after apply)
      + tags                                 = (known after apply)
    }

  # module.service-foo.module.foo-db.aws_security_group_rule.app-db must be replaced
-/+ resource "aws_security_group_rule" "app-db" {
      ~ cidr_blocks              = [
          - "10.0.0.0/16",
        ] -> (known after apply) # forces replacement
      ~ id                       = "sgrule-2335836688" -> (known after apply)
      ~ security_group_rule_id   = "sgr-062e30fd62dd948d0" -> (known after apply)
      + source_security_group_id = (known after apply)
        # (7 unchanged attributes hidden)
    }

  # module.service-company-front.module.frontend.data.aws_iam_policy_document.ec2-role will be read during apply
  # (depends on a resource or a module with changes pending)
 <= data "aws_iam_policy_document" "ec2-role" {
      + id   = (known after apply)
      + json = (known after apply)

      + statement {
          + actions = [
              + "sts:AssumeRole",
            ]
          + effect  = "Allow"

          + principals {
              + identifiers = [
                  + "ec2.amazonaws.com",
                ]
              + type        = "Service"
            }
        }
    }

  # module.service-company-front.module.frontend.data.aws_iam_policy_document.ec2-role-policy will be read during apply
  # (depends on a resource or a module with changes pending)
 <= data "aws_iam_policy_document" "ec2-role-policy" {
      + id   = (known after apply)
      + json = (known after apply)

      + statement {
          + actions   = [
              + "ecr:BatchCheckLayerAvailability",
              + "ecr:BatchGetImage",
              + "ecr:DescribeImages",
              + "ecr:DescribeRepositories",
              + "ecr:GetAuthorizationToken",
              + "ecr:GetDownloadUrlForLayer",
              + "ecr:GetRepositoryPolicy",
              + "ecr:ListImages",
              + "kms:Decrypt",
              + "logs:CreateLogGroup",
              + "logs:CreateLogStream",
              + "logs:DescribeLogStreams",
              + "logs:PutLogEvents",
              + "logs:TagResource",
              + "s3:DeleteObject",
              + "s3:GetObject",
              + "s3:GetObjectAcl",
              + "s3:ListBucket",
              + "s3:PutObject",
              + "secret:(sensitive)
            ]
          + effect    = "Allow"
          + resources = [
              + "*",
            ]
        }
      + statement {
          + actions   = [
              + "s3:GetObject",
            ]
          + effect    = "Allow"
          + resources = [
              + "arn:aws:s3:::amazonlinux.*.amazonaws.com/*",
              + "arn:aws:s3:::packages.*.amazonaws.com/*",
              + "arn:aws:s3:::repo.*.amazonaws.com/*",
            ]
        }
    }

  # module.service-company-front.module.frontend.aws_iam_policy.ec2-role-policy will be updated in-place
  ~ resource "aws_iam_policy" "ec2-role-policy" {
        id        = "arn:aws:iam::del:policy/dev-local-alex-company-front-fe-role-policy"
        name      = "dev-local-alex-company-front-fe-role-policy"
      ~ policy    = jsonencode(
            {
              - Statement = [
                  - {
                      - Action   = [
                          - "secret:(sensitive)
                          - "s3:PutObject",
                          - "s3:ListBucket",
                          - "s3:GetObjectAcl",
                          - "s3:GetObject",
                          - "s3:DeleteObject",
                          - "logs:TagResource",
                          - "logs:PutLogEvents",
                          - "logs:DescribeLogStreams",
                          - "logs:CreateLogStream",
                          - "logs:CreateLogGroup",
                          - "kms:Decrypt",
                          - "ecr:ListImages",
                          - "ecr:GetRepositoryPolicy",
                          - "ecr:GetDownloadUrlForLayer",
                          - "ecr:GetAuthorizationToken",
                          - "ecr:DescribeRepositories",
                          - "ecr:DescribeImages",
                          - "ecr:BatchGetImage",
                          - "ecr:BatchCheckLayerAvailability",
                        ]
                      - Effect   = "Allow"
                      - Resource = "*"
                      - Sid      = ""
                    },
                  - {
                      - Action   = "s3:GetObject"
                      - Effect   = "Allow"
                      - Resource = [
                          - "arn:aws:s3:::repo.*.amazonaws.com/*",
                          - "arn:aws:s3:::packages.*.amazonaws.com/*",
                          - "arn:aws:s3:::amazonlinux.*.amazonaws.com/*",
                        ]
                      - Sid      = ""
                    },
                ]
              - Version   = "2012-10-17"
            }
        ) -> (known after apply)
        tags      = {}
        # (4 unchanged attributes hidden)
    }

  # module.service-company-front.module.frontend.aws_iam_role.ec2-role will be updated in-place
  ~ resource "aws_iam_role" "ec2-role" {
      ~ assume_role_policy    = jsonencode(
            {
              - Statement = [
                  - {
                      - Action    = "sts:AssumeRole"
                      - Effect    = "Allow"
                      - Principal = {
                          - Service = "ec2.amazonaws.com"
                        }
                      - Sid       = ""
                    },
                ]
              - Version   = "2012-10-17"
            }
        ) -> (known after apply)
        id                    = "dev-local-alex-company-front-fe-role"
        name                  = "dev-local-alex-company-front-fe-role"
        tags                  = {
            "Name"     = "dev-local-alex-company-front-fe-iam-role"
            "cost:app" = "company-frontend"
            "cost:env" = "review"
        }
        # (8 unchanged attributes hidden)
    }

Plan: 7 to add, 9 to change, 7 to destroy.

Relevant Error/Panic Output Snippet

No response

Terraform Configuration Files

resource "aws_elasticsearch_domain" "app" {
  domain_name = local.domain_name
  elasticsearch_version = var.es_version
  cluster_config {
    instance_type = "t3.medium.elasticsearch"
    instance_count = var.instance_count
    zone_awareness_enabled = var.instance_count > 1
    zone_awareness_config {
      availability_zone_count = 2
    }
  }
  vpc_options {
    subnet_ids = var.instance_count > 1 ? [ var.subnet1_id, var.subnet2_id, ] : [var.subnet1_id]
    security_group_ids = [
      aws_security_group.es.id,
    ]
  }
  snapshot_options {
    automated_snapshot_start_hour = 0
  }
  encrypt_at_rest {
    enabled = false
  }
  ebs_options {
    ebs_enabled = true
    volume_size = 10
  }
  access_policies = <<EOT
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "AWS": "*"
      },
      "Action": "es:*",
      "Resource": "arn:aws:es:${var.aws_region}:${data.aws_caller_identity.current.account_id}:domain/${local.domain_name}/*"
    }
  ]
}
EOT
  tags = {
    Name = "${local.infra_name_hyphen}-elasticsearch"
    "cost:env" = var.cost_env
    "cost:app" = var.cost_app
  }
  lifecycle {
    create_before_destroy = true
  }
}


resource "aws_security_group_rule" "vpc-http-srv" {
  description = "Allow srvHTTP access from VPC"
  from_port = var.srv.port
  to_port = var.srv.port
  protocol = "tcp"
  security_group_id = module.srv.security_group_id
  cidr_blocks = [data.aws_vpc.vpc.cidr_block]
  type = "ingress"
}

resource "aws_iam_role" "ec2-role" {
  name = "${local.infra_name_hyphen}-role"
  assume_role_policy = data.aws_iam_policy_document.ec2-role.json
  tags = {
    Name = "${local.infra_name_hyphen}-iam-role"
    "cost:env" = var.cost_env
    "cost:app" = var.cost_app
  }
}

data "aws_iam_policy_document" "ec2-role-policy" {
  statement {
    effect = "Allow"
    resources = ["*"]
    actions = [
      "s3:GetObject",
      "s3:PutObject",
      "s3:ListBucket",
      "s3:GetObjectAcl",
      "s3:DeleteObject",
      "ecr:GetAuthorizationToken",
      "ecr:BatchCheckLayerAvailability",
      "ecr:GetDownloadUrlForLayer",
      "ecr:GetRepositoryPolicy",
      "ecr:DescribeRepositories",
      "ecr:ListImages",
      "ecr:DescribeImages",
      "ecr:BatchGetImage",
      "logs:CreateLogGroup",
      "logs:CreateLogStream",
      "logs:PutLogEvents",
      "logs:DescribeLogStreams",
      "logs:TagResource",
      "secretsmanager:GetSecretValue",
      "kms:Decrypt",
    ]
  }
  statement {
    effect = "Allow"
    resources = [
      "arn:aws:s3:::packages.*.amazonaws.com/*",
      "arn:aws:s3:::repo.*.amazonaws.com/*",
      "arn:aws:s3:::amazonlinux.*.amazonaws.com/*",
    ]
    actions = ["s3:GetObject"]
  }
}

resource "aws_iam_policy" "ec2-role-policy" {
  name = "${local.infra_name_hyphen}-role-policy"
  policy = data.aws_iam_policy_document.ec2-role-policy.json
}

All other resources have similar configuration

Steps to Reproduce

apply command

Debug Output

No response

Panic Output

No response

Important Factoids

No response

References

No response

Would you like to implement a fix?

None

@speller speller added bug Addresses a defect in current functionality. needs-triage Waiting for first response or review from a maintainer. labels Feb 14, 2023
@github-actions
Copy link

Community Note

Voting for Prioritization

  • Please vote on this issue by adding a 👍 reaction to the original post to help the community and maintainers prioritize this request.
  • Please see our prioritization guide for information on how we prioritize.
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request.

Volunteering to Work on This Issue

  • If you are interested in working on this issue, please leave a comment.
  • If this would be your first contribution, please review the contribution guide.

@github-actions github-actions bot added service/elasticsearch Issues and PRs that pertain to the elasticsearch service. service/iam Issues and PRs that pertain to the iam service. service/sts Issues and PRs that pertain to the sts service. service/vpc Issues and PRs that pertain to the vpc service. labels Feb 14, 2023
@justinretzolk
Copy link
Member

Hey @speller 👋 Thank you for taking the time to raise this! It's a bit difficult to say with certainty, as I'm having a bit of a hard time understanding how your configurations / modules are arranged, however, I believe this likely comes down to data resource behavior. When a data source is dependent on another object that has planned changes, the read is deferred until apply time. Any resource that then depend on that data source will show changes with (known after apply), since the value from the data source cannot be determined until apply time.

@justinretzolk justinretzolk added waiting-response Maintainers are waiting on response from community or contributor. and removed needs-triage Waiting for first response or review from a maintainer. labels Mar 6, 2023
@speller
Copy link
Contributor Author

speller commented Mar 7, 2023

@justinretzolk But the issue also relates to aws_iam_policy_document and aws_iam_policy documents. The aws_iam_policy_document data resource is not dependent on anything, it's static data. Why it is planned to be changed?

@github-actions github-actions bot removed the waiting-response Maintainers are waiting on response from community or contributor. label Mar 7, 2023
@justinretzolk
Copy link
Member

Hey @speller 👋 Based on the output, it would appear that the module that contains the aws_iam_policy_document data source is dependent on either a resource or module that has changes. To show an example of this, I put together a quick reproduction, which I'll outline below.

The tree of the reproduction looks like so:

$ tree .
.
├── main.tf
└── modules
    ├── null
    │   └── main.tf
    └── policy
        └── main.tf

The contents of each of the files appears like so:

/modules/null/main.tf

resource "null_resource" "null" {}

/modules/policy/main.tf (note: the policy that I'm using here is just something I had lying around; nothing of any consequence)

data "aws_iam_policy_document" "my_policy" {

  statement {
    sid    = "AllowManageOwnVirtualMFADevice"
    effect = "Allow"

    actions = [
      "iam:CreateVirtualMFADevice",
    ]

    resources = [
      "arn:aws:iam::*:mfa/*",
      "arn:aws:iam::*:u2f/*"
    ]
  }
}

output "test" {
  value = data.aws_iam_policy_document.my_policy.json
}

main.tf

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "4.54.0"
    }
    null = {
      source  = "hashicorp/null"
      version = "3.2.1"
    }
  }
}

module "null" {
  source = "./modules/null"
}

module "policy" {
  source = "./modules/policy"

  # Note that this depends_on is commented out. We'll uncomment this later to introduce a dependency
  # between the two modules.
  # depends_on = [
  #   module.null
  # ]
}

output "test" {
  value = module.policy.test
}

With the reproduction set up this way, there is no dependency between the null module and the policy module in the root configuration. When running terraform plan, the following is output:

$ terraform plan
module.policy.data.aws_iam_policy_document.my_policy: Reading...
module.policy.data.aws_iam_policy_document.my_policy: Read complete after 0s [id=2835584606]

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following
symbols:
  + create

Terraform will perform the following actions:

  # module.null.null_resource.null will be created
  + resource "null_resource" "null" {
      + id = (known after apply)
    }

Plan: 1 to add, 0 to change, 0 to destroy.

Changes to Outputs:
  + test = jsonencode(
        {
          + Statement = [
              + {
                  + Action   = "iam:CreateVirtualMFADevice"
                  + Effect   = "Allow"
                  + Resource = [
                      + "arn:aws:iam::*:u2f/*",
                      + "arn:aws:iam::*:mfa/*",
                    ]
                  + Sid      = "AllowManageOwnVirtualMFADevice"
                },
            ]
          + Version   = "2012-10-17"
        }
    )

Note that the output shows the policy as you would expect, read during plan time. Next, we'll uncomment the depends_on in the policy module call. This introduces a dependency between the two modules, however, the aws_iam_policy_document remains static, as is the case in your configuration. Running a terraform plan with this configuration yields the following output:

$ terraform plan

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following
symbols:
  + create
 <= read (data resources)

Terraform will perform the following actions:

  # module.null.null_resource.null will be created
  + resource "null_resource" "null" {
      + id = (known after apply)
    }

  # module.policy.data.aws_iam_policy_document.my_policy will be read during apply
  # (depends on a resource or a module with changes pending)
 <= data "aws_iam_policy_document" "my_policy" {
      + id   = (known after apply)
      + json = (known after apply)

      + statement {
          + actions   = [
              + "iam:CreateVirtualMFADevice",
            ]
          + effect    = "Allow"
          + resources = [
              + "arn:aws:iam::*:mfa/*",
              + "arn:aws:iam::*:u2f/*",
            ]
          + sid       = "AllowManageOwnVirtualMFADevice"
        }
    }

Plan: 1 to add, 0 to change, 0 to destroy.

Changes to Outputs:
  + test = (known after apply)

Note that in this case, due to the module that contains the aws_iam_policy_document depending on another resource or module (in this case, a module) that has pending changes, the read must be deferred to apply time. It's not necessarily that anything is changing with the data source, rather, due to the dependency and the fact that said dependency has a pending change, the read must be deferred. In your case, any resources that depend on the data source will also need to be deferred to apply time, when the values of the data source are known. I hope that helps better illustrate what's going on here. If I've misunderstood your configuration and you have follow up questions, I'm happy to keep chatting about it! 🙂

@speller
Copy link
Contributor Author

speller commented Mar 9, 2023

Thank you for the explanation!
But from my point of view, it is useless to defer reading data objects which have no dependencies on other variables or resources. Like here - the content is static and never changed. It adds noise to the log and adds useless apply operations. It would be nice if TF will be smarter here and detect static data.

@justinretzolk
Copy link
Member

I can definitely see your opinion there @speller. Truthfully, that bit comes down to Terraform Core functionality rather than something specific to the AWS Provider, so it may be worth raising an issue on that repository if you'd like to have someone from the Core team take a look and give you more pointed feedback on the design choices there.

In the meantime, is there any additional help we can provide from the AWS Provider side on this particular issue, or would you feel comfortable with closing this one out?

@justinretzolk
Copy link
Member

Given the conversation in the linked thread in hashicorp/terraform, I'm going to go ahead and close this issue out. Thank you again for the great discussion!

Copy link

Warning

This issue has been closed, meaning that any additional comments are hard for our team to see. Please assume that the maintainers will not see them.

Ongoing conversations amongst community members are welcome, however, the issue will be locked after 30 days. Moving conversations to another venue, such as the AWS Provider forum, is recommended. If you have additional concerns, please open a new issue, referencing this one where needed.

Copy link

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Addresses a defect in current functionality. service/elasticsearch Issues and PRs that pertain to the elasticsearch service. service/iam Issues and PRs that pertain to the iam service. service/sts Issues and PRs that pertain to the sts service. service/vpc Issues and PRs that pertain to the vpc service.
Projects
None yet
Development

No branches or pull requests

2 participants