diff --git a/.changelog/19284.txt b/.changelog/19284.txt new file mode 100644 index 000000000000..969878abda54 --- /dev/null +++ b/.changelog/19284.txt @@ -0,0 +1,7 @@ +```release-note:enhancement +resource/aws_codestarconnections_connection: Add `host_arn` argument +``` + +```release-note:enhancement +data-source/aws_codestarconnections_connection: Add `host_arn` attribute +``` \ No newline at end of file diff --git a/aws/data_source_aws_codestarconnections_connection.go b/aws/data_source_aws_codestarconnections_connection.go index 5834c74c51fa..1c7a635b8d26 100644 --- a/aws/data_source_aws_codestarconnections_connection.go +++ b/aws/data_source_aws_codestarconnections_connection.go @@ -24,6 +24,11 @@ func dataSourceAwsCodeStarConnectionsConnection() *schema.Resource { Computed: true, }, + "host_arn": { + Type: schema.TypeString, + Computed: true, + }, + "name": { Type: schema.TypeString, Computed: true, @@ -54,6 +59,7 @@ func dataSourceAwsCodeStarConnectionsConnectionRead(d *schema.ResourceData, meta d.SetId(arn) d.Set("connection_status", connection.ConnectionStatus) + d.Set("host_arn", connection.HostArn) d.Set("name", connection.ConnectionName) d.Set("provider_type", connection.ProviderType) diff --git a/aws/resource_aws_codestarconnections_connection.go b/aws/resource_aws_codestarconnections_connection.go index 871414b2307f..7da6658b8be9 100644 --- a/aws/resource_aws_codestarconnections_connection.go +++ b/aws/resource_aws_codestarconnections_connection.go @@ -40,11 +40,21 @@ func resourceAwsCodeStarConnectionsConnection() *schema.Resource { ForceNew: true, }, + "host_arn": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + ConflictsWith: []string{"provider_type"}, + ValidateFunc: validateArn, + }, + "provider_type": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: validation.StringInSlice(codestarconnections.ProviderType_Values(), false), + Type: schema.TypeString, + Optional: true, + ForceNew: true, + Computed: true, + ConflictsWith: []string{"host_arn"}, + ValidateFunc: validation.StringInSlice(codestarconnections.ProviderType_Values(), false), }, "tags": tagsSchema(), @@ -62,7 +72,14 @@ func resourceAwsCodeStarConnectionsConnectionCreate(d *schema.ResourceData, meta params := &codestarconnections.CreateConnectionInput{ ConnectionName: aws.String(d.Get("name").(string)), - ProviderType: aws.String(d.Get("provider_type").(string)), + } + + if v, ok := d.GetOk("provider_type"); ok { + params.ProviderType = aws.String(v.(string)) + } + + if v, ok := d.GetOk("host_arn"); ok { + params.HostArn = aws.String(v.(string)) } if len(tags) > 0 { @@ -103,6 +120,7 @@ func resourceAwsCodeStarConnectionsConnectionRead(d *schema.ResourceData, meta i d.Set("arn", connection.ConnectionArn) d.Set("connection_status", connection.ConnectionStatus) d.Set("name", connection.ConnectionName) + d.Set("host_arn", connection.HostArn) d.Set("provider_type", connection.ProviderType) tags, err := keyvaluetags.CodestarconnectionsListTags(conn, arn) diff --git a/aws/resource_aws_codestarconnections_connection_test.go b/aws/resource_aws_codestarconnections_connection_test.go index 09f93ac269ae..1cf4cc86b1b5 100644 --- a/aws/resource_aws_codestarconnections_connection_test.go +++ b/aws/resource_aws_codestarconnections_connection_test.go @@ -44,6 +44,38 @@ func TestAccAWSCodeStarConnectionsConnection_Basic(t *testing.T) { }) } +func TestAccAWSCodeStarConnectionsConnection_HostArn(t *testing.T) { + var v codestarconnections.Connection + resourceName := "aws_codestarconnections_connection.test" + rName := acctest.RandomWithPrefix("tf-acc-test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t); testAccPartitionHasServicePreCheck(codestarconnections.EndpointsID, t) }, + ErrorCheck: testAccErrorCheck(t, codestarconnections.EndpointsID), + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSCodeStarConnectionsConnectionDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSCodeStarConnectionsConnectionConfigHostArn(rName), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckAWSCodeStarConnectionsConnectionExists(resourceName, &v), + testAccMatchResourceAttrRegionalARN(resourceName, "id", "codestar-connections", regexp.MustCompile("connection/.+")), + testAccMatchResourceAttrRegionalARN(resourceName, "arn", "codestar-connections", regexp.MustCompile("connection/.+")), + testAccMatchResourceAttrRegionalARN(resourceName, "host_arn", "codestar-connections", regexp.MustCompile("host/.+")), + resource.TestCheckResourceAttr(resourceName, "provider_type", codestarconnections.ProviderTypeGitHubEnterpriseServer), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttr(resourceName, "connection_status", codestarconnections.ConnectionStatusPending), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + func TestAccAWSCodeStarConnectionsConnection_disappears(t *testing.T) { var v codestarconnections.Connection resourceName := "aws_codestarconnections_connection.test" @@ -166,6 +198,21 @@ resource "aws_codestarconnections_connection" "test" { `, rName) } +func testAccAWSCodeStarConnectionsConnectionConfigHostArn(rName string) string { + return fmt.Sprintf(` +resource "aws_codestarconnections_host" "test" { + name = %[1]q + provider_endpoint = "https://test.com" + provider_type = "GitHubEnterpriseServer" +} + +resource "aws_codestarconnections_connection" "test" { + name = %[1]q + host_arn = aws_codestarconnections_host.test.arn +} +`, rName) +} + func testAccAWSCodeStarConnectionsConnectionConfigTags1(rName string, tagKey1 string, tagValue1 string) string { return fmt.Sprintf(` resource "aws_codestarconnections_connection" "test" { diff --git a/website/docs/d/codestarconnections_connection.html.markdown b/website/docs/d/codestarconnections_connection.html.markdown index acfc225d04b5..dcdfd76a6216 100644 --- a/website/docs/d/codestarconnections_connection.html.markdown +++ b/website/docs/d/codestarconnections_connection.html.markdown @@ -30,6 +30,7 @@ In addition to all arguments above, the following attributes are exported: * `connection_status` - The CodeStar Connection status. Possible values are `PENDING`, `AVAILABLE` and `ERROR`. * `id` - The CodeStar Connection ARN. +* `host_arn` - The Amazon Resource Name (ARN) of the host associated with the connection. * `name` - The name of the CodeStar Connection. The name is unique in the calling AWS account. * `provider_type` - The name of the external provider where your third-party code repository is configured. Possible values are `Bitbucket`, `GitHub`, or `GitHubEnterpriseServer`. * `tags` - Map of key-value resource tags to associate with the resource. diff --git a/website/docs/r/codestarconnections_connection.markdown b/website/docs/r/codestarconnections_connection.markdown index a122eb92eda3..a7763e475bf5 100644 --- a/website/docs/r/codestarconnections_connection.markdown +++ b/website/docs/r/codestarconnections_connection.markdown @@ -66,7 +66,8 @@ resource "aws_codepipeline" "example" { The following arguments are supported: * `name` - (Required) The name of the connection to be created. The name must be unique in the calling AWS account. Changing `name` will create a new resource. -* `provider_type` - (Required) The name of the external provider where your third-party code repository is configured. Valid values are `Bitbucket`, `GitHub`, or `GitHubEnterpriseServer`. Changing `provider_type` will create a new resource. +* `provider_type` - (Optional) The name of the external provider where your third-party code repository is configured. Valid values are `Bitbucket`, `GitHub` or `GitHubEnterpriseServer`. Changing `provider_type` will create a new resource. Conflicts with `host_arn` +* `host_arn` - (Optional) The Amazon Resource Name (ARN) of the host associated with the connection. Conflicts with `provider_type` * `tags` - (Optional) Map of key-value resource tags to associate with the resource. If configured with a provider [`default_tags` configuration block](/docs/providers/aws/index.html#default_tags-configuration-block) present, tags with matching keys will overwrite those defined at the provider-level. ## Attributes Reference