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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

data source aws_vpc_endpoint_service not working as expect in AWS China partition (cn-north-1) #17640

Open
marcincuber opened this issue Feb 16, 2021 · 4 comments
Labels
bug Addresses a defect in current functionality. partition/aws-cn Pertains to the aws-cn partition. service/ec2 Issues and PRs that pertain to the ec2 service. stale Old or inactive issues managed by automation, if no further action taken these will get closed.

Comments

@marcincuber
Copy link

Community Note

  • Please vote on this issue by adding a 馃憤 reaction to the original issue to help the community and maintainers prioritize this request
  • 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
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform CLI and Terraform AWS Provider Version

Terraform v0.14.5
+ provider registry.terraform.io/hashicorp/aws v3.28.0
+ provider registry.terraform.io/hashicorp/random v3.0.1
+ provider registry.terraform.io/hashicorp/tls v3.0.0

Affected Resource(s) + Terraform Configuration Files

data "aws_vpc_endpoint_service" "ecr_dkr" {
  service_type = "Interface"
  service      = "ecr.dkr"
}

Panic Output

Error: error reading VPC Endpoint Service (com.amazonaws.cn-north-1.ecr.dkr): InvalidServiceName: The Vpc Endpoint Service 'com.amazonaws.cn-north-1.ecr.dkr' does not exist
	status code: 400, request id: cad8f3f9-c8bf-466a-97b2-6d9201ba2b43

Expected Behavior

Expected behaviour would be to correctly find service name which in "AWS China partition (cn-north-1)" should be cn.com.amazonaws.cn-north-1.ecr.dkr. Currently, this is not happening and in fact terraform fails at plan stage.

Steps to Reproduce

  1. terraform plan
@ghost ghost added the service/ec2 Issues and PRs that pertain to the ec2 service. label Feb 16, 2021
@github-actions github-actions bot added the needs-triage Waiting for first response or review from a maintainer. label Feb 16, 2021
@marcincuber
Copy link
Author

marcincuber commented Feb 16, 2021

I have managed to solve the problem by using filters:

data "aws_vpc_endpoint_service" "s3" {
  service_type = "Interface"
  filter {
    name   = "service-name"
    values = ["*s3*"]
  }
}

output "aws_vpc_endpoint_service_s3" {
  value = data.aws_vpc_endpoint_service.s3.service_name
}

data "aws_vpc_endpoint_service" "ecr_dkr" {
  service_type = "Interface"
  filter {
    name   = "service-name"
    values = ["*ecr.dkr*"]
  }
}

output "aws_vpc_endpoint_service_ecr_dkr" {
  value = data.aws_vpc_endpoint_service.ecr_dkr.service_name
}

Results:

aws_vpc_endpoint_service_ecr_dkr = "cn.com.amazonaws.cn-north-1.ecr.dkr"
aws_vpc_endpoint_service_s3      = "cn.com.amazonaws.cn-north-1.s3"

@ewbankkit
Copy link
Contributor

@marcincuber Thanks for raising this issue.

Instead of the filter with name = "service-name" you could use the service_name attribute along with the aws_partition and aws_region data source:

data "aws_partition" "current" {}
data "aws_region" "current" {}

data "aws_vpc_endpoint_service" "ecr_dkr" {
  service_type = "Interface"
  service      = "${data.aws_partition.current.reverse_dns_prefix}.${data.aws_region.current.name}.ecr.dkr"
}

although this will only succeed in the cn-north-1 region.

This is the code at fault:

if v, ok := d.GetOk("service_name"); ok {
serviceName = v.(string)
serviceNameOk = true
} else if v, ok := d.GetOk("service"); ok {
serviceName = fmt.Sprintf("com.amazonaws.%s.%s", meta.(*AWSClient).region, v.(string))
serviceNameOk = true
}

It should use the ReverseDns function added in #17142:

// ReverseDns switches a DNS hostname to reverse DNS and vice-versa.
func ReverseDns(hostname string) string {
parts := strings.Split(hostname, ".")
for i, j := 0, len(parts)-1; i < j; i, j = i+1, j-1 {
parts[i], parts[j] = parts[j], parts[i]
}
return strings.Join(parts, ".")
}

@ewbankkit ewbankkit added bug Addresses a defect in current functionality. and removed needs-triage Waiting for first response or review from a maintainer. labels Feb 16, 2021
@marcincuber
Copy link
Author

marcincuber commented Feb 16, 2021

@ewbankkit thanks for your response. I think that using filter until this is fixed is a better option (out of the two) that will work across different AWS partitions.

@maryelizbeth maryelizbeth added the partition/aws-cn Pertains to the aws-cn partition. label May 4, 2022
Copy link

Marking this issue as stale due to inactivity. This helps our maintainers find and focus on the active issues. If this issue receives no comments in the next 30 days it will automatically be closed. Maintainers can also remove the stale label.

If this issue was automatically closed and you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thank you!

@github-actions github-actions bot added the stale Old or inactive issues managed by automation, if no further action taken these will get closed. label Apr 28, 2024
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. partition/aws-cn Pertains to the aws-cn partition. service/ec2 Issues and PRs that pertain to the ec2 service. stale Old or inactive issues managed by automation, if no further action taken these will get closed.
Projects
None yet
Development

No branches or pull requests

3 participants