github.com/vtorhonen/terraform@v0.9.0-beta2.0.20170307220345-5d894e4ffda7/builtin/providers/aws/import_aws_security_group_test.go (about)

     1  package aws
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  
     7  	"github.com/hashicorp/terraform/helper/resource"
     8  	"github.com/hashicorp/terraform/terraform"
     9  )
    10  
    11  func TestAccAWSSecurityGroup_importBasic(t *testing.T) {
    12  	checkFn := func(s []*terraform.InstanceState) error {
    13  		// Expect 3: group, 2 rules
    14  		if len(s) != 3 {
    15  			return fmt.Errorf("expected 3 states: %#v", s)
    16  		}
    17  
    18  		return nil
    19  	}
    20  
    21  	resource.Test(t, resource.TestCase{
    22  		PreCheck:     func() { testAccPreCheck(t) },
    23  		Providers:    testAccProviders,
    24  		CheckDestroy: testAccCheckAWSSecurityGroupDestroy,
    25  		Steps: []resource.TestStep{
    26  			resource.TestStep{
    27  				Config: testAccAWSSecurityGroupConfig,
    28  			},
    29  
    30  			resource.TestStep{
    31  				ResourceName:     "aws_security_group.web",
    32  				ImportState:      true,
    33  				ImportStateCheck: checkFn,
    34  			},
    35  		},
    36  	})
    37  }
    38  
    39  func TestAccAWSSecurityGroup_importSelf(t *testing.T) {
    40  	resource.Test(t, resource.TestCase{
    41  		PreCheck:     func() { testAccPreCheck(t) },
    42  		Providers:    testAccProviders,
    43  		CheckDestroy: testAccCheckAWSSecurityGroupDestroy,
    44  		Steps: []resource.TestStep{
    45  			resource.TestStep{
    46  				Config: testAccAWSSecurityGroupConfig_importSelf,
    47  			},
    48  
    49  			resource.TestStep{
    50  				ResourceName:      "aws_security_group.allow_all",
    51  				ImportState:       true,
    52  				ImportStateVerify: true,
    53  			},
    54  		},
    55  	})
    56  }
    57  
    58  func TestAccAWSSecurityGroup_importSourceSecurityGroup(t *testing.T) {
    59  	resource.Test(t, resource.TestCase{
    60  		PreCheck:     func() { testAccPreCheck(t) },
    61  		Providers:    testAccProviders,
    62  		CheckDestroy: testAccCheckAWSSecurityGroupDestroy,
    63  		Steps: []resource.TestStep{
    64  			resource.TestStep{
    65  				Config: testAccAWSSecurityGroupConfig_importSourceSecurityGroup,
    66  			},
    67  
    68  			resource.TestStep{
    69  				ResourceName:      "aws_security_group.test_group_1",
    70  				ImportState:       true,
    71  				ImportStateVerify: true,
    72  			},
    73  		},
    74  	})
    75  }