opentofu/builtin/providers/aws/resource_aws_ecr_repository_test.go
Paul Stack 3b2c4ee2ed provider/aws: Remove hardcoded https from the ecr repository (#11307)
* provider/aws: Remove hardcoded https from the ecr repository

When the ECR resource was created, we hardcoded the repository URL to
start with https://

This was a mistake as all interaction with the repository now must
include a replace function for the https:// to "" for this to be usable

We need to note this change in the backward incompatibilities

```
% make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAccAWSEcrRepository_'                                                      ✭
==> Checking that code complies with gofmt requirements...
go generate $(go list ./... | grep -v /terraform/vendor/)
2017/01/20 14:37:36 Generated command/internal_plugin_list.go
TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSEcrRepository_ -timeout 120m
=== RUN   TestAccAWSEcrRepository_importBasic
--- PASS: TestAccAWSEcrRepository_importBasic (20.46s)
=== RUN   TestAccAWSEcrRepository_basic
--- PASS: TestAccAWSEcrRepository_basic (18.77s)
PASS
ok  	github.com/hashicorp/terraform/builtin/providers/aws	39.251s
```

* Update ecr_repository.html.markdown
2017-01-20 17:34:52 +00:00

77 lines
1.8 KiB
Go

package aws
import (
"fmt"
"testing"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/ecr"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
)
func TestAccAWSEcrRepository_basic(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSEcrRepositoryDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSEcrRepository,
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSEcrRepositoryExists("aws_ecr_repository.default"),
),
},
},
})
}
func testAccCheckAWSEcrRepositoryDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).ecrconn
for _, rs := range s.RootModule().Resources {
if rs.Type != "aws_ecr_repository" {
continue
}
input := ecr.DescribeRepositoriesInput{
RepositoryNames: []*string{aws.String(rs.Primary.Attributes["name"])},
}
out, err := conn.DescribeRepositories(&input)
if err != nil {
if ecrerr, ok := err.(awserr.Error); ok && ecrerr.Code() == "RepositoryNotFoundException" {
return nil
}
return err
}
for _, repository := range out.Repositories {
if repository.RepositoryName == aws.String(rs.Primary.Attributes["name"]) {
return fmt.Errorf("ECR repository still exists:\n%#v", repository)
}
}
}
return nil
}
func testAccCheckAWSEcrRepositoryExists(name string) resource.TestCheckFunc {
return func(s *terraform.State) error {
_, ok := s.RootModule().Resources[name]
if !ok {
return fmt.Errorf("Not found: %s", name)
}
return nil
}
}
var testAccAWSEcrRepository = `
resource "aws_ecr_repository" "default" {
name = "foo-repository-terraform"
}
`