-
Notifications
You must be signed in to change notification settings - Fork 9.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue #4785: New Datasource aws_codecommit_repository #4934
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
582c31d
issue #4785 New datasource: aws_codecommit_repository
saravanan30erd 540b68c
add acceptance test
saravanan30erd bb44ef1
add documentation for datasource codecommit repository
saravanan30erd 00ba359
corrections based on feedback
saravanan30erd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
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" | ||
) | ||
|
||
func dataSourceAwsCodeCommitRepository() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceAwsCodeCommitRepositoryRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"repository_name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
ValidateFunc: validateMaxLength(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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
"regexp" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/helper/acctest" | ||
"github.com/hashicorp/terraform/helper/resource" | ||
) | ||
|
||
func TestAccAWSCodeCommitRepositoryDataSource_basic(t *testing.T) { | ||
rName := fmt.Sprintf("tf-acctest-%d", acctest.RandInt()) | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccCheckAwsCodeCommitRepositoryDataSourceConfig(rName), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrPair("data.aws_codecommit_repository.default", "repository_name", | ||
"aws_codecommit_repository.default", "repository_name"), | ||
resource.TestMatchResourceAttr("data.aws_codecommit_repository.default", "arn", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor nitpick: I will update the rest of the checks to |
||
regexp.MustCompile(fmt.Sprintf("^arn:aws:codecommit:[^:]+:\\d{12}:%s", rName))), | ||
resource.TestMatchResourceAttr("data.aws_codecommit_repository.default", "clone_url_http", | ||
regexp.MustCompile(fmt.Sprintf("^https://git-codecommit.[^:]+.amazonaws.com/v1/repos/%s", rName))), | ||
resource.TestMatchResourceAttr("data.aws_codecommit_repository.default", "clone_url_ssh", | ||
regexp.MustCompile(fmt.Sprintf("^ssh://git-codecommit.[^:]+.amazonaws.com/v1/repos/%s", rName))), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccCheckAwsCodeCommitRepositoryDataSourceConfig(rName string) string { | ||
return fmt.Sprintf(` | ||
resource "aws_codecommit_repository" "default" { | ||
repository_name = "%s" | ||
} | ||
|
||
data "aws_codecommit_repository" "default" { | ||
repository_name = "${aws_codecommit_repository.default.repository_name}" | ||
} | ||
`, rName) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
--- | ||
layout: "aws" | ||
page_title: "AWS: aws_codecommit_repository" | ||
sidebar_current: "docs-aws-datasource-codecommit-repository" | ||
description: |- | ||
Provides details about CodeCommit Repository. | ||
--- | ||
|
||
# Data Source: aws_codecommit_repository | ||
|
||
The CodeCommit Repository data source allows the ARN, Repository ID, Repository URL for HTTP and Repository URL for SSH to be retrieved for an CodeCommit repository. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
data "aws_codecommit_repository" "test" { | ||
repository_name = "MyTestRepository" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
* `repository_name` - (Required) The name for the repository. This needs to be less than 100 characters. | ||
|
||
## Attributes Reference | ||
|
||
In addition to all arguments above, the following attributes are exported: | ||
|
||
* `repository_id` - The ID of the repository | ||
* `arn` - The ARN of the repository | ||
* `clone_url_http` - The URL to use for cloning the repository over HTTPS. | ||
* `clone_url_ssh` - The URL to use for cloning the repository over SSH. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To prevent potential panics, we should perform a
nil
check forout.RepositoryMetadata
before referencing it below.