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

CodeArtifact encryption_key argument should be optional+computed #15573

Closed
wants to merge 6 commits into from

Conversation

j3parker
Copy link
Contributor

@j3parker j3parker commented Oct 9, 2020

Community Note

  • Please vote on this pull request by adding a 👍 reaction to the original pull request comment to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for pull request followers and do not help prioritize the request

Release note for CHANGELOG:

resource/aws_codeartifact_domain: Change encryption_key to an optional+computed attribute

Output from acceptance testing:

$ make testacc TESTARGS='-run=TestAccAWSCodeArtifactDomain*'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -count 1 -parallel 20 -run=TestAccAWSCodeArtifactDomain_* -timeout 120m
=== RUN   TestAccAWSCodeArtifactDomainPermissionsPolicy_basic
=== PAUSE TestAccAWSCodeArtifactDomainPermissionsPolicy_basic
=== RUN   TestAccAWSCodeArtifactDomainPermissionsPolicy_owner
=== PAUSE TestAccAWSCodeArtifactDomainPermissionsPolicy_owner
=== RUN   TestAccAWSCodeArtifactDomainPermissionsPolicy_disappears
=== PAUSE TestAccAWSCodeArtifactDomainPermissionsPolicy_disappears
=== RUN   TestAccAWSCodeArtifactDomainPermissionsPolicy_disappears_domain
=== PAUSE TestAccAWSCodeArtifactDomainPermissionsPolicy_disappears_domain
=== RUN   TestAccAWSCodeArtifactDomain_basic
=== PAUSE TestAccAWSCodeArtifactDomain_basic
=== RUN   TestAccAWSCodeArtifactDomain_defaultencryptionkey
=== PAUSE TestAccAWSCodeArtifactDomain_defaultencryptionkey
=== RUN   TestAccAWSCodeArtifactDomain_disappears
=== PAUSE TestAccAWSCodeArtifactDomain_disappears
=== CONT  TestAccAWSCodeArtifactDomainPermissionsPolicy_basic
=== CONT  TestAccAWSCodeArtifactDomainPermissionsPolicy_disappears_domain
=== CONT  TestAccAWSCodeArtifactDomain_basic
=== CONT  TestAccAWSCodeArtifactDomain_disappears
=== CONT  TestAccAWSCodeArtifactDomain_defaultencryptionkey
=== CONT  TestAccAWSCodeArtifactDomainPermissionsPolicy_disappears
=== CONT  TestAccAWSCodeArtifactDomainPermissionsPolicy_owner
2020/10/14 13:48:17 [DEBUG] Waiting for state to become: [success]
=== CONT  TestAccAWSCodeArtifactDomain_defaultencryptionkey
    resource_aws_codeartifact_domain_test.go:104: Step 1/2 error: Error running apply:
        Error: error creating CodeArtifact Domain: InvalidParameter: 1 validation error(s) found.
        - minimum field size of 1, CreateDomainInput.EncryptionKey.



--- FAIL: TestAccAWSCodeArtifactDomain_defaultencryptionkey (32.34s)
--- PASS: TestAccAWSCodeArtifactDomainPermissionsPolicy_disappears (40.24s)
--- PASS: TestAccAWSCodeArtifactDomainPermissionsPolicy_disappears_domain (44.32s)
--- PASS: TestAccAWSCodeArtifactDomain_basic (65.13s)
--- PASS: TestAccAWSCodeArtifactDomainPermissionsPolicy_owner (75.98s)
--- PASS: TestAccAWSCodeArtifactDomain_disappears (81.95s)
--- PASS: TestAccAWSCodeArtifactDomainPermissionsPolicy_basic (100.26s)
FAIL
FAIL    github.com/terraform-providers/terraform-provider-aws/aws       100.306s
FAIL
GNUmakefile:26: recipe for target 'testacc' failed
make: *** [testacc] Error 1

@j3parker j3parker requested a review from a team October 9, 2020 13:34
@ghost ghost added service/codeartifact Issues and PRs that pertain to the codeartifact service. size/XS Managed by automation to categorize the size of a PR. labels Oct 9, 2020
@github-actions github-actions bot added the needs-triage Waiting for first response or review from a maintainer. label Oct 9, 2020
@@ -33,7 +33,7 @@ func resourceAwsCodeArtifactDomain() *schema.Resource {
},
"encryption_key": {
Type: schema.TypeString,
Required: true,
Optional: true,
Copy link
Contributor Author

@j3parker j3parker Oct 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is optional in the SDK and in the API.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @j3parker,
I'll take a closer look but from what I recall the API validates that the kms Id field is not empty even if it's optional. That's why it's required in terraform.

Copy link
Contributor Author

@j3parker j3parker Oct 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's what I get from the CLI:

$ aws configure set cli_history enabled

$ aws codeartifact create-domain --domain test
{
    "domain": {
        "name": "test",
        "owner": "(redacted)",
        "arn": "arn:aws:codeartifact:us-east-1:(redacted):domain/test",
        "status": "Active",
        "createdTime": "2020-10-09T10:33:21.559000-04:00",
        "encryptionKey": "arn:aws:kms:us-east-1:(redacted):key/(redacted)",
        "repositoryCount": 0,
        "assetSizeBytes": 0
    }
}

$ aws history show

AWS CLI command entered
at time: 2020-10-09 10:33:20.776
with AWS CLI version: aws-cli/2.0.49 Python/3.7.7 Windows/10 exe/AMD64
with arguments: ['codeartifact', 'create-domain', '--domain', 'test']

[0] API call made
at time: 2020-10-09 10:33:20.930
to service: codeartifact
using operation: CreateDomain
with parameters: {
    "domain": "test"
}

[0] HTTP request sent
at time: 2020-10-09 10:33:20.936
to URL: https://codeartifact.us-east-1.amazonaws.com/v1/domain?domain=test
with method: POST
with headers: {
    "Authorization": "(redacted)",
    "Content-Length": "0",
    "User-Agent": "aws-cli/2.0.49 Python/3.7.7 Windows/10 exe/AMD64 command/codeartifact.create-domain",
    "X-Amz-Date": "20201009T143320Z",
    "X-Amz-Security-Token": "(redacted)"
}
with body: There is no associated body

[0] HTTP response received
at time: 2020-10-09 10:33:21.466
with status code: 200
with headers: {
    "Connection": "keep-alive",
    "Content-Length": "354",
    "Content-Type": "application/json",
    "Date": "Fri, 09 Oct 2020 14:33:21 GMT",
    "x-amzn-RequestId": "(redacted)"
}
with body: {
    "domain": {
        "arn": "arn:aws:codeartifact:us-east-1:(redacted):domain/test",
        "assetSizeBytes": 0,
        "createdTime": 1602254001.559,
        "encryptionKey": "arn:aws:kms:us-east-1:(redacted):key/(redacted)",
        "name": "test",
        "owner": "(redacted)",
        "repositoryCount": 0,
        "s3BucketArn": "arn:aws:s3:::assets-(redacted)-us-east-1",
        "status": "Active"
    }
}

So it looks like it's truly optional (it's not needed even on the wire). There is an encryptionKey in the response, but that's the (auto-generated on-demand) AWS-managed CMK. There is at most one of those per-account, and typically it's the default if a customer-managed CMK isn't specified (AWS takes care of it completely, and it gets shared between services, they're free etc.)

@DrFaust92
Copy link
Collaborator

DrFaust92 commented Oct 9, 2020 via email

@DrFaust92
Copy link
Collaborator

@j3parker, can you also add computed attribute to kms key id? If none is passed and the API returns a key we need to handle diffs with computed.

Alsop please run acceptance tests.

Thanks again!

@j3parker
Copy link
Contributor Author

j3parker commented Oct 9, 2020

Cool, sure thing!

@DrFaust92 DrFaust92 added enhancement Requests to existing resources that expand the functionality or scope. and removed needs-triage Waiting for first response or review from a maintainer. labels Oct 9, 2020
@j3parker
Copy link
Contributor Author

j3parker commented Oct 14, 2020

done -- attached the logs to the PR description; they passed.

@j3parker j3parker changed the title CodeArtifact encryption_key argument should be optional CodeArtifact encryption_key argument should be optional+computed Oct 14, 2020
@DrFaust92
Copy link
Collaborator

Hey @j3parker,

Can you add an acceptance test for this use case an update docs? Thanks.

@j3parker
Copy link
Contributor Author

Sure thing.

@ghost ghost added size/S Managed by automation to categorize the size of a PR. documentation Introduces or discusses updates to documentation. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. and removed size/XS Managed by automation to categorize the size of a PR. labels Oct 14, 2020
@j3parker
Copy link
Contributor Author

Done.

RE: documentation, I based the new sentence after the one for the kms_master_key_id attribute for S3 buckets.
Here's a screenshot in the UI to show that the key name alias:

image

RE: the test -- it's failing with this error:

=== CONT  TestAccAWSCodeArtifactDomain_defaultencryptionkey
    resource_aws_codeartifact_domain_test.go:104: Step 1/2 error: Error running apply:
        Error: error creating CodeArtifact Domain: InvalidParameter: 1 validation error(s) found.
        - minimum field size of 1, CreateDomainInput.EncryptionKey.

I assume that's what you're talking about with the golang SDK. Should I open an issue in that repo?
Btw -- I was pattern matching with this test case, let me know if it's what you wanted/if there is something more I should be doing.

@j3parker
Copy link
Contributor Author

j3parker commented Oct 14, 2020

Hmmm... I'm not sure. I can make it work directly with the SDK.
I played around with the validation stuff in the provider but couldn't get it to work. I'll dig around more in a bit.

package main                                                                                                                                                                                                     
import (
    "fmt"
    "github.com/aws/aws-sdk-go/aws"
    "github.com/aws/aws-sdk-go/aws/session"
    "github.com/aws/aws-sdk-go/service/codeartifact"
)

func main() {
    sess, err := session.NewSession(&aws.Config{
        Region: aws.String("us-east-1")},
    )

    svc := codeartifact.New(sess)

    domain := "foo"
    res, err := svc.CreateDomain(&codeartifact.CreateDomainInput{
        Domain: &domain,
    })

    if err != nil {
        fmt.Println("Could not create domain", err)
        return
    }

    fmt.Println("stuff", res)
}
$ go run main.go
stuff {
  Domain: {
    Arn: "arn:aws:codeartifact:us-east-1:*****:domain/foo",
    AssetSizeBytes: 0,
    CreatedTime: 2020-10-14 18:46:53.39 +0000 UTC,
    EncryptionKey: "arn:aws:kms:us-east-1:*****:key/*****",
    Name: "foo",
    Owner: "*****",
    RepositoryCount: 0,
    Status: "Active"
  }
}

@j3parker j3parker requested a review from a team as a code owner November 6, 2020 16:29
@j3parker
Copy link
Contributor Author

j3parker commented Nov 6, 2020

Just fixing merge conflicts; hoping to look into this again today or Monday.

Base automatically changed from master to main January 23, 2021 00:59
@ewbankkit
Copy link
Contributor

Replaced by #17262.

@ewbankkit ewbankkit closed this Jan 23, 2021
@j3parker j3parker deleted the patch-1 branch January 25, 2021 15:18
@github-actions github-actions bot added this to the v3.26.0 milestone Jan 28, 2021
@ghost
Copy link

ghost commented Jan 28, 2021

This has been released in version 3.26.0 of the Terraform AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template for triage. Thanks!

@ghost
Copy link

ghost commented Feb 23, 2021

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked as resolved and limited conversation to collaborators Feb 23, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Introduces or discusses updates to documentation. enhancement Requests to existing resources that expand the functionality or scope. service/codeartifact Issues and PRs that pertain to the codeartifact service. size/S Managed by automation to categorize the size of a PR. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants