github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/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  			{
    27  				Config: testAccAWSSecurityGroupConfig,
    28  			},
    29  
    30  			{
    31  				ResourceName:     "aws_security_group.web",
    32  				ImportState:      true,
    33  				ImportStateCheck: checkFn,
    34  			},
    35  		},
    36  	})
    37  }
    38  
    39  func TestAccAWSSecurityGroup_importIpv6(t *testing.T) {
    40  	checkFn := func(s []*terraform.InstanceState) error {
    41  		// Expect 3: group, 2 rules
    42  		if len(s) != 3 {
    43  			return fmt.Errorf("expected 3 states: %#v", s)
    44  		}
    45  
    46  		return nil
    47  	}
    48  
    49  	resource.Test(t, resource.TestCase{
    50  		PreCheck:     func() { testAccPreCheck(t) },
    51  		Providers:    testAccProviders,
    52  		CheckDestroy: testAccCheckAWSSecurityGroupDestroy,
    53  		Steps: []resource.TestStep{
    54  			{
    55  				Config: testAccAWSSecurityGroupConfigIpv6,
    56  			},
    57  
    58  			{
    59  				ResourceName:     "aws_security_group.web",
    60  				ImportState:      true,
    61  				ImportStateCheck: checkFn,
    62  			},
    63  		},
    64  	})
    65  }
    66  
    67  func TestAccAWSSecurityGroup_importSelf(t *testing.T) {
    68  	resource.Test(t, resource.TestCase{
    69  		PreCheck:     func() { testAccPreCheck(t) },
    70  		Providers:    testAccProviders,
    71  		CheckDestroy: testAccCheckAWSSecurityGroupDestroy,
    72  		Steps: []resource.TestStep{
    73  			{
    74  				Config: testAccAWSSecurityGroupConfig_importSelf,
    75  			},
    76  
    77  			{
    78  				ResourceName:      "aws_security_group.allow_all",
    79  				ImportState:       true,
    80  				ImportStateVerify: true,
    81  			},
    82  		},
    83  	})
    84  }
    85  
    86  func TestAccAWSSecurityGroup_importSourceSecurityGroup(t *testing.T) {
    87  	resource.Test(t, resource.TestCase{
    88  		PreCheck:     func() { testAccPreCheck(t) },
    89  		Providers:    testAccProviders,
    90  		CheckDestroy: testAccCheckAWSSecurityGroupDestroy,
    91  		Steps: []resource.TestStep{
    92  			{
    93  				Config: testAccAWSSecurityGroupConfig_importSourceSecurityGroup,
    94  			},
    95  
    96  			{
    97  				ResourceName:      "aws_security_group.test_group_1",
    98  				ImportState:       true,
    99  				ImportStateVerify: true,
   100  			},
   101  		},
   102  	})
   103  }
   104  
   105  func TestAccAWSSecurityGroup_importIPRangeAndSecurityGroupWithSameRules(t *testing.T) {
   106  	checkFn := func(s []*terraform.InstanceState) error {
   107  		// Expect 4: group, 3 rules
   108  		if len(s) != 4 {
   109  			return fmt.Errorf("expected 4 states: %#v", s)
   110  		}
   111  
   112  		return nil
   113  	}
   114  
   115  	resource.Test(t, resource.TestCase{
   116  		PreCheck:     func() { testAccPreCheck(t) },
   117  		Providers:    testAccProviders,
   118  		CheckDestroy: testAccCheckAWSSecurityGroupDestroy,
   119  		Steps: []resource.TestStep{
   120  			{
   121  				Config: testAccAWSSecurityGroupConfig_importIPRangeAndSecurityGroupWithSameRules,
   122  			},
   123  
   124  			{
   125  				ResourceName:     "aws_security_group.test_group_1",
   126  				ImportState:      true,
   127  				ImportStateCheck: checkFn,
   128  			},
   129  		},
   130  	})
   131  }
   132  
   133  func TestAccAWSSecurityGroup_importIPRangesWithSameRules(t *testing.T) {
   134  	checkFn := func(s []*terraform.InstanceState) error {
   135  		// Expect 4: group, 2 rules
   136  		if len(s) != 3 {
   137  			return fmt.Errorf("expected 3 states: %#v", s)
   138  		}
   139  
   140  		return nil
   141  	}
   142  
   143  	resource.Test(t, resource.TestCase{
   144  		PreCheck:     func() { testAccPreCheck(t) },
   145  		Providers:    testAccProviders,
   146  		CheckDestroy: testAccCheckAWSSecurityGroupDestroy,
   147  		Steps: []resource.TestStep{
   148  			{
   149  				Config: testAccAWSSecurityGroupConfig_importIPRangesWithSameRules,
   150  			},
   151  
   152  			{
   153  				ResourceName:     "aws_security_group.test_group_1",
   154  				ImportState:      true,
   155  				ImportStateCheck: checkFn,
   156  			},
   157  		},
   158  	})
   159  }