-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15566 from DrFaust92/d/codeartifact_repository_en…
…dpoint d/codeartifact_repository_endpoint - new data source
- Loading branch information
Showing
4 changed files
with
200 additions
and
0 deletions.
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,74 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/codeartifact" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" | ||
) | ||
|
||
func dataSourceAwsCodeArtifactRepositoryEndpoint() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceAwsCodeArtifactRepositoryEndpointRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"domain": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"repository": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"format": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ValidateFunc: validation.StringInSlice(codeartifact.PackageFormat_Values(), false), | ||
}, | ||
"domain_owner": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
ValidateFunc: validateAwsAccountId, | ||
}, | ||
"repository_endpoint": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceAwsCodeArtifactRepositoryEndpointRead(d *schema.ResourceData, meta interface{}) error { | ||
conn := meta.(*AWSClient).codeartifactconn | ||
domainOwner := meta.(*AWSClient).accountid | ||
domain := d.Get("domain").(string) | ||
repo := d.Get("repository").(string) | ||
format := d.Get("format").(string) | ||
params := &codeartifact.GetRepositoryEndpointInput{ | ||
Domain: aws.String(domain), | ||
Repository: aws.String(repo), | ||
Format: aws.String(format), | ||
} | ||
|
||
if v, ok := d.GetOk("domain_owner"); ok { | ||
params.DomainOwner = aws.String(v.(string)) | ||
domainOwner = v.(string) | ||
} | ||
|
||
log.Printf("[DEBUG] Getting CodeArtifact Repository Endpoint") | ||
out, err := conn.GetRepositoryEndpoint(params) | ||
if err != nil { | ||
return fmt.Errorf("error getting CodeArtifact Repository Endpoint: %w", err) | ||
} | ||
log.Printf("[DEBUG] CodeArtifact Repository Endpoint: %#v", out) | ||
|
||
d.SetId(fmt.Sprintf("%s:%s:%s:%s", domainOwner, domain, repo, format)) | ||
d.Set("repository_endpoint", out.RepositoryEndpoint) | ||
d.Set("domain_owner", domainOwner) | ||
|
||
return nil | ||
} |
89 changes: 89 additions & 0 deletions
89
aws/data_source_aws_codeartifact_repository_endpoint_test.go
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,89 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
func TestAccAWSCodeArtifactRepositoryEndpointDataSource_basic(t *testing.T) { | ||
rName := acctest.RandomWithPrefix("tf-acc-test") | ||
dataSourceName := "data.aws_codeartifact_repository_endpoint.test" | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccCheckAWSCodeArtifactRepositoryEndpointBasicConfig(rName), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrSet(dataSourceName, "repository_endpoint"), | ||
testAccCheckResourceAttrAccountID(dataSourceName, "domain_owner"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestAccAWSCodeArtifactRepositoryEndpointDataSource_owner(t *testing.T) { | ||
rName := acctest.RandomWithPrefix("tf-acc-test") | ||
dataSourceName := "data.aws_codeartifact_repository_endpoint.test" | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccCheckAWSCodeArtifactRepositoryEndpointOwnerConfig(rName), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrSet(dataSourceName, "repository_endpoint"), | ||
testAccCheckResourceAttrAccountID(dataSourceName, "domain_owner"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccCheckAWSCodeArtifactRepositoryEndpointBaseConfig(rName string) string { | ||
return fmt.Sprintf(` | ||
resource "aws_kms_key" "test" { | ||
description = %[1]q | ||
deletion_window_in_days = 7 | ||
} | ||
resource "aws_codeartifact_domain" "test" { | ||
domain = %[1]q | ||
encryption_key = aws_kms_key.test.arn | ||
} | ||
resource "aws_codeartifact_repository" "test" { | ||
repository = %[1]q | ||
domain = aws_codeartifact_domain.test.domain | ||
} | ||
`, rName) | ||
} | ||
|
||
func testAccCheckAWSCodeArtifactRepositoryEndpointBasicConfig(rName string) string { | ||
return testAccCheckAWSCodeArtifactRepositoryEndpointBaseConfig(rName) + | ||
fmt.Sprintf(` | ||
data "aws_codeartifact_repository_endpoint" "test" { | ||
domain = aws_codeartifact_domain.test.domain | ||
repository = aws_codeartifact_repository.test.repository | ||
format = "npm" | ||
} | ||
`) | ||
} | ||
|
||
func testAccCheckAWSCodeArtifactRepositoryEndpointOwnerConfig(rName string) string { | ||
return testAccCheckAWSCodeArtifactRepositoryEndpointBaseConfig(rName) + | ||
fmt.Sprintf(` | ||
data "aws_codeartifact_repository_endpoint" "test" { | ||
domain = aws_codeartifact_domain.test.domain | ||
repository = aws_codeartifact_repository.test.repository | ||
domain_owner = aws_codeartifact_domain.test.owner | ||
format = "npm" | ||
} | ||
`) | ||
} |
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
36 changes: 36 additions & 0 deletions
36
website/docs/d/codeartifact_repository_endpoint.html.markdown
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,36 @@ | ||
--- | ||
subcategory: "CodeArtifact" | ||
layout: "aws" | ||
page_title: "AWS: aws_codeartifact_repository_endpoint" | ||
description: |- | ||
Provides details about a CodeArtifact Repository Endpoint | ||
--- | ||
|
||
# Data Source: aws_codeartifact_repository_endpoint | ||
|
||
The CodeArtifact Repository Endpoint data source returns the endpoint of a repository for a specific package format. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
data "aws_codeartifact_repository_endpoint" "test" { | ||
domain = aws_codeartifact_domain.test.domain | ||
repository = aws_codeartifact_repository.test.repository | ||
format = "npm" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
* `domain` - (Required) The name of the domain that contains the repository. | ||
* `repository` - (Required) The name of the repository. | ||
* `format` - (Required) Which endpoint of a repository to return. A repository has one endpoint for each package format: `npm`, `pypi`, and `maven`. | ||
* `domain_owner` - (Optional) The account number of the AWS account that owns the domain. | ||
|
||
## Attributes Reference | ||
|
||
In addition to the argument above, the following attributes are exported: | ||
|
||
* `repository_endpoint` - The URL of the returned endpoint. |