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

Support for AWS Signer service #16383

Merged
merged 2 commits into from
Nov 23, 2020
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
7 changes: 7 additions & 0 deletions .hashibot.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,9 @@ behavior "regexp_issue_labeler_v2" "service_labels" {
"service/shield" = [
"aws_shield_",
],
"service/signer" = [
"aws_signer_",
],
"service/simpledb" = [
"aws_simpledb_",
],
Expand Down Expand Up @@ -1408,6 +1411,10 @@ behavior "pull_request_path_labeler" "service_labels" {
"**/*_shield_*",
"**/shield_*",
],
"service/signer" = [
"**/*_signer_*",
"**/signer_*"
]
"service/simpledb" = [
"aws/internal/service/simpledb/**/*",
"**/*_simpledb_*",
Expand Down
3 changes: 3 additions & 0 deletions aws/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ import (
"github.com/aws/aws-sdk-go/service/ses"
"github.com/aws/aws-sdk-go/service/sfn"
"github.com/aws/aws-sdk-go/service/shield"
"github.com/aws/aws-sdk-go/service/signer"
"github.com/aws/aws-sdk-go/service/simpledb"
"github.com/aws/aws-sdk-go/service/sns"
"github.com/aws/aws-sdk-go/service/sqs"
Expand Down Expand Up @@ -335,6 +336,7 @@ type AWSClient struct {
sesconn *ses.SES
sfnconn *sfn.SFN
shieldconn *shield.Shield
signerconn *signer.Signer
simpledbconn *simpledb.SimpleDB
snsconn *sns.SNS
sqsconn *sqs.SQS
Expand Down Expand Up @@ -564,6 +566,7 @@ func (c *Config) Client() (interface{}, error) {
servicequotasconn: servicequotas.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["servicequotas"])})),
sesconn: ses.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["ses"])})),
sfnconn: sfn.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["stepfunctions"])})),
signerconn: signer.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["signer"])})),
simpledbconn: simpledb.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["sdb"])})),
snsconn: sns.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["sns"])})),
sqsconn: sqs.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["sqs"])})),
Expand Down
224 changes: 224 additions & 0 deletions aws/data_source_aws_signer_signing_job.go
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
}
85 changes: 85 additions & 0 deletions aws/data_source_aws_signer_signing_job_test.go
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) },
Copy link
Contributor

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:

        Error: error creating Signer signing profile: ResourceNotFoundException: Signing platform not found for ID AWSLambda-SHA384-ECDSA
        {
          RespMetadata: {
            StatusCode: 404,
            RequestID: "3fbe82f2-4fc0-4283-9862-d183964eec1a"
          },
          Code_: "PlatformNotFound",
          Message_: "Signing platform not found for ID AWSLambda-SHA384-ECDSA"
        }

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"
Copy link
Contributor

Choose a reason for hiding this comment

The 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)
}
Loading