Reputation: 1697
I've tried variations of the following tf file after reading these docs: https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ecr_repository to import an existing ECR repository.
import {
to = aws_ecr_repository.tamarack_api
id = "arn:aws:ecr:us-west-2:xxxxxxxxxxxx:repository/tamarack-api"
}
resource "aws_ecr_repository" tamarack_api {
name = "tamarack-api"
}
terraform plan
gives me this error:
Error: reading ECR Repository (arn:aws:ecr:us-west-2:xxxxxxxxxxxx:repository/tamarack-api): InvalidParameterException: Invalid parameter at 'repositoryName' failed to satisfy constraint: 'must satisfy regular expression '(?:[a-z0-9]+(?:[.-][a-z0-9]+)/)[a-z0-9]+(?:[.-][a-z0-9]+)*''
I tried that regex in https://regex101.com/ using the Go
language, but it matches the string tamarack-api
. Thanks for any help with this!
Upvotes: 1
Views: 2517
Reputation: 238957
Id is only tamarack-api
, not arn:aws:ecr:us-west-2:xxxxxxxxxxxx:repository/tamarack-api
:
import {
to = aws_ecr_repository.tamarack_api
id = "tamarack-api"
}
Upvotes: 3
Reputation: 11
If a resource reference includes this arn:aws:ecr:us-west-2:xxxxxxxxxxxx:
part then it is actually the ARN not the name. This VPC resource is a good example. The name
of the VPC is like a tag, the ID
is something like vpc-abcdef
and the ARN would look like arn:aws:ecr:us-west-2:xxxxxxxxxxxx:
.
It's helpful to know because some resources will allow you to have duplicate name
s but the ARN is always unique.
Upvotes: 1