From 11190144f039dc4723bb86c06316faaa3d795a8e Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Sat, 21 Nov 2015 11:13:25 -0800 Subject: [PATCH] AWS Opsworks tests bring their own IAM objects. Previously we assumed the existence of some default objects that most Opsworks users have because the Opsworks console creates them by default when a new stack is created. However, that meant that these tests wouldn't work correctly for anyone who either had never used Opsworks via the UI or who had never accepted the default of having the console create some predefined IAM objects to use. It may also have led to some weird failures if a particular user had customized the settings for these default objects. Now the tests create suitable IAM roles, a policy and an instance profile and use these when creating Opsworks stacks, avoiding any dependency on any pre-existing objects. This fixes #3998. --- ...resource_aws_opsworks_custom_layer_test.go | 7 +- .../aws/resource_aws_opsworks_stack_test.go | 162 ++++++++++-------- 2 files changed, 89 insertions(+), 80 deletions(-) diff --git a/builtin/providers/aws/resource_aws_opsworks_custom_layer_test.go b/builtin/providers/aws/resource_aws_opsworks_custom_layer_test.go index 14a65b106..a39b5dbdb 100644 --- a/builtin/providers/aws/resource_aws_opsworks_custom_layer_test.go +++ b/builtin/providers/aws/resource_aws_opsworks_custom_layer_test.go @@ -12,16 +12,13 @@ import ( // and `aws-opsworks-service-role`. func TestAccAwsOpsworksCustomLayer(t *testing.T) { - opsiam := testAccAwsOpsworksStackIam{} - testAccAwsOpsworksStackPopulateIam(t, &opsiam) - resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckAwsOpsworksCustomLayerDestroy, Steps: []resource.TestStep{ resource.TestStep{ - Config: fmt.Sprintf(testAccAwsOpsworksCustomLayerConfigCreate, opsiam.ServiceRoleArn, opsiam.InstanceProfileArn), + Config: testAccAwsOpsworksCustomLayerConfigCreate, Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( "aws_opsworks_custom_layer.tf-acc", "name", "tf-ops-acc-custom-layer", @@ -68,7 +65,7 @@ func TestAccAwsOpsworksCustomLayer(t *testing.T) { ), }, resource.TestStep{ - Config: fmt.Sprintf(testAccAwsOpsworksCustomLayerConfigUpdate, opsiam.ServiceRoleArn, opsiam.InstanceProfileArn), + Config: testAccAwsOpsworksCustomLayerConfigUpdate, Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( "aws_opsworks_custom_layer.tf-acc", "name", "tf-ops-acc-custom-layer", diff --git a/builtin/providers/aws/resource_aws_opsworks_stack_test.go b/builtin/providers/aws/resource_aws_opsworks_stack_test.go index 2a3e95b3c..63a27578c 100644 --- a/builtin/providers/aws/resource_aws_opsworks_stack_test.go +++ b/builtin/providers/aws/resource_aws_opsworks_stack_test.go @@ -8,23 +8,91 @@ import ( "github.com/hashicorp/terraform/terraform" "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/iam" "github.com/aws/aws-sdk-go/service/opsworks" ) -// These tests assume the existence of predefined Opsworks IAM roles named `aws-opsworks-ec2-role` -// and `aws-opsworks-service-role`. +////////////////////////////////////////////////// +//// Helper configs for the necessary IAM objects +////////////////////////////////////////////////// + +var testAccAwsOpsworksStackIamConfig = ` +resource "aws_iam_role" "opsworks_service" { + name = "terraform_testacc_opsworks_service" + assume_role_policy = <