Skip to content

Commit

Permalink
Merge pull request #2871 from hashicorp/b-aws-server-sert-fixes
Browse files Browse the repository at this point in the history
provider/aws: Fix issue with IAM Server Certificates and Chains
  • Loading branch information
catsby committed Jul 29, 2015
2 parents eda2c93 + 8527174 commit 6339e18
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions builtin/providers/aws/resource_aws_iam_server_certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"crypto/sha1"
"encoding/hex"
"fmt"
"log"
"strings"

"github.com/aws/aws-sdk-go/aws"
Expand Down Expand Up @@ -34,8 +35,9 @@ func resourceAwsIAMServerCertificate() *schema.Resource {
},

"path": &schema.Schema{
Type: schema.TypeBool,
Type: schema.TypeString,
Optional: true,
Default: "/",
ForceNew: true,
},

Expand Down Expand Up @@ -74,10 +76,11 @@ func resourceAwsIAMServerCertificateCreate(d *schema.ResourceData, meta interfac
createOpts.CertificateChain = aws.String(v.(string))
}

if v, ok := d.GetOk("Path"); ok {
if v, ok := d.GetOk("path"); ok {
createOpts.Path = aws.String(v.(string))
}

log.Printf("[DEBUG] Creating IAM Server Certificate with opts: %s", createOpts)
resp, err := conn.UploadServerCertificate(createOpts)
if err != nil {
if awsErr, ok := err.(awserr.Error); ok {
Expand Down Expand Up @@ -107,7 +110,12 @@ func resourceAwsIAMServerCertificateRead(d *schema.ResourceData, meta interface{
// these values should always be present, and have a default if not set in
// configuration, and so safe to reference with nil checks
d.Set("certificate_body", normalizeCert(resp.ServerCertificate.CertificateBody))
d.Set("certificate_chain", normalizeCert(resp.ServerCertificate.CertificateChain))

c := normalizeCert(resp.ServerCertificate.CertificateChain)
if c != "" {
d.Set("certificate_chain", c)
}

d.Set("path", resp.ServerCertificate.ServerCertificateMetadata.Path)
d.Set("arn", resp.ServerCertificate.ServerCertificateMetadata.ARN)

Expand All @@ -132,9 +140,10 @@ func resourceAwsIAMServerCertificateDelete(d *schema.ResourceData, meta interfac
}

func normalizeCert(cert interface{}) string {
if cert == nil {
if cert == nil || cert == (*string)(nil) {
return ""
}

switch cert.(type) {
case string:
hash := sha1.Sum([]byte(strings.TrimSpace(cert.(string))))
Expand Down

0 comments on commit 6339e18

Please sign in to comment.