parent
e3924b1831
commit
2e83eb1cfe
|
@ -14,8 +14,8 @@ import (
|
||||||
|
|
||||||
func resourceAwsOpsworksPermission() *schema.Resource {
|
func resourceAwsOpsworksPermission() *schema.Resource {
|
||||||
return &schema.Resource{
|
return &schema.Resource{
|
||||||
Create: resourceAwsOpsworksPermissionCreate,
|
Create: resourceAwsOpsworksSetPermission,
|
||||||
Update: resourceAwsOpsworksPermissionCreate,
|
Update: resourceAwsOpsworksSetPermission,
|
||||||
Delete: resourceAwsOpsworksPermissionDelete,
|
Delete: resourceAwsOpsworksPermissionDelete,
|
||||||
Read: resourceAwsOpsworksPermissionRead,
|
Read: resourceAwsOpsworksPermissionRead,
|
||||||
|
|
||||||
|
@ -105,10 +105,11 @@ func resourceAwsOpsworksPermissionRead(d *schema.ResourceData, meta interface{})
|
||||||
found = true
|
found = true
|
||||||
d.SetId(id)
|
d.SetId(id)
|
||||||
d.Set("id", id)
|
d.Set("id", id)
|
||||||
d.Set("allow_ssh", permission.AllowSudo)
|
d.Set("allow_ssh", permission.AllowSsh)
|
||||||
d.Set("allow_sodo", permission.AllowSudo)
|
d.Set("allow_sudo", permission.AllowSudo)
|
||||||
d.Set("user_arn", permission.IamUserArn)
|
d.Set("user_arn", permission.IamUserArn)
|
||||||
d.Set("stack_id", permission.StackId)
|
d.Set("stack_id", permission.StackId)
|
||||||
|
d.Set("level", permission.Level)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -121,12 +122,13 @@ func resourceAwsOpsworksPermissionRead(d *schema.ResourceData, meta interface{})
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func resourceAwsOpsworksPermissionCreate(d *schema.ResourceData, meta interface{}) error {
|
func resourceAwsOpsworksSetPermission(d *schema.ResourceData, meta interface{}) error {
|
||||||
client := meta.(*AWSClient).opsworksconn
|
client := meta.(*AWSClient).opsworksconn
|
||||||
|
|
||||||
req := &opsworks.SetPermissionInput{
|
req := &opsworks.SetPermissionInput{
|
||||||
AllowSudo: aws.Bool(d.Get("allow_sudo").(bool)),
|
AllowSudo: aws.Bool(d.Get("allow_sudo").(bool)),
|
||||||
AllowSsh: aws.Bool(d.Get("allow_ssh").(bool)),
|
AllowSsh: aws.Bool(d.Get("allow_ssh").(bool)),
|
||||||
|
Level: aws.String(d.Get("level").(string)),
|
||||||
IamUserArn: aws.String(d.Get("user_arn").(string)),
|
IamUserArn: aws.String(d.Get("user_arn").(string)),
|
||||||
StackId: aws.String(d.Get("stack_id").(string)),
|
StackId: aws.String(d.Get("stack_id").(string)),
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,14 +9,13 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAccAWSOpsworksPermission(t *testing.T) {
|
func TestAccAWSOpsworksPermission(t *testing.T) {
|
||||||
rName := fmt.Sprintf("test-user-%d", acctest.RandInt())
|
sName := fmt.Sprintf("tf-ops-perm-%d", acctest.RandInt())
|
||||||
roleName := fmt.Sprintf("tf-ops-user-profile-%d", acctest.RandInt())
|
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: testAccAwsOpsworksPermissionCreate(rName, roleName),
|
Config: testAccAwsOpsworksPermissionCreate(sName, "true", "true", "iam_only"),
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
"aws_opsworks_permission.tf-acc-perm", "allow_ssh", "true",
|
"aws_opsworks_permission.tf-acc-perm", "allow_ssh", "true",
|
||||||
|
@ -29,19 +28,61 @@ func TestAccAWSOpsworksPermission(t *testing.T) {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
resource.TestStep{
|
||||||
|
Config: testAccAwsOpsworksPermissionCreate(sName, "true", "false", "iam_only"),
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
resource.TestCheckResourceAttr(
|
||||||
|
"aws_opsworks_permission.tf-acc-perm", "allow_ssh", "true",
|
||||||
|
),
|
||||||
|
resource.TestCheckResourceAttr(
|
||||||
|
"aws_opsworks_permission.tf-acc-perm", "allow_sudo", "false",
|
||||||
|
),
|
||||||
|
resource.TestCheckResourceAttr(
|
||||||
|
"aws_opsworks_permission.tf-acc-perm", "level", "iam_only",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
resource.TestStep{
|
||||||
|
Config: testAccAwsOpsworksPermissionCreate(sName, "false", "false", "deny"),
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
resource.TestCheckResourceAttr(
|
||||||
|
"aws_opsworks_permission.tf-acc-perm", "allow_ssh", "false",
|
||||||
|
),
|
||||||
|
resource.TestCheckResourceAttr(
|
||||||
|
"aws_opsworks_permission.tf-acc-perm", "allow_sudo", "false",
|
||||||
|
),
|
||||||
|
resource.TestCheckResourceAttr(
|
||||||
|
"aws_opsworks_permission.tf-acc-perm", "level", "deny",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
resource.TestStep{
|
||||||
|
Config: testAccAwsOpsworksPermissionCreate(sName, "false", "false", "show"),
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
resource.TestCheckResourceAttr(
|
||||||
|
"aws_opsworks_permission.tf-acc-perm", "allow_ssh", "false",
|
||||||
|
),
|
||||||
|
resource.TestCheckResourceAttr(
|
||||||
|
"aws_opsworks_permission.tf-acc-perm", "allow_sudo", "false",
|
||||||
|
),
|
||||||
|
resource.TestCheckResourceAttr(
|
||||||
|
"aws_opsworks_permission.tf-acc-perm", "level", "show",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func testAccAwsOpsworksPermissionCreate(rn, roleName string) string {
|
func testAccAwsOpsworksPermissionCreate(name, ssh, sudo, level string) string {
|
||||||
return fmt.Sprintf(`
|
return fmt.Sprintf(`
|
||||||
resource "aws_opsworks_permission" "tf-acc-perm" {
|
resource "aws_opsworks_permission" "tf-acc-perm" {
|
||||||
stack_id = "${aws_opsworks_stack.tf-acc.id}"
|
stack_id = "${aws_opsworks_stack.tf-acc.id}"
|
||||||
|
|
||||||
allow_ssh = true
|
allow_ssh = %s
|
||||||
allow_sudo = true
|
allow_sudo = %s
|
||||||
user_arn = "${aws_opsworks_user_profile.user.user_arn}"
|
user_arn = "${aws_opsworks_user_profile.user.user_arn}"
|
||||||
level = "iam_only"
|
level = "%s"
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_opsworks_user_profile" "user" {
|
resource "aws_opsworks_user_profile" "user" {
|
||||||
|
@ -55,5 +96,5 @@ resource "aws_iam_user" "user" {
|
||||||
}
|
}
|
||||||
|
|
||||||
%s
|
%s
|
||||||
`, rn, testAccAwsOpsworksStackConfigNoVpcCreate(rn))
|
`, ssh, sudo, level, name, testAccAwsOpsworksStackConfigVpcCreate(name))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue