hashicorp / terraform-provider-aws

The AWS Provider enables Terraform to manage AWS resources.
https://registry.terraform.io/providers/hashicorp/aws
Mozilla Public License 2.0
9.82k stars 9.17k forks source link

[Bug]: Terraform prompt service linked role error if enable custom endpoint #28433

Open Wyifei opened 1 year ago

Wyifei commented 1 year ago

Terraform Core Version

1.3.6

AWS Provider Version

4.47.0

Affected Resource(s)

aws_opensearch_domain aws_iam_service_linked_role

Expected Behavior

The opensearch could be created without error

Actual Behavior

Terraform prompt error

Relevant Error/Panic Output Snippet

No response

Terraform Configuration Files

resource "aws_iam_service_linked_role" "test" {
  aws_service_name = "opensearchservice.amazonaws.com"
}

resource "aws_opensearch_domain" "test" {
  depends_on = [
    aws_iam_service_linked_role.test
  ]
  domain_name    = "${var.projectname}-${var.environment}"
  engine_version = "OpenSearch_1.3"

  cluster_config {
    instance_type          = "t3.medium.search"
    instance_count         = 3
    zone_awareness_enabled = true
    zone_awareness_config {
      availability_zone_count = 3
    }
  }

  advanced_security_options {
    enabled = true
    internal_user_database_enabled = true
    master_user_options {
      master_user_name     = "admin"
      master_user_password = yamldecode(nonsensitive(aws_secretsmanager_secret_version.dashboard_credentials.secret_string)).data
    }
  }

  node_to_node_encryption {
    enabled = true
  }

  domain_endpoint_options {
    custom_endpoint_enabled         = true
    custom_endpoint                 = "logs.${var.region}.${var.testdomain}"
    custom_endpoint_certificate_arn = data.aws_acm_certificate.test_cert.arn
    enforce_https                   = true
    tls_security_policy             = "Policy-Min-TLS-1-2-2019-07"
  }

  encrypt_at_rest {
    enabled = true
  }

  ebs_options {
    ebs_enabled = true
    volume_size = 10
  }

  tags = {
    Name        = "${var.projectname}-${var.environment}"
    Environment = "${var.environment}"
  }

}

resource "aws_opensearch_domain_policy" "test" {
  domain_name = aws_opensearch_domain.test.domain_name

  access_policies = templatefile("${path.module}/policies/access_policy.json", {
    arn = data.aws_opensearch_domain.test.arn
  })
  depends_on = [aws_opensearch_domain.test]
}

resource "aws_route53_record" "test" {
  zone_id = data.aws_route53_zone.test.zone_id
  name    = "logs.${var.region}.${var.testdomain}"
  type    = "CNAME"
  ttl     = 300
  records = ["${aws_opensearch_domain.test.endpoint}"]
}

Steps to Reproduce

  1. Terraform apply then prompt error:

image

  1. If comment customer part as below, terraform apply runs normally

    domain_endpoint_options {
      #custom_endpoint_enabled         = true
      #custom_endpoint                 = "logs.${var.region}.${var.testdomain}"
      #custom_endpoint_certificate_arn = data.aws_acm_certificate.test_cert.arn
      enforce_https                   = true
      tls_security_policy             = "Policy-Min-TLS-1-2-2019-07"
    }

Debug Output

No response

Panic Output

No response

Important Factoids

No response

References

No response

Would you like to implement a fix?

None

github-actions[bot] commented 1 year ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue