forked from hashicorp/terraform
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/master' into 9869_validate_cre…
…dentials * upstream/master: (79 commits) update CHANGELOG Update panicwrap to pass through all interrupt signals Gracefully stops on SIGTERM website: update website for conditionals vendor: update HIL with conditionals Keep a consistent provider order. Update CHANGELOG.md provider/aws: Forces the api gateway domain name certificates to recreate the resource (hashicorp#10588) Update CHANGELOG.md provider/aws: FIxed the api_gw_domain_name replace operation (hashicorp#10179) Fixed note formatting Explicitly say `count` is not supported by modules (hashicorp#10553) docs/aws: Fix the discrepencies of the emr_cluster documentation (hashicorp#10578) Update CHANGELOG.md Service role is not updated on AWS for a CodeDeploy deployment group (hashicorp#9866) Update CHANGELOG.md provider/datadog hashicorp#9375: Refactor tags to a list instead of a map. (hashicorp#10570) Update the Vagrantfile to resolve package update/installation issue. (hashicorp#9783) docs/aws: Add iam_server_certificate data source to nav bar (hashicorp#10576) Update CHANGELOG.md ...
- Loading branch information
Showing
506 changed files
with
72,300 additions
and
4,883 deletions.
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
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,12 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/hashicorp/terraform/builtin/providers/external" | ||
"github.com/hashicorp/terraform/plugin" | ||
) | ||
|
||
func main() { | ||
plugin.Serve(&plugin.ServeOpts{ | ||
ProviderFunc: external.Provider, | ||
}) | ||
} |
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,15 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/hashicorp/terraform/builtin/providers/rancher" | ||
"github.com/hashicorp/terraform/plugin" | ||
"github.com/hashicorp/terraform/terraform" | ||
) | ||
|
||
func main() { | ||
plugin.Serve(&plugin.ServeOpts{ | ||
ProviderFunc: func() terraform.ResourceProvider { | ||
return rancher.Provider() | ||
}, | ||
}) | ||
} |
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
134 changes: 134 additions & 0 deletions
134
builtin/providers/aws/data_source_aws_iam_server_certificate.go
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,134 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
"sort" | ||
"strings" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/iam" | ||
"github.com/hashicorp/errwrap" | ||
"github.com/hashicorp/terraform/helper/schema" | ||
) | ||
|
||
func dataSourceAwsIAMServerCertificate() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceAwsIAMServerCertificateRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"name": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
ForceNew: true, | ||
ConflictsWith: []string{"name_prefix"}, | ||
ValidateFunc: func(v interface{}, k string) (ws []string, errors []error) { | ||
value := v.(string) | ||
if len(value) > 128 { | ||
errors = append(errors, fmt.Errorf( | ||
"%q cannot be longer than 128 characters", k)) | ||
} | ||
return | ||
}, | ||
}, | ||
|
||
"name_prefix": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Optional: true, | ||
ForceNew: true, | ||
ValidateFunc: func(v interface{}, k string) (ws []string, errors []error) { | ||
value := v.(string) | ||
if len(value) > 30 { | ||
errors = append(errors, fmt.Errorf( | ||
"%q cannot be longer than 30 characters, name is limited to 128", k)) | ||
} | ||
return | ||
}, | ||
}, | ||
|
||
"latest": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Optional: true, | ||
ForceNew: true, | ||
Default: false, | ||
}, | ||
|
||
"arn": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"path": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"expiration_date": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
type certificateByExpiration []*iam.ServerCertificateMetadata | ||
|
||
func (m certificateByExpiration) Len() int { | ||
return len(m) | ||
} | ||
|
||
func (m certificateByExpiration) Swap(i, j int) { | ||
m[i], m[j] = m[j], m[i] | ||
} | ||
|
||
func (m certificateByExpiration) Less(i, j int) bool { | ||
return m[i].Expiration.After(*m[j].Expiration) | ||
} | ||
|
||
func dataSourceAwsIAMServerCertificateRead(d *schema.ResourceData, meta interface{}) error { | ||
iamconn := meta.(*AWSClient).iamconn | ||
|
||
var matcher = func(cert *iam.ServerCertificateMetadata) bool { | ||
return strings.HasPrefix(aws.StringValue(cert.ServerCertificateName), d.Get("name_prefix").(string)) | ||
} | ||
if v, ok := d.GetOk("name"); ok { | ||
matcher = func(cert *iam.ServerCertificateMetadata) bool { | ||
return aws.StringValue(cert.ServerCertificateName) == v.(string) | ||
} | ||
} | ||
|
||
var metadatas = []*iam.ServerCertificateMetadata{} | ||
err := iamconn.ListServerCertificatesPages(&iam.ListServerCertificatesInput{}, func(p *iam.ListServerCertificatesOutput, lastPage bool) bool { | ||
for _, cert := range p.ServerCertificateMetadataList { | ||
if matcher(cert) { | ||
metadatas = append(metadatas, cert) | ||
} | ||
} | ||
return true | ||
}) | ||
if err != nil { | ||
return errwrap.Wrapf("Error describing certificates: {{err}}", err) | ||
} | ||
|
||
if len(metadatas) == 0 { | ||
return fmt.Errorf("Search for AWS IAM server certificate returned no results") | ||
} | ||
if len(metadatas) > 1 { | ||
if !d.Get("latest").(bool) { | ||
return fmt.Errorf("Search for AWS IAM server certificate returned too many results") | ||
} | ||
|
||
sort.Sort(certificateByExpiration(metadatas)) | ||
} | ||
|
||
metadata := metadatas[0] | ||
d.SetId(*metadata.ServerCertificateId) | ||
d.Set("arn", *metadata.Arn) | ||
d.Set("path", *metadata.Path) | ||
d.Set("name", *metadata.ServerCertificateName) | ||
if metadata.Expiration != nil { | ||
d.Set("expiration_date", metadata.Expiration.Format("2006-01-02T15:04:05")) | ||
} | ||
|
||
return nil | ||
} |
63 changes: 63 additions & 0 deletions
63
builtin/providers/aws/data_source_aws_iam_server_certificate_test.go
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,63 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
"sort" | ||
"testing" | ||
"time" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/iam" | ||
"github.com/hashicorp/terraform/helper/resource" | ||
) | ||
|
||
func timePtr(t time.Time) *time.Time { | ||
return &t | ||
} | ||
|
||
func TestResourceSortByExpirationDate(t *testing.T) { | ||
certs := []*iam.ServerCertificateMetadata{ | ||
&iam.ServerCertificateMetadata{ | ||
ServerCertificateName: aws.String("oldest"), | ||
Expiration: timePtr(time.Now()), | ||
}, | ||
&iam.ServerCertificateMetadata{ | ||
ServerCertificateName: aws.String("latest"), | ||
Expiration: timePtr(time.Now().Add(3 * time.Hour)), | ||
}, | ||
&iam.ServerCertificateMetadata{ | ||
ServerCertificateName: aws.String("in between"), | ||
Expiration: timePtr(time.Now().Add(2 * time.Hour)), | ||
}, | ||
} | ||
sort.Sort(certificateByExpiration(certs)) | ||
if *certs[0].ServerCertificateName != "latest" { | ||
t.Fatalf("Expected first item to be %q, but was %q", "latest", *certs[0].ServerCertificateName) | ||
} | ||
} | ||
|
||
func TestAccAWSDataSourceIAMServerCertificate_basic(t *testing.T) { | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckIAMServerCertificateDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccAwsDataIAMServerCertConfig, | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrSet("aws_iam_server_certificate.test_cert", "arn"), | ||
resource.TestCheckResourceAttrSet("data.aws_iam_server_certificate.test", "arn"), | ||
resource.TestCheckResourceAttrSet("data.aws_iam_server_certificate.test", "name"), | ||
resource.TestCheckResourceAttrSet("data.aws_iam_server_certificate.test", "path"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
var testAccAwsDataIAMServerCertConfig = fmt.Sprintf(`%s | ||
data "aws_iam_server_certificate" "test" { | ||
name = "${aws_iam_server_certificate.test_cert.name}" | ||
latest = true | ||
} | ||
`, testAccIAMServerCertConfig) |
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
Oops, something went wrong.