Skip to content

Commit

Permalink
finished functionality and started adding tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle Robertson authored and alpacamybags118 committed Aug 31, 2021
1 parent 557351e commit 3471e9a
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 7 deletions.
18 changes: 11 additions & 7 deletions aws/data_source_aws_iam_saml_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@ package aws
import (
"fmt"
"log"
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/iam"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)

func dataSourceAwsIAMSamlProvider() *schema.Resource {
return &schema.Resouce{
return &schema.Resource{
Read: dataSourceAwsIAMSamlProviderRead,

Schema: map[string]*schema.Schema{
"arn": {
Type: schema.TypeString,
Required: true,
}
},
"create_date": {
Type: schema.TypeString,
Computed: true,
Expand All @@ -29,7 +29,7 @@ func dataSourceAwsIAMSamlProvider() *schema.Resource {
Computed: true,
},
"valid_until": {
Type: schema.TypeString,
Type: schema.TypeString,
Computed: true,
},
},
Expand All @@ -39,7 +39,7 @@ func dataSourceAwsIAMSamlProvider() *schema.Resource {
func dataSourceAwsIAMSamlProviderRead(d *schema.ResourceData, meta interface{}) error {
iamconn := meta.(*AWSClient).iamconn

arn = d.Get("arn").(string)
arn := d.Get("arn").(string)

req := &iam.GetSAMLProviderInput{
SAMLProviderArn: aws.String(arn),
Expand All @@ -55,9 +55,13 @@ func dataSourceAwsIAMSamlProviderRead(d *schema.ResourceData, meta interface{})
}

d.SetId(*req.SAMLProviderArn)
d.Set("create_date", resp.CreateDate)

validUntil := resp.ValidUntil.Format(time.RFC1123)
dateCreated := resp.CreateDate.Format(time.RFC1123)

d.Set("create_date", dateCreated)
d.Set("saml_metadata_document", resp.SAMLMetadataDocument)
d.Set("valid_until", resp.ValidUntil)
d.Set("valid_until", validUntil)

return nil
}
66 changes: 66 additions & 0 deletions aws/data_source_aws_iam_saml_provider_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package aws

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
)

func TestAccAWSDataSourceSAMLProvider_basic(t *testing.T) {
providerName := acctest.RandomWithPrefix("tf-saml-provider-test")
dataSourceName := "data.aws_iam_saml_provider.test"
resourceName := "aws_iam_saml_provider.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccAwsIAMRoleConfig(roleName),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrPair(dataSourceName, "arn", resourceName, "arn"),
resource.TestCheckResourceAttrPair(dataSourceName, "assume_role_policy", resourceName, "assume_role_policy"),
resource.TestCheckResourceAttrPair(dataSourceName, "create_date", resourceName, "create_date"),
resource.TestCheckResourceAttrPair(dataSourceName, "description", resourceName, "description"),
resource.TestCheckResourceAttrPair(dataSourceName, "max_session_duration", resourceName, "max_session_duration"),
resource.TestCheckResourceAttrPair(dataSourceName, "name", resourceName, "name"),
resource.TestCheckResourceAttrPair(dataSourceName, "path", resourceName, "path"),
resource.TestCheckResourceAttrPair(dataSourceName, "unique_id", resourceName, "unique_id"),
),
},
},
})
}

func testAccAwsIAMRoleConfig(roleName string) string {
return fmt.Sprintf(`
resource "aws_iam_role" "test" {
name = %[1]q
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "ec2.amazonaws.com"
},
"Effect": "Allow",
"Sid": ""
}
]
}
EOF
path = "/testpath/"
}
data "aws_iam_role" "test" {
name = "${aws_iam_role.test.name}"
}
`, roleName)
}

0 comments on commit 3471e9a

Please sign in to comment.