Skip to content
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

Add support for optional KMS key ID in repository resource #35095

Merged
merged 22 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
54c82a3
Add support for optional KMS key ID in repository resource
obounaim Dec 29, 2023
b287141
Remove ForceNew option for kms_key_id
obounaim Dec 29, 2023
ad6d4fc
Add "kms_key_id" field to repository data source
obounaim Dec 29, 2023
01a648c
Add changelog entry
obounaim Dec 29, 2023
93c75ca
Update documentation
obounaim Dec 29, 2023
fd0015b
Add Computed field for kms_key_id
obounaim Dec 29, 2023
89e1a94
Merge branch 'main' into HEAD
ewbankkit Jan 19, 2024
c09cf72
codecommit: Use AWS SDK for Go v2.
ewbankkit Jan 19, 2024
df8ae2b
Run 'make gen'.
ewbankkit Jan 19, 2024
78405b0
Run 'go get github.com/aws/aws-sdk-go-v2/service/[email protected] &…
ewbankkit Jan 19, 2024
9a18cfc
codecommit: Fix tagging code generation.
ewbankkit Jan 19, 2024
7cce7f1
r/aws_codecommit_approval_rule_template: Migrate to AWS SDK for Go v2.
ewbankkit Jan 19, 2024
f02d3b4
d/aws_codecommit_approval_rule_template: Migrate to AWS SDK for Go v2.
ewbankkit Jan 21, 2024
266cc9e
r/aws_codecommit_approval_rule_template_association: Migrate to AWS S…
ewbankkit Jan 21, 2024
962947c
r/aws_codecommit_trigger: Migrate to AWS SDK for Go v2.
ewbankkit Jan 21, 2024
f3b8d3a
r/aws_codecommit_repository: Migrate to AWS SDK for Go v2.
ewbankkit Jan 21, 2024
3a47e42
d/aws_codecommit_repository: Migrate to AWS SDK for Go v2.
ewbankkit Jan 21, 2024
11c9ec8
Add 'names.CodeCommitEndpointID'.
ewbankkit Jan 21, 2024
e4e899c
codecommit: Migrate acceptance tests to AWS SDK for Go v2.
ewbankkit Jan 22, 2024
db96a50
Add 'TestAccCodeCommitRepository_kmsKey'.
ewbankkit Jan 22, 2024
c9b758c
Acceptance test output:
ewbankkit Jan 22, 2024
05d982c
r/aws_codecommit_trigger: Fix 'RepositoryTriggerBranchNameListRequire…
ewbankkit Jan 22, 2024
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
11 changes: 11 additions & 0 deletions .changelog/35095.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
```release-note:enhancement
resource/aws_codecommit_repository: Add `kms_key_id` argument
```

```release-note:enhancement
data-source/aws_codecommit_repository: Add `kms_key_id` attribute
```

```release-note:enhancement
resource/aws_codecommit_trigger: Add plan-time validation of `trigger.destination_arn` and `trigger.events`
```
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ require (
github.com/aws/aws-sdk-go-v2/service/cloudcontrol v1.15.7
github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs v1.31.0
github.com/aws/aws-sdk-go-v2/service/codecatalyst v1.10.6
github.com/aws/aws-sdk-go-v2/service/codecommit v1.20.1
github.com/aws/aws-sdk-go-v2/service/codedeploy v1.22.3
github.com/aws/aws-sdk-go-v2/service/codeguruprofiler v1.18.6
github.com/aws/aws-sdk-go-v2/service/codepipeline v1.22.6
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs v1.31.0 h1:Rk+Ft0Mu/eiNt2iJ2
github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs v1.31.0/go.mod h1:jZNaJEtn9TLi3pfxycLz79HVkKxP8ZdYm92iaNFgBsA=
github.com/aws/aws-sdk-go-v2/service/codecatalyst v1.10.6 h1:WLVD5wFI3yC1u/8L9bNeZ9+VURSdKjGA1Q+n+F1355Y=
github.com/aws/aws-sdk-go-v2/service/codecatalyst v1.10.6/go.mod h1:/lHwoB/rkF3eWMJPvm9wXN7y1THwqCLCOrF7xzA2u9E=
github.com/aws/aws-sdk-go-v2/service/codecommit v1.20.1 h1:FJx0hebVW2EfD5eJjRSkQdWsqFTvZSCSitnMHcOxxko=
github.com/aws/aws-sdk-go-v2/service/codecommit v1.20.1/go.mod h1:aNVj38vn3H6ZZTF+I7As5p9ZIOdB5Jhc1TlNLm9E5FA=
github.com/aws/aws-sdk-go-v2/service/codedeploy v1.22.3 h1:KUQmoqL05L+fftMgWLVlk15TL005gxC6NTzU5UiW03E=
github.com/aws/aws-sdk-go-v2/service/codedeploy v1.22.3/go.mod h1:NqMyFU67rmETeGllV83ilhMC7r+7KnjeEvux4PYakPk=
github.com/aws/aws-sdk-go-v2/service/codeguruprofiler v1.18.6 h1:x5j98Y39PwTePUmTdY5XG7OX9+76sKnA9D88xeCtXcc=
Expand Down
6 changes: 3 additions & 3 deletions internal/conns/awsclient_gen.go

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

108 changes: 63 additions & 45 deletions internal/service/codecommit/approval_rule_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,37 @@ import (
"log"
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/codecommit"
"github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/codecommit"
"github.com/aws/aws-sdk-go-v2/service/codecommit/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-plugin-sdk/v2/helper/structure"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/errs"
"github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag"
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
"github.com/hashicorp/terraform-provider-aws/internal/verify"
)

// @SDKResource("aws_codecommit_approval_rule_template")
func ResourceApprovalRuleTemplate() *schema.Resource {
// @SDKResource("aws_codecommit_approval_rule_template", name="Approval Rule Template")
func resourceApprovalRuleTemplate() *schema.Resource {
return &schema.Resource{
CreateWithoutTimeout: resourceApprovalRuleTemplateCreate,
ReadWithoutTimeout: resourceApprovalRuleTemplateRead,
UpdateWithoutTimeout: resourceApprovalRuleTemplateUpdate,
DeleteWithoutTimeout: resourceApprovalRuleTemplateDelete,

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

Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringLenBetween(1, 100),
"approval_rule_template_id": {
Type: schema.TypeString,
Computed: true,
},
"content": {
Type: schema.TypeString,
Expand All @@ -50,19 +53,15 @@ func ResourceApprovalRuleTemplate() *schema.Resource {
validation.StringLenBetween(1, 3000),
),
},
"creation_date": {
Type: schema.TypeString,
Computed: true,
},
"description": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringLenBetween(0, 1000),
},
"approval_rule_template_id": {
Type: schema.TypeString,
Computed: true,
},
"creation_date": {
Type: schema.TypeString,
Computed: true,
},
"last_modified_date": {
Type: schema.TypeString,
Computed: true,
Expand All @@ -71,6 +70,11 @@ func ResourceApprovalRuleTemplate() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"name": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringLenBetween(1, 100),
},
"rule_content_sha256": {
Type: schema.TypeString,
Computed: true,
Expand All @@ -81,10 +85,9 @@ func ResourceApprovalRuleTemplate() *schema.Resource {

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

name := d.Get("name").(string)

input := &codecommit.CreateApprovalRuleTemplateInput{
ApprovalRuleTemplateName: aws.String(name),
ApprovalRuleTemplateContent: aws.String(d.Get("content").(string)),
Expand All @@ -94,7 +97,8 @@ func resourceApprovalRuleTemplateCreate(ctx context.Context, d *schema.ResourceD
input.ApprovalRuleTemplateDescription = aws.String(v.(string))
}

_, err := conn.CreateApprovalRuleTemplateWithContext(ctx, input)
_, err := conn.CreateApprovalRuleTemplate(ctx, input)

if err != nil {
return sdkdiag.AppendErrorf(diags, "creating CodeCommit Approval Rule Template (%s): %s", name, err)
}
Expand All @@ -106,16 +110,12 @@ func resourceApprovalRuleTemplateCreate(ctx context.Context, d *schema.ResourceD

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

input := &codecommit.GetApprovalRuleTemplateInput{
ApprovalRuleTemplateName: aws.String(d.Id()),
}
result, err := findApprovalRuleTemplateByName(ctx, conn, d.Id())

resp, err := conn.GetApprovalRuleTemplateWithContext(ctx, input)

if !d.IsNewResource() && tfawserr.ErrCodeEquals(err, codecommit.ErrCodeApprovalRuleTemplateDoesNotExistException) {
log.Printf("[WARN] CodeCommit Approval Rule Template (%s) not found, removing from state", d.Id())
if !d.IsNewResource() && tfresource.NotFound(err) {
log.Printf("[WARN] CodeCommit Approval Rule Template %s not found, removing from state", d.Id())
d.SetId("")
return diags
}
Expand All @@ -124,35 +124,29 @@ func resourceApprovalRuleTemplateRead(ctx context.Context, d *schema.ResourceDat
return sdkdiag.AppendErrorf(diags, "reading CodeCommit Approval Rule Template (%s): %s", d.Id(), err)
}

if resp == nil || resp.ApprovalRuleTemplate == nil {
return sdkdiag.AppendErrorf(diags, "reading CodeCommit Approval Rule Template (%s): empty output", d.Id())
}

result := resp.ApprovalRuleTemplate

d.Set("name", result.ApprovalRuleTemplateName)
d.Set("approval_rule_template_id", result.ApprovalRuleTemplateId)
d.Set("description", result.ApprovalRuleTemplateDescription)
d.Set("content", result.ApprovalRuleTemplateContent)
d.Set("creation_date", result.CreationDate.Format(time.RFC3339))
d.Set("last_modified_date", result.LastModifiedDate.Format(time.RFC3339))
d.Set("last_modified_user", result.LastModifiedUser)
d.Set("name", result.ApprovalRuleTemplateName)
d.Set("rule_content_sha256", result.RuleContentSha256)

return diags
}

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

if d.HasChange("description") {
input := &codecommit.UpdateApprovalRuleTemplateDescriptionInput{
ApprovalRuleTemplateDescription: aws.String(d.Get("description").(string)),
ApprovalRuleTemplateName: aws.String(d.Id()),
}

_, err := conn.UpdateApprovalRuleTemplateDescriptionWithContext(ctx, input)
_, err := conn.UpdateApprovalRuleTemplateDescription(ctx, input)

if err != nil {
return sdkdiag.AppendErrorf(diags, "updating CodeCommit Approval Rule Template (%s) description: %s", d.Id(), err)
Expand All @@ -166,7 +160,7 @@ func resourceApprovalRuleTemplateUpdate(ctx context.Context, d *schema.ResourceD
NewRuleContent: aws.String(d.Get("content").(string)),
}

_, err := conn.UpdateApprovalRuleTemplateContentWithContext(ctx, input)
_, err := conn.UpdateApprovalRuleTemplateContent(ctx, input)

if err != nil {
return sdkdiag.AppendErrorf(diags, "updating CodeCommit Approval Rule Template (%s) content: %s", d.Id(), err)
Expand All @@ -181,7 +175,7 @@ func resourceApprovalRuleTemplateUpdate(ctx context.Context, d *schema.ResourceD
OldApprovalRuleTemplateName: aws.String(d.Id()),
}

_, err := conn.UpdateApprovalRuleTemplateNameWithContext(ctx, input)
_, err := conn.UpdateApprovalRuleTemplateName(ctx, input)

if err != nil {
return sdkdiag.AppendErrorf(diags, "updating CodeCommit Approval Rule Template (%s) name: %s", d.Id(), err)
Expand All @@ -195,15 +189,14 @@ func resourceApprovalRuleTemplateUpdate(ctx context.Context, d *schema.ResourceD

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

input := &codecommit.DeleteApprovalRuleTemplateInput{
log.Printf("[INFO] Deleting CodeCommit Approval Rule Template: %s", d.Id())
_, err := conn.DeleteApprovalRuleTemplate(ctx, &codecommit.DeleteApprovalRuleTemplateInput{
ApprovalRuleTemplateName: aws.String(d.Id()),
}

_, err := conn.DeleteApprovalRuleTemplateWithContext(ctx, input)
})

if tfawserr.ErrCodeEquals(err, codecommit.ErrCodeApprovalRuleTemplateDoesNotExistException) {
if errs.IsA[*types.ApprovalRuleTemplateDoesNotExistException](err) {
return diags
}

Expand All @@ -213,3 +206,28 @@ func resourceApprovalRuleTemplateDelete(ctx context.Context, d *schema.ResourceD

return diags
}

func findApprovalRuleTemplateByName(ctx context.Context, conn *codecommit.Client, name string) (*types.ApprovalRuleTemplate, error) {
input := &codecommit.GetApprovalRuleTemplateInput{
ApprovalRuleTemplateName: aws.String(name),
}

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

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

if err != nil {
return nil, err
}

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

return output.ApprovalRuleTemplate, nil
}
Loading
Loading