-
Notifications
You must be signed in to change notification settings - Fork 9.2k
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
Support for AWS Signer service #16383
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,224 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/signer" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
func dataSourceAwsSignerSigningJob() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceAwsSignerSigningJobRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"job_id": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"completed_at": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"created_at": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"job_owner": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"job_invoker": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"platform_display_name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"platform_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"profile_name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"profile_version": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"requested_by": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"revocation_record": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"reason": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"revoked_at": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"revoked_by": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
"signature_expires_at": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"signed_object": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"s3": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"bucket": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"key": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
"source": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"s3": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"bucket": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"key": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"version": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
"status": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"status_reason": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceAwsSignerSigningJobRead(d *schema.ResourceData, meta interface{}) error { | ||
conn := meta.(*AWSClient).signerconn | ||
jobId := d.Get("job_id").(string) | ||
|
||
describeSigningJobOutput, err := conn.DescribeSigningJob(&signer.DescribeSigningJobInput{ | ||
JobId: aws.String(jobId), | ||
}) | ||
|
||
if err != nil { | ||
return fmt.Errorf("error reading Signer signing job (%s): %s", d.Id(), err) | ||
} | ||
|
||
if err := d.Set("completed_at", aws.TimeValue(describeSigningJobOutput.CompletedAt).Format(time.RFC3339)); err != nil { | ||
return fmt.Errorf("error setting signer signing job completed at: %s", err) | ||
} | ||
|
||
if err := d.Set("created_at", aws.TimeValue(describeSigningJobOutput.CreatedAt).Format(time.RFC3339)); err != nil { | ||
return fmt.Errorf("error setting signer signing job created at: %s", err) | ||
} | ||
|
||
if err := d.Set("job_invoker", describeSigningJobOutput.JobInvoker); err != nil { | ||
return fmt.Errorf("error setting signer signing job invoker: %s", err) | ||
} | ||
|
||
if err := d.Set("job_owner", describeSigningJobOutput.JobOwner); err != nil { | ||
return fmt.Errorf("error setting signer signing job owner: %s", err) | ||
} | ||
|
||
if err := d.Set("platform_display_name", describeSigningJobOutput.PlatformDisplayName); err != nil { | ||
return fmt.Errorf("error setting signer signing job platform display name: %s", err) | ||
} | ||
|
||
if err := d.Set("platform_id", describeSigningJobOutput.PlatformId); err != nil { | ||
return fmt.Errorf("error setting signer signing job platform id: %s", err) | ||
} | ||
|
||
if err := d.Set("profile_name", describeSigningJobOutput.ProfileName); err != nil { | ||
return fmt.Errorf("error setting signer signing job profile name: %s", err) | ||
} | ||
|
||
if err := d.Set("profile_version", describeSigningJobOutput.ProfileVersion); err != nil { | ||
return fmt.Errorf("error setting signer signing job profile version: %s", err) | ||
} | ||
|
||
if err := d.Set("requested_by", describeSigningJobOutput.RequestedBy); err != nil { | ||
return fmt.Errorf("error setting signer signing job requested by: %s", err) | ||
} | ||
|
||
if err := d.Set("revocation_record", flattenSignerSigningJobRevocationRecord(describeSigningJobOutput.RevocationRecord)); err != nil { | ||
return fmt.Errorf("error setting signer signing job revocation record: %s", err) | ||
} | ||
|
||
signatureExpiresAt := "" | ||
if describeSigningJobOutput.SignatureExpiresAt != nil { | ||
signatureExpiresAt = aws.TimeValue(describeSigningJobOutput.SignatureExpiresAt).Format(time.RFC3339) | ||
} | ||
if err := d.Set("signature_expires_at", signatureExpiresAt); err != nil { | ||
return fmt.Errorf("error setting signer signing job requested by: %s", err) | ||
} | ||
|
||
if err := d.Set("signed_object", flattenSignerSigningJobSignedObject(describeSigningJobOutput.SignedObject)); err != nil { | ||
return fmt.Errorf("error setting signer signing job signed object: %s", err) | ||
} | ||
|
||
if err := d.Set("source", flattenSignerSigningJobSource(describeSigningJobOutput.Source)); err != nil { | ||
return fmt.Errorf("error setting signer signing job source: %s", err) | ||
} | ||
|
||
if err := d.Set("status", describeSigningJobOutput.Status); err != nil { | ||
return fmt.Errorf("error setting signer signing job status: %s", err) | ||
} | ||
|
||
if err := d.Set("status_reason", describeSigningJobOutput.StatusReason); err != nil { | ||
return fmt.Errorf("error setting signer signing job status reason: %s", err) | ||
} | ||
|
||
d.SetId(aws.StringValue(describeSigningJobOutput.JobId)) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
func TestAccDataSourceAWSSignerSigningJob_basic(t *testing.T) { | ||
rString := acctest.RandString(48) | ||
profileName := fmt.Sprintf("tf_acc_sp_basic_%s", rString) | ||
dataSourceName := "data.aws_signer_signing_job.test" | ||
resourceName := "aws_signer_signing_job.job_test" | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourceAWSSignerSigningJobConfigBasic(profileName), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrPair(dataSourceName, "status", resourceName, "status"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "job_owner", resourceName, "job_owner"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "job_invoker", resourceName, "job_invoker"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "profile_name", resourceName, "profile_name"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDataSourceAWSSignerSigningJobConfigBasic(profileName string) string { | ||
return fmt.Sprintf(` | ||
data "aws_caller_identity" "current" {} | ||
|
||
resource "aws_signer_signing_profile" "test_sp" { | ||
platform_id = "AWSLambda-SHA384-ECDSA" | ||
name = "%s" | ||
} | ||
|
||
resource "aws_s3_bucket" "bucket" { | ||
bucket = "tf-signer-signing-bucket" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Followup note: Randomize naming post-merge |
||
|
||
versioning { | ||
enabled = true | ||
} | ||
|
||
force_destroy = true | ||
} | ||
|
||
resource "aws_s3_bucket" "dest_bucket" { | ||
bucket = "tf-signer-signing-dest-bucket" | ||
force_destroy = true | ||
} | ||
|
||
resource "aws_s3_bucket_object" "lambda_signing_code" { | ||
bucket = aws_s3_bucket.bucket.bucket | ||
key = "lambdatest.zip" | ||
source = "test-fixtures/lambdatest.zip" | ||
} | ||
|
||
resource "aws_signer_signing_job" "job_test" { | ||
profile_name = aws_signer_signing_profile.test_sp.name | ||
|
||
source { | ||
s3 { | ||
bucket = aws_s3_bucket.bucket.bucket | ||
key = aws_s3_bucket_object.lambda_signing_code.key | ||
version = aws_s3_bucket_object.lambda_signing_code.version_id | ||
} | ||
} | ||
|
||
destination { | ||
s3 { | ||
bucket = aws_s3_bucket.dest_bucket.bucket | ||
} | ||
} | ||
} | ||
|
||
data "aws_signer_signing_job" "test" { | ||
job_id = aws_signer_signing_job.job_test.job_id | ||
}`, profileName) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Followup note: Functionality will not be launching in GovCloud (US) immediately, will need to skip testing there for now: