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

[New Resource]: Opensearch: Authorize VPC endpoint access #33908

Closed
Heldroe opened this issue Oct 12, 2023 · 8 comments · Fixed by #39846
Closed

[New Resource]: Opensearch: Authorize VPC endpoint access #33908

Heldroe opened this issue Oct 12, 2023 · 8 comments · Fixed by #39846
Assignees
Labels
new-resource Introduces a new resource. service/opensearch Issues and PRs that pertain to the opensearch service.
Milestone

Comments

@Heldroe
Copy link

Heldroe commented Oct 12, 2023

Description

When creating a VPC endpoint for an OpenSearch domain (aws_opensearch_vpc_endpoint) from a different account, the other account must first be allowed to create endpoints for the domain (see https://docs.aws.amazon.com/opensearch-service/latest/developerguide/vpc-interface-endpoints.html#vpc-endpoint-access)

Requested Resource(s) and/or Data Source(s)

aws_opensearch_vpc_endpoint_authorized_principal

Potential Terraform Configuration

resource "aws_opensearch_vpc_endpoint_authorized_principal" "other_account" {
  domain_name = "my-domain"
  principal   = "1234567890" # AWS account ID
}

References

Would you like to implement a fix?

No

@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 the service/opensearch Issues and PRs that pertain to the opensearch service. label Oct 12, 2023
@terraform-aws-provider terraform-aws-provider bot added the needs-triage Waiting for first response or review from a maintainer. label Oct 12, 2023
@justinretzolk justinretzolk added new-resource Introduces a new resource. and removed needs-triage Waiting for first response or review from a maintainer. labels Oct 25, 2023
@saqibiqbal7891
Copy link

This functionality has been released in v5.22.0 of the Terraform AWS Provider

Link

@marcohenriques
Copy link

This functionality has been released in v5.22.0 of the Terraform AWS Provider

Link

wasn't that support to create opensearch vpc endpoints? If I understand it correctly, after creating this endpoint, if the endpoint is to an OpenSearch I another account (same region), in that account we need to authorize it. Is there anything like that already implemented? I didn't find it on the docs

@josechudev
Copy link

Hi, is someone currently working on this? I'd like to help

@raffraffraff
Copy link

raffraffraff commented Mar 5, 2024

I hate to "me too" this, but without this resource I have had to resort to some really horrible null_resource crap in my Terraform:

resource "null_resource" "authorized_principals" {
  for_each = var.authorized_principals
  triggers = {
    OS_DOMAIN_ARN    = aws_opensearch_domain.this.arn
    OS_DOMAIN_NAME   = var.domain_name
    OS_AWS_PROFILE   = var.aws_profile
    OS_AWS_REGION    = var.region
    VPC_AWS_ACCOUNT  = each.key
  }

  provisioner "local-exec" {
    interpreter = ["/bin/bash", "-c"]
    command     = "${path.module}/scripts/authorization.sh authorize"
    environment = {
      OS_DOMAIN_ARN    = aws_opensearch_domain.this.arn
      OS_DOMAIN_NAME   = var.domain_name
      OS_AWS_PROFILE   = var.aws_profile
      OS_AWS_REGION    = var.region
      VPC_AWS_ACCOUNT  = each.key
    }
  }

  provisioner "local-exec" {
    when        = destroy
    interpreter = ["/bin/bash", "-c"]
    command     = "${path.module}/scripts/authorization.sh revoke"
    environment = {
      OS_DOMAIN_NAME   = self.triggers.OS_DOMAIN_NAME
      OS_AWS_PROFILE   = self.triggers.OS_AWS_PROFILE
      OS_AWS_REGION    = self.triggers.OS_AWS_REGION
      VPC_AWS_ACCOUNT  = self.triggers.VPC_AWS_ACCOUNT
    }
  }

}

and the shell script it calls:

OSCMD="aws --profile $OS_AWS_PROFILE --region $OS_AWS_REGION opensearch"

die() {
  echo "$1" >&2
  exit 1
}

# THESE WILL ONLY READ STATE
list() {
  $OSCMD list-vpc-endpoint-access \
    --domain-name $OS_DOMAIN_NAME \
    --no-cli-pager
}

auth_status() {
  list \
    | jq -r '.AuthorizedPrincipalList[] | select(.Principal=="'$VPC_AWS_ACCOUNT'") | .Principal' \
    | grep -q $VPC_AWS_ACCOUNT
}

# THESE WILL MAKE MODIFICATIONS
authorize() {
  $OSCMD authorize-vpc-endpoint-access \
    --domain-name $OS_DOMAIN_NAME \
    --account $VPC_AWS_ACCOUNT \
    --no-cli-pager >/dev/null
}

revoke() {
  auth_status || die $? "AWS account not authorized, nothing to do"
  $OSCMD revoke-vpc-endpoint-access \
    --domain-name $OS_DOMAIN_NAME \
    --account $VPC_AWS_ACCOUNT \
    --no-cli-pager >/dev/null
}

until [ -z "$1" ]; do
  case $1 in

    authorize)  auth_status && exit 0
                authorize && exit 0
                die "AWS Account $VPC_AWS_ACCOUNT authorization on OpenSearch domain $OS_DOMAIN_NAME failed"
                ;;

    revoke)     auth_status || exit 0
                revoke && exit 0
                die "AWS Account $VPC_AWS_ACCOUNT revocation on OpenSearch domain $OS_DOMAIN_NAME failed"
                ;;

    status)     auth_status && exit 0
                  die "AWS Account $VPC_AWS_ACCOUNT not authorized on OpenSearch domain $OS_DOMAIN_NAME"
                ;;

    list)       list
                ;;

    *)          die "No action specified"
                ;;
  esac
  shift
done

Awful awful awful. I have basically no golang skills, but this is one of those times where I'm willing to learn it just so I can get this feature in, if nobody else is working on it.

@nsyntych
Copy link

I have started working on it here: https://github.com/punkops/terraform-provider-aws/blob/03b0b0637499f967b37a9947a1b65e7176083e61/internal/service/opensearch/vpc_endpoint_access.go

Not a master in golang myself but seems straight forward.

It works but it needs a lot of polishing, testing and documentation still...

Any suggestions and help is welcome.

@nam054 nam054 self-assigned this Oct 21, 2024
@github-actions github-actions bot added the prioritized Part of the maintainer teams immediate focus. To be addressed within the current quarter. label Oct 21, 2024
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.

@github-actions github-actions bot added this to the v5.74.0 milestone Oct 29, 2024
@github-actions github-actions bot removed the prioritized Part of the maintainer teams immediate focus. To be addressed within the current quarter. label Oct 31, 2024
Copy link

This functionality has been released in v5.74.0 of the Terraform AWS Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new-resource Introduces a new resource. service/opensearch Issues and PRs that pertain to the opensearch service.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants