-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6935 from kterada0509/feature/add-force-destroy-s…
…upport-for-transfer-server Add force destroy support for Transfer Server
- Loading branch information
Showing
3 changed files
with
174 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ import ( | |
"testing" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/iam" | ||
"github.com/aws/aws-sdk-go/service/transfer" | ||
|
||
"github.com/hashicorp/terraform/helper/acctest" | ||
|
@@ -36,9 +37,10 @@ func TestAccAWSTransferServer_basic(t *testing.T) { | |
), | ||
}, | ||
{ | ||
ResourceName: "aws_transfer_server.foo", | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
ResourceName: "aws_transfer_server.foo", | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
ImportStateVerifyIgnore: []string{"force_destroy"}, | ||
}, | ||
{ | ||
Config: testAccAWSTransferServerConfig_basicUpdate(rName), | ||
|
@@ -108,6 +110,40 @@ func TestAccAWSTransferServer_disappears(t *testing.T) { | |
}) | ||
} | ||
|
||
func TestAccAWSTransferServer_forcedestroy(t *testing.T) { | ||
var conf transfer.DescribedServer | ||
var roleConf iam.GetRoleOutput | ||
rName := acctest.RandString(5) | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
IDRefreshName: "aws_transfer_server.foo", | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckAWSTransferServerDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccAWSTransferServerConfig_forcedestroy(rName), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckAWSTransferServerExists("aws_transfer_server.foo", &conf), | ||
testAccCheckAWSRoleExists("aws_iam_role.foo", &roleConf), | ||
resource.TestCheckResourceAttr( | ||
"aws_transfer_server.foo", "identity_provider_type", "SERVICE_MANAGED"), | ||
resource.TestCheckResourceAttr( | ||
"aws_transfer_server.foo", "force_destroy", "true"), | ||
testAccCheckAWSTransferCreateUser(&conf, &roleConf, rName), | ||
testAccCheckAWSTransferCreateSshKey(&conf, rName), | ||
), | ||
}, | ||
{ | ||
ResourceName: "aws_transfer_server.foo", | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
ImportStateVerifyIgnore: []string{"force_destroy"}, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccCheckAWSTransferServerExists(n string, res *transfer.DescribedServer) resource.TestCheckFunc { | ||
return func(s *terraform.State) error { | ||
rs, ok := s.RootModule().Resources[n] | ||
|
@@ -177,6 +213,42 @@ func testAccCheckAWSTransferServerDestroy(s *terraform.State) error { | |
return nil | ||
} | ||
|
||
func testAccCheckAWSTransferCreateUser(describedServer *transfer.DescribedServer, getRoleOutput *iam.GetRoleOutput, userName string) resource.TestCheckFunc { | ||
return func(s *terraform.State) error { | ||
conn := testAccProvider.Meta().(*AWSClient).transferconn | ||
|
||
input := &transfer.CreateUserInput{ | ||
ServerId: describedServer.ServerId, | ||
UserName: aws.String(userName), | ||
Role: getRoleOutput.Role.Arn, | ||
} | ||
|
||
if _, err := conn.CreateUser(input); err != nil { | ||
return fmt.Errorf("error creating Transfer User (%s) on Server (%s): %s", userName, aws.StringValue(describedServer.ServerId), err) | ||
} | ||
|
||
return nil | ||
} | ||
} | ||
|
||
func testAccCheckAWSTransferCreateSshKey(describedServer *transfer.DescribedServer, userName string) resource.TestCheckFunc { | ||
return func(s *terraform.State) error { | ||
conn := testAccProvider.Meta().(*AWSClient).transferconn | ||
|
||
input := &transfer.ImportSshPublicKeyInput{ | ||
ServerId: describedServer.ServerId, | ||
UserName: aws.String(userName), | ||
SshPublicKeyBody: aws.String("ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD3F6tyPEFEzV0LX3X8BsXdMsQz1x2cEikKDEY0aIj41qgxMCP/iteneqXSIFZBp5vizPvaoIR3Um9xK7PGoW8giupGn+EPuxIA4cDM4vzOqOkiMPhz5XK0whEjkVzTo4+S0puvDZuwIsdiW9mxhJc7tgBNL0cYlWSYVkz4G/fslNfRPW5mYAM49f4fhtxPb5ok4Q2Lg9dPKVHO/Bgeu5woMc7RY0p1ej6D4CKFE6lymSDJpW0YHX/wqE9+cfEauh7xZcG0q9t2ta6F6fmX0agvpFyZo8aFbXeUBr7osSCJNgvavWbM/06niWrOvYX2xwWdhXmXSrbX8ZbabVohBK41 [email protected]"), | ||
} | ||
|
||
if _, err := conn.ImportSshPublicKey(input); err != nil { | ||
return fmt.Errorf("error creating Transfer SSH Public Key for (%s/%s): %s", userName, aws.StringValue(describedServer.ServerId), err) | ||
} | ||
|
||
return nil | ||
} | ||
} | ||
|
||
const testAccAWSTransferServerConfig_basic = ` | ||
resource "aws_transfer_server" "foo" {} | ||
` | ||
|
@@ -348,3 +420,50 @@ resource "aws_transfer_server" "foo" { | |
`, rName, rName, rName, rName) | ||
|
||
} | ||
|
||
func testAccAWSTransferServerConfig_forcedestroy(rName string) string { | ||
return fmt.Sprintf(` | ||
resource "aws_transfer_server" "foo" { | ||
force_destroy = true | ||
} | ||
resource "aws_iam_role" "foo" { | ||
name = "tf-test-transfer-user-iam-role-%s" | ||
assume_role_policy = <<EOF | ||
{ | ||
"Version": "2012-10-17", | ||
"Statement": [ | ||
{ | ||
"Effect": "Allow", | ||
"Principal": { | ||
"Service": "transfer.amazonaws.com" | ||
}, | ||
"Action": "sts:AssumeRole" | ||
} | ||
] | ||
} | ||
EOF | ||
} | ||
resource "aws_iam_role_policy" "foo" { | ||
name = "tf-test-transfer-user-iam-policy-%s" | ||
role = "${aws_iam_role.foo.id}" | ||
policy = <<POLICY | ||
{ | ||
"Version": "2012-10-17", | ||
"Statement": [ | ||
{ | ||
"Sid": "AllowFullAccesstoS3", | ||
"Effect": "Allow", | ||
"Action": [ | ||
"s3:*" | ||
], | ||
"Resource": "*" | ||
} | ||
] | ||
} | ||
POLICY | ||
} | ||
`, rName, rName) | ||
} |
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