github.com/minamijoyo/terraform@v0.7.8-0.20161029001309-18b3736ba44b/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  }