provider/aws: Tidy up IAM user acc tests
This commit is contained in:
parent
1a08318a45
commit
e90fa6abd4
|
@ -1,21 +1,25 @@
|
|||
package aws
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/terraform/helper/acctest"
|
||||
"github.com/hashicorp/terraform/helper/resource"
|
||||
)
|
||||
|
||||
func TestAccAWSUser_importBasic(t *testing.T) {
|
||||
resourceName := "aws_iam_user.user"
|
||||
|
||||
n := fmt.Sprintf("test-user-%d", acctest.RandInt())
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testAccCheckAWSUserDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testAccAWSUserConfig,
|
||||
Config: testAccAWSUserConfig(n, "/"),
|
||||
},
|
||||
|
||||
resource.TestStep{
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
"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/helper/acctest"
|
||||
"github.com/hashicorp/terraform/helper/resource"
|
||||
"github.com/hashicorp/terraform/terraform"
|
||||
)
|
||||
|
@ -14,23 +15,28 @@ import (
|
|||
func TestAccAWSUser_basic(t *testing.T) {
|
||||
var conf iam.GetUserOutput
|
||||
|
||||
name1 := fmt.Sprintf("test-user-%d", acctest.RandInt())
|
||||
name2 := fmt.Sprintf("test-user-%d", acctest.RandInt())
|
||||
path1 := "/"
|
||||
path2 := "/path2/"
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testAccCheckAWSUserDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testAccAWSUserConfig,
|
||||
Config: testAccAWSUserConfig(name1, path1),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckAWSUserExists("aws_iam_user.user", &conf),
|
||||
testAccCheckAWSUserAttributes(&conf, "test-user", "/"),
|
||||
testAccCheckAWSUserAttributes(&conf, name1, "/"),
|
||||
),
|
||||
},
|
||||
resource.TestStep{
|
||||
Config: testAccAWSUserConfig2,
|
||||
Config: testAccAWSUserConfig(name2, path2),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckAWSUserExists("aws_iam_user.user", &conf),
|
||||
testAccCheckAWSUserAttributes(&conf, "test-user2", "/path2/"),
|
||||
testAccCheckAWSUserAttributes(&conf, name2, "/path2/"),
|
||||
),
|
||||
},
|
||||
},
|
||||
|
@ -106,15 +112,10 @@ func testAccCheckAWSUserAttributes(user *iam.GetUserOutput, name string, path st
|
|||
}
|
||||
}
|
||||
|
||||
const testAccAWSUserConfig = `
|
||||
func testAccAWSUserConfig(r, p string) string {
|
||||
return fmt.Sprintf(`
|
||||
resource "aws_iam_user" "user" {
|
||||
name = "test-user"
|
||||
path = "/"
|
||||
name = "%s"
|
||||
path = "%s"
|
||||
}`, r, p)
|
||||
}
|
||||
`
|
||||
const testAccAWSUserConfig2 = `
|
||||
resource "aws_iam_user" "user" {
|
||||
name = "test-user2"
|
||||
path = "/path2/"
|
||||
}
|
||||
`
|
||||
|
|
|
@ -29,9 +29,16 @@ func TestAccAWSOpsworksUserProfile(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
var testAccAwsOpsworksUserProfileCreate = testAccAWSUserConfig + testAccAwsOpsworksStackConfigNoVpcCreate("tf-ops-acc-user-profile") + `
|
||||
var testAccAwsOpsworksUserProfileCreate = testAccAWSOpsUserConfig + testAccAwsOpsworksStackConfigNoVpcCreate("tf-ops-acc-user-profile") + `
|
||||
resource "aws_opsworks_user_profile" "user" {
|
||||
user_arn = "${aws_iam_user.user.arn}"
|
||||
ssh_username = "${aws_iam_user.user.name}"
|
||||
}
|
||||
`
|
||||
|
||||
var testAccAWSOpsUserConfig = `
|
||||
resource "aws_iam_user" "user" {
|
||||
name = "test-user"
|
||||
path = "/"
|
||||
}
|
||||
`
|
||||
|
|
Loading…
Reference in New Issue