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

r/aws_codeartifact_domain: fix error with asset_size_bytes size #33220

Merged
merged 5 commits into from
Aug 29, 2023
Merged
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/33220.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_codeartifact_domain: Change the type of asset_size_bytes to `TypeString` instead of `TypeInt` to prevent `value out of range` panic
```
9 changes: 5 additions & 4 deletions internal/service/codeartifact/codeartifact_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ func TestAccCodeArtifact_serial(t *testing.T) {
"owner": testAccAuthorizationTokenDataSource_owner,
},
"Domain": {
"basic": testAccDomain_basic,
"defaultEncryptionKey": testAccDomain_defaultEncryptionKey,
"disappears": testAccDomain_disappears,
"tags": testAccDomain_tags,
"basic": testAccDomain_basic,
"defaultEncryptionKey": testAccDomain_defaultEncryptionKey,
"disappears": testAccDomain_disappears,
"migrateAssetSizeBytesToString": testAccDomain_MigrateAssetSizeBytesToString,
"tags": testAccDomain_tags,
},
"DomainPermissionsPolicy": {
"basic": testAccDomainPermissionsPolicy_basic,
Expand Down
5 changes: 3 additions & 2 deletions internal/service/codeartifact/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package codeartifact
import (
"context"
"log"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -62,7 +63,7 @@ func ResourceDomain() *schema.Resource {
Computed: true,
},
"asset_size_bytes": {
Type: schema.TypeInt,
Type: schema.TypeString,
Computed: true,
},
"repository_count": {
Expand Down Expand Up @@ -131,7 +132,7 @@ func resourceDomainRead(ctx context.Context, d *schema.ResourceData, meta interf
d.Set("arn", arn)
d.Set("encryption_key", sm.Domain.EncryptionKey)
d.Set("owner", sm.Domain.Owner)
d.Set("asset_size_bytes", sm.Domain.AssetSizeBytes)
d.Set("asset_size_bytes", strconv.FormatInt(aws.Int64Value(sm.Domain.AssetSizeBytes), 10))
d.Set("repository_count", sm.Domain.RepositoryCount)
d.Set("created_time", sm.Domain.CreatedTime.Format(time.RFC3339))

Expand Down
33 changes: 33 additions & 0 deletions internal/service/codeartifact/domain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,39 @@ func testAccDomain_disappears(t *testing.T) {
})
}

func testAccDomain_MigrateAssetSizeBytesToString(t *testing.T) {
ctx := acctest.Context(t)
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_codeartifact_domain.test"

resource.Test(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckPartitionHasService(t, codeartifact.EndpointsID) },
ErrorCheck: acctest.ErrorCheck(t, codeartifact.EndpointsID),
CheckDestroy: testAccCheckDomainDestroy(ctx),
Steps: []resource.TestStep{
{
ExternalProviders: map[string]resource.ExternalProvider{
"aws": {
Source: "hashicorp/aws",
VersionConstraint: "5.14.0",
},
},
Config: testAccDomainConfig_basic(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckDomainExists(ctx, resourceName),
resource.TestCheckResourceAttr(resourceName, "domain", rName),
resource.TestCheckResourceAttr(resourceName, "asset_size_bytes", "0"),
),
},
{
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
Config: testAccDomainConfig_basic(rName),
PlanOnly: true,
},
},
})
}

func testAccCheckDomainExists(ctx context.Context, n string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
Expand Down