/
data_source_aws_codecommit_repository.go
79 lines (65 loc) · 2.04 KB
/
data_source_aws_codecommit_repository.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package aws
import (
"fmt"
"log"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/codecommit"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/validation"
)
func dataSourceAwsCodeCommitRepository() *schema.Resource {
return &schema.Resource{
Read: dataSourceAwsCodeCommitRepositoryRead,
Schema: map[string]*schema.Schema{
"repository_name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringLenBetween(0, 100),
},
"arn": {
Type: schema.TypeString,
Computed: true,
},
"repository_id": {
Type: schema.TypeString,
Computed: true,
},
"clone_url_http": {
Type: schema.TypeString,
Computed: true,
},
"clone_url_ssh": {
Type: schema.TypeString,
Computed: true,
},
},
}
}
func dataSourceAwsCodeCommitRepositoryRead(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).codecommitconn
repositoryName := d.Get("repository_name").(string)
input := &codecommit.GetRepositoryInput{
RepositoryName: aws.String(repositoryName),
}
out, err := conn.GetRepository(input)
if err != nil {
if isAWSErr(err, codecommit.ErrCodeRepositoryDoesNotExistException, "") {
log.Printf("[WARN] CodeCommit Repository (%s) not found, removing from state", d.Id())
d.SetId("")
return fmt.Errorf("Resource codecommit repository not found for %s", repositoryName)
} else {
return fmt.Errorf("Error reading CodeCommit Repository: %s", err.Error())
}
}
if out.RepositoryMetadata == nil {
return fmt.Errorf("no matches found for repository name: %s", repositoryName)
}
d.SetId(aws.StringValue(out.RepositoryMetadata.RepositoryName))
d.Set("arn", out.RepositoryMetadata.Arn)
d.Set("clone_url_http", out.RepositoryMetadata.CloneUrlHttp)
d.Set("clone_url_ssh", out.RepositoryMetadata.CloneUrlSsh)
d.Set("repository_name", out.RepositoryMetadata.RepositoryName)
d.Set("repository_id", out.RepositoryMetadata.RepositoryId)
return nil
}