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]: aws_vpc_endpoint does not remove custom policy from resource if removed from Terraform config #40973

Open
mhemani-reach opened this issue Jan 16, 2025 · 1 comment
Labels
bug Addresses a defect in current functionality. needs-triage Waiting for first response or review from a maintainer. service/iam Issues and PRs that pertain to the iam service. service/vpc Issues and PRs that pertain to the vpc service.

Comments

@mhemani-reach
Copy link

Terraform Core Version

1.5.7

AWS Provider Version

5.84.0, 5.67.0

Affected Resource(s)

  • aws_vpc_endpoint

Expected Behavior

If the policy parameter is removed from the aws_vpc_endpoint resource, it should remove the custom policy from the endpoint and revert to the default policy. This is the behaviour when modifying the endpoint on the AWS web console.

Actual Behavior

No changes. Your infrastructure matches the configuration.

Terraform has compared your real infrastructure against your configuration and found no differences, so no changes are needed

Relevant Error/Panic Output Snippet

Terraform Configuration Files

resource "aws_vpc_endpoint" "this" {
  vpc_id = var.vpc_id
  service_name = "com.amazonaws.us-east-1.elasticmapreduce"
  vpc_endpoint_type = "Interface"
  security_group_ids = [aws_security_group.vpc-endpoints.id]
  subnet_ids = var.private_subnets
  private_dns_enabled = true
  tags = {
    Name = "${module.vpc.name}-emr-endpoint"
  }
  policy = data.aws_iam_policy_document.vpc-endpoint-policy.json
}

resource "aws_security_group" "vpc-endpoints" {
 name        = "vpc-endpoints"
  description = "Security group for VPC Endpoints"
  vpc_id      = var.vpc_id
  tags = {
    "Name" = "${module.vpc.name}-endpoints"
  }
  lifecycle {
    create_before_destroy = true
  }
}

resource "aws_vpc_security_group_ingress_rule" "vpc-endpoints-ingress" {
  description       = "Allow traffic to VPC endpoints"
  security_group_id = aws_security_group.vpc-endpoints.id
  cidr_ipv4         = "10.0.0.0/8"
  from_port         = 443
  to_port           = 443
  ip_protocol       = "tcp"
}

data "aws_iam_policy_document" "vpc-endpoint-policy" {
  statement {
    sid       = "DenyIfNotFromVpc"
    effect    = "Deny"
    actions   = ["*"]
    resources = ["*"]
    principals {
      type        = "*"
      identifiers = ["*"]
    }
    condition {
      test     = "StringNotEquals"
      values   = [var.vpc_id]
      variable = "aws:sourceVpc"
    }
  }
}

Steps to Reproduce

  1. Apply terraform to create the VPC endpoint with the custom policy
  2. Comment out or remove the policy parameter from the aws_vpc_endpoint resource and replan
  3. Subsequent terraform plan will not show any diff, even though the policy parameter has been removed from the endpoint. This also has the same result if the aws_iam_policy_document data source is entirely removed from config

Debug Output

No response

Panic Output

No response

Important Factoids

  • Policy can still be modified, Terraform detects the changes to the content of the policy data source and updates the endpoint policy accordingly.

References

No response

Would you like to implement a fix?

No

@mhemani-reach mhemani-reach added the bug Addresses a defect in current functionality. label Jan 16, 2025
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/iam Issues and PRs that pertain to the iam service. service/vpc Issues and PRs that pertain to the vpc service. needs-triage Waiting for first response or review from a maintainer. labels Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Addresses a defect in current functionality. needs-triage Waiting for first response or review from a maintainer. service/iam Issues and PRs that pertain to the iam service. service/vpc Issues and PRs that pertain to the vpc service.
Projects
None yet
Development

No branches or pull requests

1 participant