Merge pull request #7281 from hashicorp/import-aws-ecr
provider/aws: Support import functionality for `aws_ecr_repository`
This commit is contained in:
commit
d39760e620
|
@ -0,0 +1,28 @@
|
||||||
|
package aws
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestAccAWSEcrRepository_importBasic(t *testing.T) {
|
||||||
|
resourceName := "aws_ecr_repository.default"
|
||||||
|
|
||||||
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
Providers: testAccProviders,
|
||||||
|
CheckDestroy: testAccCheckAWSEcrRepositoryDestroy,
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
resource.TestStep{
|
||||||
|
Config: testAccAWSEcrRepository,
|
||||||
|
},
|
||||||
|
|
||||||
|
resource.TestStep{
|
||||||
|
ResourceName: resourceName,
|
||||||
|
ImportState: true,
|
||||||
|
ImportStateVerify: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
|
@ -16,6 +16,9 @@ func resourceAwsEcrRepository() *schema.Resource {
|
||||||
Create: resourceAwsEcrRepositoryCreate,
|
Create: resourceAwsEcrRepositoryCreate,
|
||||||
Read: resourceAwsEcrRepositoryRead,
|
Read: resourceAwsEcrRepositoryRead,
|
||||||
Delete: resourceAwsEcrRepositoryDelete,
|
Delete: resourceAwsEcrRepositoryDelete,
|
||||||
|
Importer: &schema.ResourceImporter{
|
||||||
|
State: schema.ImportStatePassthrough,
|
||||||
|
},
|
||||||
|
|
||||||
Schema: map[string]*schema.Schema{
|
Schema: map[string]*schema.Schema{
|
||||||
"name": &schema.Schema{
|
"name": &schema.Schema{
|
||||||
|
@ -68,7 +71,6 @@ func resourceAwsEcrRepositoryRead(d *schema.ResourceData, meta interface{}) erro
|
||||||
|
|
||||||
log.Printf("[DEBUG] Reading repository %s", d.Id())
|
log.Printf("[DEBUG] Reading repository %s", d.Id())
|
||||||
out, err := conn.DescribeRepositories(&ecr.DescribeRepositoriesInput{
|
out, err := conn.DescribeRepositories(&ecr.DescribeRepositoriesInput{
|
||||||
RegistryId: aws.String(d.Get("registry_id").(string)),
|
|
||||||
RepositoryNames: []*string{aws.String(d.Id())},
|
RepositoryNames: []*string{aws.String(d.Id())},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -86,6 +88,7 @@ func resourceAwsEcrRepositoryRead(d *schema.ResourceData, meta interface{}) erro
|
||||||
d.SetId(*repository.RepositoryName)
|
d.SetId(*repository.RepositoryName)
|
||||||
d.Set("arn", *repository.RepositoryArn)
|
d.Set("arn", *repository.RepositoryArn)
|
||||||
d.Set("registry_id", *repository.RegistryId)
|
d.Set("registry_id", *repository.RegistryId)
|
||||||
|
d.Set("name", repository.RepositoryName)
|
||||||
|
|
||||||
repositoryUrl := buildRepositoryUrl(repository, meta.(*AWSClient).region)
|
repositoryUrl := buildRepositoryUrl(repository, meta.(*AWSClient).region)
|
||||||
log.Printf("[INFO] Setting the repository url to be %s", repositoryUrl)
|
log.Printf("[INFO] Setting the repository url to be %s", repositoryUrl)
|
||||||
|
|
|
@ -36,7 +36,6 @@ func testAccCheckAWSEcrRepositoryDestroy(s *terraform.State) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
input := ecr.DescribeRepositoriesInput{
|
input := ecr.DescribeRepositoriesInput{
|
||||||
RegistryId: aws.String(rs.Primary.Attributes["registry_id"]),
|
|
||||||
RepositoryNames: []*string{aws.String(rs.Primary.Attributes["name"])},
|
RepositoryNames: []*string{aws.String(rs.Primary.Attributes["name"])},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,11 +70,6 @@ func testAccCheckAWSEcrRepositoryExists(name string) resource.TestCheckFunc {
|
||||||
}
|
}
|
||||||
|
|
||||||
var testAccAWSEcrRepository = `
|
var testAccAWSEcrRepository = `
|
||||||
# ECR initially only available in us-east-1
|
|
||||||
# https://aws.amazon.com/blogs/aws/ec2-container-registry-now-generally-available/
|
|
||||||
provider "aws" {
|
|
||||||
region = "us-east-1"
|
|
||||||
}
|
|
||||||
resource "aws_ecr_repository" "default" {
|
resource "aws_ecr_repository" "default" {
|
||||||
name = "foo-repository-terraform"
|
name = "foo-repository-terraform"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue