provider/aws: Allow importing iam_saml_provider (#7605)
This commit is contained in:
parent
1ad0402b29
commit
df40b91fb8
|
@ -0,0 +1,28 @@
|
|||
package aws
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/terraform/helper/resource"
|
||||
)
|
||||
|
||||
func TestAccAWSIAMSamlProvider_importBasic(t *testing.T) {
|
||||
resourceName := "aws_iam_saml_provider.salesforce"
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testAccCheckIAMSamlProviderDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testAccIAMSamlProviderConfig,
|
||||
},
|
||||
|
||||
resource.TestStep{
|
||||
ResourceName: resourceName,
|
||||
ImportState: true,
|
||||
ImportStateVerify: true,
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
|
@ -1,6 +1,8 @@
|
|||
package aws
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"time"
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
|
@ -16,6 +18,10 @@ func resourceAwsIamSamlProvider() *schema.Resource {
|
|||
Update: resourceAwsIamSamlProviderUpdate,
|
||||
Delete: resourceAwsIamSamlProviderDelete,
|
||||
|
||||
Importer: &schema.ResourceImporter{
|
||||
State: schema.ImportStatePassthrough,
|
||||
},
|
||||
|
||||
Schema: map[string]*schema.Schema{
|
||||
"arn": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
|
@ -69,6 +75,11 @@ func resourceAwsIamSamlProviderRead(d *schema.ResourceData, meta interface{}) er
|
|||
|
||||
validUntil := out.ValidUntil.Format(time.RFC1123)
|
||||
d.Set("arn", d.Id())
|
||||
name, err := extractNameFromIAMSamlProviderArn(d.Id())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
d.Set("name", name)
|
||||
d.Set("valid_until", validUntil)
|
||||
d.Set("saml_metadata_document", *out.SAMLMetadataDocument)
|
||||
|
||||
|
@ -100,3 +111,13 @@ func resourceAwsIamSamlProviderDelete(d *schema.ResourceData, meta interface{})
|
|||
|
||||
return err
|
||||
}
|
||||
|
||||
func extractNameFromIAMSamlProviderArn(arn string) (string, error) {
|
||||
// arn:aws:iam::123456789012:saml-provider/tf-salesforce-test
|
||||
r := regexp.MustCompile("^arn:aws:iam::[0-9]{12}:saml-provider/(.+)$")
|
||||
submatches := r.FindStringSubmatch(arn)
|
||||
if len(submatches) != 2 {
|
||||
return "", fmt.Errorf("Unable to extract name from a given ARN: %q", arn)
|
||||
}
|
||||
return submatches[1], nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue