Skip to content

[New Resource]: CodeConnections #38678

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

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/36671.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-resource
aws_codeconnections
```
61 changes: 61 additions & 0 deletions .ci/.semgrep-service-name0.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3533,6 +3533,67 @@ rules:
patterns:
- pattern-regex: "(?i)CodeCommit"
severity: WARNING
- id: codeconnections-in-func-name
languages:
- go
message: Do not use "CodeConnections" in func name inside codeconnections package
paths:
include:
- internal/service/codeconnections
exclude:
- internal/service/codeconnections/list_pages_gen.go
patterns:
- pattern: func $NAME( ... )
- metavariable-pattern:
metavariable: $NAME
patterns:
- pattern-regex: "(?i)CodeConnections"
- focus-metavariable: $NAME
- pattern-not: func $NAME($T *testing.T)
severity: WARNING
- id: codeconnections-in-test-name
languages:
- go
message: Include "CodeConnections" in test name
paths:
include:
- internal/service/codeconnections/*_test.go
patterns:
- pattern: func $NAME( ... )
- metavariable-pattern:
metavariable: $NAME
patterns:
- pattern-not-regex: "^TestAccCodeConnections"
- pattern-regex: ^TestAcc.*
severity: WARNING
- id: codeconnections-in-const-name
languages:
- go
message: Do not use "CodeConnections" in const name inside codeconnections package
paths:
include:
- internal/service/codeconnections
patterns:
- pattern: const $NAME = ...
- metavariable-pattern:
metavariable: $NAME
patterns:
- pattern-regex: "(?i)CodeConnections"
severity: WARNING
- id: codeconnections-in-var-name
languages:
- go
message: Do not use "CodeConnections" in var name inside codeconnections package
paths:
include:
- internal/service/codeconnections
patterns:
- pattern: var $NAME = ...
- metavariable-pattern:
metavariable: $NAME
patterns:
- pattern-regex: "(?i)CodeConnections"
severity: WARNING
- id: codedeploy-in-func-name
languages:
- go
Expand Down
2 changes: 2 additions & 0 deletions .github/labeler-issue-triage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ service/codecatalyst:
- '((\*|-)\s*`?|(data|resource)\s+"?)aws_codecatalyst_'
service/codecommit:
- '((\*|-)\s*`?|(data|resource)\s+"?)aws_codecommit_'
service/codeconnections:
- '((\*|-)\s*`?|(data|resource)\s+"?)aws_codeconnections_'
service/codeguruprofiler:
- '((\*|-)\s*`?|(data|resource)\s+"?)aws_codeguruprofiler_'
service/codegurureviewer:
Expand Down
6 changes: 6 additions & 0 deletions .github/labeler-pr-triage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,12 @@ service/codecommit:
- any-glob-to-any-file:
- 'internal/service/codecommit/**/*'
- 'website/**/codecommit_*'
service/codeconnections:
- any:
- changed-files:
- any-glob-to-any-file:
- 'internal/service/codeconnections/**/*'
- 'website/**/codeconnections_*'
service/codeguruprofiler:
- any:
- changed-files:
Expand Down
1 change: 1 addition & 0 deletions .teamcity/components/generated/services_all.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ val services = mapOf(
"codebuild" to ServiceSpec("CodeBuild"),
"codecatalyst" to ServiceSpec("CodeCatalyst"),
"codecommit" to ServiceSpec("CodeCommit"),
"codeconnections" to ServiceSpec("CodeConnections"),
"codeguruprofiler" to ServiceSpec("CodeGuru Profiler"),
"codegurureviewer" to ServiceSpec("CodeGuru Reviewer"),
"codepipeline" to ServiceSpec("CodePipeline"),
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ require (
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.16 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.1 // indirect
github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.16 // indirect
github.com/aws/aws-sdk-go-v2/service/codeconnections v1.2.4 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.4 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.3.18 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.9.17 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ github.com/aws/aws-sdk-go-v2/service/codecatalyst v1.15.4 h1:MPfnaWtfyb6puC5qrib
github.com/aws/aws-sdk-go-v2/service/codecatalyst v1.15.4/go.mod h1:3FL8cUHMp2BRCb7tXAhAViSYMMfMymFqEoflzpolgXU=
github.com/aws/aws-sdk-go-v2/service/codecommit v1.25.1 h1:mOOALIM4JzhYkq3voCBbmZqmyEVEhHsfasMTbVxLkNs=
github.com/aws/aws-sdk-go-v2/service/codecommit v1.25.1/go.mod h1:6zf5j3mIUXKM0s2iz5ttR2Qwq+o47D0jotpAyaKgZRA=
github.com/aws/aws-sdk-go-v2/service/codeconnections v1.2.4 h1:3lxRcfeG08sKOgpPVegrwZTqiZVhoaCgjQcFIAoVcu4=
github.com/aws/aws-sdk-go-v2/service/codeconnections v1.2.4/go.mod h1:/7jKISx+WnIhDyx1vJ8zsg32OgTD6kniLgKnOvnJnbk=
github.com/aws/aws-sdk-go-v2/service/codedeploy v1.27.4 h1:MVX41GBkdLFuq+oMfVQhLhriP57TFI09VAuSJkwTAcs=
github.com/aws/aws-sdk-go-v2/service/codedeploy v1.27.4/go.mod h1:BaUzjsBCB2ZbLQvH2x5ixq748bz288dedHYgG1Qwac8=
github.com/aws/aws-sdk-go-v2/service/codeguruprofiler v1.22.4 h1:OGN+raxbAM+DAoUbjBSw1wWAzlw6Te6u57xVBBBuYUk=
Expand Down
1 change: 1 addition & 0 deletions infrastructure/repository/labels-service.tf
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ variable "service_labels" {
"codebuild",
"codecatalyst",
"codecommit",
"codeconnections",
"codeguruprofiler",
"codegurureviewer",
"codepipeline",
Expand Down
5 changes: 5 additions & 0 deletions internal/conns/awsclient_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions internal/provider/service_packages_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions internal/service/codeconnections/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Terraform AWS Provider CodeConnections Package

This area is primarily for AWS provider contributors and maintainers. For information on _using_ Terraform and the AWS provider, see the links below.

## Handy Links

* [Find out about contributing](https://hashicorp.github.io/terraform-provider-aws/#contribute) to the AWS provider!
* AWS Provider Docs: [Home](https://registry.terraform.io/providers/hashicorp/aws/latest/docs)
* AWS Provider Docs: [One of the CodeConnections resources](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/codeconnections_connection)
* AWS Docs: [AWS SDK for Go CodeConnections](https://docs.aws.amazon.com/sdk-for-go/api/service/codeconnections/)
183 changes: 183 additions & 0 deletions internal/service/codeconnections/connection.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package codeconnections

import (
"context"
"log"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/codeconnections"
"github.com/aws/aws-sdk-go-v2/service/codeconnections/types"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/enum"
"github.com/hashicorp/terraform-provider-aws/internal/errs"
"github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag"
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
"github.com/hashicorp/terraform-provider-aws/internal/verify"
"github.com/hashicorp/terraform-provider-aws/names"
)

// @SDKResource("aws_codeconnections_connection", name="Connection")
// @Tags(identifierAttribute="arn")
func resourceConnection() *schema.Resource {
return &schema.Resource{
CreateWithoutTimeout: resourceConnectionCreate,
ReadWithoutTimeout: resourceConnectionRead,
UpdateWithoutTimeout: resourceConnectionUpdate,
DeleteWithoutTimeout: resourceConnectionDelete,

Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
},

Schema: map[string]*schema.Schema{
names.AttrARN: {
Type: schema.TypeString,
Computed: true,
},
"connection_status": {
Type: schema.TypeString,
Computed: true,
},
"host_arn": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: verify.ValidARN,
ConflictsWith: []string{"provider_type"},
},
names.AttrName: {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"provider_type": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Computed: true,
ValidateDiagFunc: enum.Validate[types.ProviderType](),
ConflictsWith: []string{"host_arn"},
},
names.AttrTags: tftags.TagsSchema(),
names.AttrTagsAll: tftags.TagsSchemaComputed(),
},

CustomizeDiff: verify.SetTagsDiff,
}
}

func resourceConnectionCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).CodeConnectionsClient(ctx)

name := d.Get(names.AttrName).(string)
input := &codeconnections.CreateConnectionInput{
ConnectionName: aws.String(name),
Tags: getTagsIn(ctx),
}

if v, ok := d.GetOk("host_arn"); ok {
input.HostArn = aws.String(v.(string))
}

if v, ok := d.GetOk("provider_type"); ok {
input.ProviderType = types.ProviderType(v.(string))
}

output, err := conn.CreateConnection(ctx, input)

if err != nil {
return sdkdiag.AppendErrorf(diags, "creating CodeConnections Connection (%s): %s", name, err)
}

d.SetId(aws.ToString(output.ConnectionArn))

return append(diags, resourceConnectionRead(ctx, d, meta)...)
}

func resourceConnectionRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).CodeConnectionsClient(ctx)

connection, err := findConnectionByARN(ctx, conn, d.Id())

if !d.IsNewResource() && tfresource.NotFound(err) {
log.Printf("[WARN] CodeConnections Connection (%s) not found, removing from state", d.Id())
d.SetId("")
return diags
}

if err != nil {
return sdkdiag.AppendErrorf(diags, "reading CodeConnections Connection (%s): %s", d.Id(), err)
}

arn := aws.ToString(connection.ConnectionArn)
d.SetId(arn)
d.Set(names.AttrARN, connection.ConnectionArn)
d.Set("connection_status", connection.ConnectionStatus)
d.Set("host_arn", connection.HostArn)
d.Set(names.AttrName, connection.ConnectionName)
d.Set("provider_type", connection.ProviderType)

return diags
}

func resourceConnectionUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
var diags diag.Diagnostics

// Tags only.

return append(diags, resourceConnectionRead(ctx, d, meta)...)
}

func resourceConnectionDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).CodeConnectionsClient(ctx)

log.Printf("[DEBUG] Deleting CodeConnections Connection: %s", d.Id())
_, err := conn.DeleteConnection(ctx, &codeconnections.DeleteConnectionInput{
ConnectionArn: aws.String(d.Id()),
})

if errs.IsA[*types.ResourceNotFoundException](err) {
return diags
}

if err != nil {
return sdkdiag.AppendErrorf(diags, "deleting CodeConnections Connection (%s): %s", d.Id(), err)
}

return diags
}

func findConnectionByARN(ctx context.Context, conn *codeconnections.Client, arn string) (*types.Connection, error) {
input := &codeconnections.GetConnectionInput{
ConnectionArn: aws.String(arn),
}

output, err := conn.GetConnection(ctx, input)

if errs.IsA[*types.ResourceNotFoundException](err) {
return nil, &retry.NotFoundError{
LastError: err,
LastRequest: input,
}
}

if err != nil {
return nil, err
}

if output == nil || output.Connection == nil {
return nil, tfresource.NewEmptyResultError(input)
}

return output.Connection, nil
}
Loading