Finishing the last of the CodeCommit Repository resource. Also started to add some tests. The trouble for me right now is that CodeCommit is only in US-East-1 so I need to guard against that right now

This commit is contained in:
stack72 2015-09-18 00:26:25 +01:00
parent 89ce6f7c83
commit d9fd77c141
2 changed files with 91 additions and 2 deletions

View File

@ -2,6 +2,7 @@ package aws
import ( import (
"fmt" "fmt"
"log"
"github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/codecommit" "github.com/aws/aws-sdk-go/service/codecommit"
@ -108,7 +109,7 @@ func resourceAwsCodeCommitRepositoryUpdate(d *schema.ResourceData, meta interfac
} }
} }
return nil return resourceAwsCodeCommitRepositoryRead(d, meta)
} }
func resourceAwsCodeCommitRepositoryRead(d *schema.ResourceData, meta interface{}) error { func resourceAwsCodeCommitRepositoryRead(d *schema.ResourceData, meta interface{}) error {
@ -127,12 +128,24 @@ func resourceAwsCodeCommitRepositoryRead(d *schema.ResourceData, meta interface{
d.Set("arn", *out.RepositoryMetadata.Arn) d.Set("arn", *out.RepositoryMetadata.Arn)
d.Set("clone_url_http", *out.RepositoryMetadata.CloneUrlHttp) d.Set("clone_url_http", *out.RepositoryMetadata.CloneUrlHttp)
d.Set("clone_url_ssh", *out.RepositoryMetadata.CloneUrlSsh) d.Set("clone_url_ssh", *out.RepositoryMetadata.CloneUrlSsh)
d.Set("default_branch", *out.RepositoryMetadata.DefaultBranch) if out.RepositoryMetadata.DefaultBranch != nil {
d.Set("default_branch", *out.RepositoryMetadata.DefaultBranch)
}
return nil return nil
} }
func resourceAwsCodeCommitRepositoryDelete(d *schema.ResourceData, meta interface{}) error { func resourceAwsCodeCommitRepositoryDelete(d *schema.ResourceData, meta interface{}) error {
codecommitconn := meta.(*AWSClient).codecommitconn
log.Printf("[DEBUG] CodeCommit Delete Repository: %s", d.Id())
_, err := codecommitconn.DeleteRepository(&codecommit.DeleteRepositoryInput{
RepositoryName: aws.String(d.Id()),
})
if err != nil {
return fmt.Errorf("Error deleting CodeCommit Repository: %s", err.Error())
}
return nil return nil
} }

View File

@ -0,0 +1,76 @@
package aws
import (
"fmt"
"testing"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/codecommit"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
)
func TestAccAWSCodeCommitRepository_basic(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckCodeCommitRepositoryDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccCodeCommitRepository_basic,
Check: resource.ComposeTestCheckFunc(
testAccCheckCodeCommitRepositoryExists("aws_codecommit_repository.test"),
),
},
},
})
}
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 {
if len(s.RootModule().Resources) > 0 {
return fmt.Errorf("Expected all resources to be gone, but found: %#v",
s.RootModule().Resources)
}
return nil
}
const testAccCodeCommitRepository_basic = `
resource "aws_codecommit_repository" "test" {
repository_name = "my_test_repository"
description = "This is a test description"
}
`