Started the work for the AWS CodeCommit Repository resource

Starting to add the skeleton for the creation and update of a repository
This commit is contained in:
stack72 2015-10-30 21:35:16 +00:00
parent 82ad93539b
commit 89ce6f7c83
4 changed files with 173 additions and 1 deletions

View File

@ -17,6 +17,7 @@ import (
"github.com/aws/aws-sdk-go/service/cloudtrail"
"github.com/aws/aws-sdk-go/service/cloudwatch"
"github.com/aws/aws-sdk-go/service/cloudwatchlogs"
"github.com/aws/aws-sdk-go/service/codecommit"
"github.com/aws/aws-sdk-go/service/codedeploy"
"github.com/aws/aws-sdk-go/service/directoryservice"
"github.com/aws/aws-sdk-go/service/dynamodb"
@ -78,6 +79,7 @@ type AWSClient struct {
opsworksconn *opsworks.OpsWorks
glacierconn *glacier.Glacier
codedeployconn *codedeploy.CodeDeploy
codecommitconn *codecommit.CodeCommit
}
// Client configures and returns a fully initialized AWSClient
@ -213,6 +215,9 @@ func (c *Config) Client() (interface{}, error) {
log.Println("[INFO] Initializing CodeDeploy Connection")
client.codedeployconn = codedeploy.New(sess)
log.Println("[INFO] Initializing CodeCommit SDK connection")
client.codecommitconn = codecommit.New(awsConfig)
}
if len(errs) > 0 {

View File

@ -177,6 +177,7 @@ func Provider() terraform.ResourceProvider {
"aws_cloudwatch_metric_alarm": resourceAwsCloudWatchMetricAlarm(),
"aws_codedeploy_app": resourceAwsCodeDeployApp(),
"aws_codedeploy_deployment_group": resourceAwsCodeDeployDeploymentGroup(),
"aws_codecommit_repository": resourceAwsCodeCommitRepository(),
"aws_customer_gateway": resourceAwsCustomerGateway(),
"aws_db_instance": resourceAwsDbInstance(),
"aws_db_parameter_group": resourceAwsDbParameterGroup(),

View File

@ -0,0 +1,165 @@
package aws
import (
"fmt"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/codecommit"
"github.com/hashicorp/terraform/helper/schema"
)
func resourceAwsCodeCommitRepository() *schema.Resource {
return &schema.Resource{
Create: resourceAwsCodeCommitRepositoryCreate,
Update: resourceAwsCodeCommitRepositoryUpdate,
Read: resourceAwsCodeCommitRepositoryRead,
Delete: resourceAwsCodeCommitRepositoryDelete,
Schema: map[string]*schema.Schema{
"repository_name": &schema.Schema{
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: func(v interface{}, k string) (ws []string, errors []error) {
value := v.(string)
if len(value) > 100 {
errors = append(errors, fmt.Errorf(
"%q cannot be longer than 100 characters", k))
}
return
},
},
"description": &schema.Schema{
Type: schema.TypeString,
Optional: true,
ValidateFunc: func(v interface{}, k string) (ws []string, errors []error) {
value := v.(string)
if len(value) > 1000 {
errors = append(errors, fmt.Errorf(
"%q cannot be longer than 1000 characters", k))
}
return
},
},
"arn": &schema.Schema{
Type: schema.TypeString,
Computed: true,
},
"repository_id": &schema.Schema{
Type: schema.TypeString,
Computed: true,
},
"clone_url_http": &schema.Schema{
Type: schema.TypeString,
Computed: true,
},
"clone_url_ssh": &schema.Schema{
Type: schema.TypeString,
Computed: true,
},
"default_branch": &schema.Schema{
Type: schema.TypeString,
Optional: true,
},
},
}
}
func resourceAwsCodeCommitRepositoryCreate(d *schema.ResourceData, meta interface{}) error {
codecommitconn := meta.(*AWSClient).codecommitconn
input := &codecommit.CreateRepositoryInput{
RepositoryName: aws.String(d.Get("repository_name").(string)),
RepositoryDescription: aws.String(d.Get("description").(string)),
}
out, err := codecommitconn.CreateRepository(input)
if err != nil {
return fmt.Errorf("Error creating CodeCommit Repository: %s", err)
}
d.SetId(d.Get("repository_name").(string))
d.Set("repository_id", *out.RepositoryMetadata.RepositoryId)
d.Set("arn", *out.RepositoryMetadata.Arn)
d.Set("clone_url_http", *out.RepositoryMetadata.CloneUrlHttp)
d.Set("clone_url_ssh", *out.RepositoryMetadata.CloneUrlSsh)
return resourceAwsCodeCommitRepositoryUpdate(d, meta)
}
func resourceAwsCodeCommitRepositoryUpdate(d *schema.ResourceData, meta interface{}) error {
codecommitconn := meta.(*AWSClient).codecommitconn
if d.HasChange("default_branch") {
if err := resourceAwsCodeCommitUpdateDefaultBranch(codecommitconn, d); err != nil {
return err
}
}
if d.HasChange("description") {
if err := resourceAwsCodeCommitUpdateDescription(codecommitconn, d); err != nil {
return err
}
}
return nil
}
func resourceAwsCodeCommitRepositoryRead(d *schema.ResourceData, meta interface{}) error {
codecommitconn := meta.(*AWSClient).codecommitconn
input := &codecommit.GetRepositoryInput{
RepositoryName: aws.String(d.Id()),
}
out, err := codecommitconn.GetRepository(input)
if err != nil {
return fmt.Errorf("Error reading CodeCommit Repository: %s", err.Error())
}
d.Set("repository_id", *out.RepositoryMetadata.RepositoryId)
d.Set("arn", *out.RepositoryMetadata.Arn)
d.Set("clone_url_http", *out.RepositoryMetadata.CloneUrlHttp)
d.Set("clone_url_ssh", *out.RepositoryMetadata.CloneUrlSsh)
d.Set("default_branch", *out.RepositoryMetadata.DefaultBranch)
return nil
}
func resourceAwsCodeCommitRepositoryDelete(d *schema.ResourceData, meta interface{}) error {
return nil
}
func resourceAwsCodeCommitUpdateDescription(codecommitconn *codecommit.CodeCommit, d *schema.ResourceData) error {
branchInput := &codecommit.UpdateRepositoryDescriptionInput{
RepositoryName: aws.String(d.Id()),
RepositoryDescription: aws.String(d.Get("description").(string)),
}
_, err := codecommitconn.UpdateRepositoryDescription(branchInput)
if err != nil {
return fmt.Errorf("Error Updating Repository Description for CodeCommit Repository: %s", err.Error())
}
return nil
}
func resourceAwsCodeCommitUpdateDefaultBranch(codecommitconn *codecommit.CodeCommit, d *schema.ResourceData) error {
branchInput := &codecommit.UpdateDefaultBranchInput{
RepositoryName: aws.String(d.Id()),
DefaultBranchName: aws.String(d.Get("default_branch").(string)),
}
_, err := codecommitconn.UpdateDefaultBranch(branchInput)
if err != nil {
return fmt.Errorf("Error Updating Default Branch for CodeCommit Repository: %s", err.Error())
}
return nil
}

View File

@ -1,8 +1,9 @@
package terraform
import (
"github.com/hashicorp/terraform/config"
"strings"
"github.com/hashicorp/terraform/config"
)
// EvalIgnoreChanges is an EvalNode implementation that removes diff