mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-08 15:13:56 -06:00
3cd125a901
Adds import capability to the `aws_codecommit_repository` resource. Also fixes an issue in the Read function where both `description` and `resource_name` attributes weren't being updated and set in the Schema. Fixes: #13559 ``` $ make testacc TEST=./builtin/providers/aws TESTARGS="-run=TestAccAWSCodeCommitRepository" ==> Checking that code complies with gofmt requirements... go generate $(go list ./... | grep -v /terraform/vendor/) 2017/04/12 10:14:44 Generated command/internal_plugin_list.go TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSCodeCommitRepository -timeout 120m === RUN TestAccAWSCodeCommitRepository_importBasic --- PASS: TestAccAWSCodeCommitRepository_importBasic (16.11s) === RUN TestAccAWSCodeCommitRepository_basic --- PASS: TestAccAWSCodeCommitRepository_basic (14.97s) === RUN TestAccAWSCodeCommitRepository_withChanges --- PASS: TestAccAWSCodeCommitRepository_withChanges (26.71s) === RUN TestAccAWSCodeCommitRepository_create_default_branch --- PASS: TestAccAWSCodeCommitRepository_create_default_branch (14.34s) === RUN TestAccAWSCodeCommitRepository_create_and_update_default_branch --- PASS: TestAccAWSCodeCommitRepository_create_and_update_default_branch (27.90s) PASS ok github.com/hashicorp/terraform/builtin/providers/aws 100.071s ```
189 lines
5.4 KiB
Go
189 lines
5.4 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/codecommit"
|
|
"github.com/hashicorp/terraform/helper/acctest"
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
"github.com/hashicorp/terraform/terraform"
|
|
)
|
|
|
|
func TestAccAWSCodeCommitRepository_basic(t *testing.T) {
|
|
rInt := acctest.RandInt()
|
|
resource.Test(t, resource.TestCase{
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
Providers: testAccProviders,
|
|
CheckDestroy: testAccCheckCodeCommitRepositoryDestroy,
|
|
Steps: []resource.TestStep{
|
|
{
|
|
Config: testAccCodeCommitRepository_basic(rInt),
|
|
Check: resource.ComposeTestCheckFunc(
|
|
testAccCheckCodeCommitRepositoryExists("aws_codecommit_repository.test"),
|
|
),
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
func TestAccAWSCodeCommitRepository_withChanges(t *testing.T) {
|
|
rInt := acctest.RandInt()
|
|
resource.Test(t, resource.TestCase{
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
Providers: testAccProviders,
|
|
CheckDestroy: testAccCheckCodeCommitRepositoryDestroy,
|
|
Steps: []resource.TestStep{
|
|
{
|
|
Config: testAccCodeCommitRepository_basic(rInt),
|
|
Check: resource.ComposeTestCheckFunc(
|
|
testAccCheckCodeCommitRepositoryExists("aws_codecommit_repository.test"),
|
|
resource.TestCheckResourceAttr(
|
|
"aws_codecommit_repository.test", "description", "This is a test description"),
|
|
),
|
|
},
|
|
{
|
|
Config: testAccCodeCommitRepository_withChanges(rInt),
|
|
Check: resource.ComposeTestCheckFunc(
|
|
testAccCheckCodeCommitRepositoryExists("aws_codecommit_repository.test"),
|
|
resource.TestCheckResourceAttr(
|
|
"aws_codecommit_repository.test", "description", "This is a test description - with changes"),
|
|
),
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
func TestAccAWSCodeCommitRepository_create_default_branch(t *testing.T) {
|
|
rInt := acctest.RandInt()
|
|
resource.Test(t, resource.TestCase{
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
Providers: testAccProviders,
|
|
CheckDestroy: testAccCheckCodeCommitRepositoryDestroy,
|
|
Steps: []resource.TestStep{
|
|
{
|
|
Config: testAccCodeCommitRepository_with_default_branch(rInt),
|
|
Check: resource.ComposeTestCheckFunc(
|
|
testAccCheckCodeCommitRepositoryExists("aws_codecommit_repository.test"),
|
|
resource.TestCheckResourceAttr(
|
|
"aws_codecommit_repository.test", "default_branch", "master"),
|
|
),
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
func TestAccAWSCodeCommitRepository_create_and_update_default_branch(t *testing.T) {
|
|
rInt := acctest.RandInt()
|
|
resource.Test(t, resource.TestCase{
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
Providers: testAccProviders,
|
|
CheckDestroy: testAccCheckCodeCommitRepositoryDestroy,
|
|
Steps: []resource.TestStep{
|
|
{
|
|
Config: testAccCodeCommitRepository_basic(rInt),
|
|
Check: resource.ComposeTestCheckFunc(
|
|
testAccCheckCodeCommitRepositoryExists("aws_codecommit_repository.test"),
|
|
resource.TestCheckNoResourceAttr(
|
|
"aws_codecommit_repository.test", "default_branch"),
|
|
),
|
|
},
|
|
{
|
|
Config: testAccCodeCommitRepository_with_default_branch(rInt),
|
|
Check: resource.ComposeTestCheckFunc(
|
|
testAccCheckCodeCommitRepositoryExists("aws_codecommit_repository.test"),
|
|
resource.TestCheckResourceAttr(
|
|
"aws_codecommit_repository.test", "default_branch", "master"),
|
|
),
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
func testAccCheckCodeCommitRepositoryExists(name string) resource.TestCheckFunc {
|
|
return func(s *terraform.State) error {
|
|
rs, ok := s.RootModule().Resources[name]
|
|
if !ok {
|
|
return fmt.Errorf("Not found: %s", name)
|
|
}
|
|
|
|
if rs.Primary.ID == "" {
|
|
return fmt.Errorf("No ID is set")
|
|
}
|
|
|
|
codecommitconn := testAccProvider.Meta().(*AWSClient).codecommitconn
|
|
out, err := codecommitconn.GetRepository(&codecommit.GetRepositoryInput{
|
|
RepositoryName: aws.String(rs.Primary.ID),
|
|
})
|
|
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if out.RepositoryMetadata.Arn == nil {
|
|
return fmt.Errorf("No CodeCommit Repository Vault Found")
|
|
}
|
|
|
|
if *out.RepositoryMetadata.RepositoryName != rs.Primary.ID {
|
|
return fmt.Errorf("CodeCommit Repository Mismatch - existing: %q, state: %q",
|
|
*out.RepositoryMetadata.RepositoryName, rs.Primary.ID)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
}
|
|
|
|
func testAccCheckCodeCommitRepositoryDestroy(s *terraform.State) error {
|
|
conn := testAccProvider.Meta().(*AWSClient).codecommitconn
|
|
|
|
for _, rs := range s.RootModule().Resources {
|
|
if rs.Type != "aws_codecommit_repository" {
|
|
continue
|
|
}
|
|
|
|
_, err := conn.GetRepository(&codecommit.GetRepositoryInput{
|
|
RepositoryName: aws.String(rs.Primary.ID),
|
|
})
|
|
|
|
if ae, ok := err.(awserr.Error); ok && ae.Code() == "RepositoryDoesNotExistException" {
|
|
continue
|
|
}
|
|
if err == nil {
|
|
return fmt.Errorf("Repository still exists: %s", rs.Primary.ID)
|
|
}
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func testAccCodeCommitRepository_basic(rInt int) string {
|
|
return fmt.Sprintf(`
|
|
resource "aws_codecommit_repository" "test" {
|
|
repository_name = "test_repository_%d"
|
|
description = "This is a test description"
|
|
}
|
|
`, rInt)
|
|
}
|
|
|
|
func testAccCodeCommitRepository_withChanges(rInt int) string {
|
|
return fmt.Sprintf(`
|
|
resource "aws_codecommit_repository" "test" {
|
|
repository_name = "test_repository_%d"
|
|
description = "This is a test description - with changes"
|
|
}
|
|
`, rInt)
|
|
}
|
|
|
|
func testAccCodeCommitRepository_with_default_branch(rInt int) string {
|
|
return fmt.Sprintf(`
|
|
resource "aws_codecommit_repository" "test" {
|
|
repository_name = "test_repository_%d"
|
|
description = "This is a test description"
|
|
default_branch = "master"
|
|
}
|
|
`, rInt)
|
|
}
|