providers/aws: aws_instance id-only
This commit is contained in:
parent
46430cd384
commit
d85df63526
|
@ -533,6 +533,9 @@ func resourceAwsInstanceRead(d *schema.ResourceData, meta interface{}) error {
|
|||
if err := d.Set("vpc_security_group_ids", sgs); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := d.Set("security_groups", []string{}); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
for _, sg := range instance.SecurityGroups {
|
||||
sgs = append(sgs, *sg.GroupName)
|
||||
|
@ -541,11 +544,29 @@ func resourceAwsInstanceRead(d *schema.ResourceData, meta interface{}) error {
|
|||
if err := d.Set("security_groups", sgs); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := d.Set("vpc_security_group_ids", []string{}); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if err := readBlockDevices(d, instance, conn); err != nil {
|
||||
return err
|
||||
}
|
||||
if _, ok := d.GetOk("ephemeral_block_device"); !ok {
|
||||
d.Set("ephemeral_block_device", []interface{}{})
|
||||
}
|
||||
|
||||
// Instance attributes
|
||||
{
|
||||
attr, err := conn.DescribeInstanceAttribute(&ec2.DescribeInstanceAttributeInput{
|
||||
Attribute: aws.String("disableApiTermination"),
|
||||
InstanceId: aws.String(d.Id()),
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
d.Set("disable_api_termination", attr.DisableApiTermination.Value)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -696,8 +717,17 @@ func readBlockDevices(d *schema.ResourceData, instance *ec2.Instance, conn *ec2.
|
|||
if err := d.Set("ebs_block_device", ibds["ebs"]); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// This handles the import case which needs to be defaulted to empty
|
||||
if _, ok := d.GetOk("root_block_device"); !ok {
|
||||
if err := d.Set("root_block_device", []interface{}{}); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if ibds["root"] != nil {
|
||||
if err := d.Set("root_block_device", []interface{}{ibds["root"]}); err != nil {
|
||||
roots := []interface{}{ibds["root"]}
|
||||
if err := d.Set("root_block_device", roots); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,7 +33,14 @@ func TestAccAWSInstance_basic(t *testing.T) {
|
|||
}
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
|
||||
// We ignore security groups because even with EC2 classic
|
||||
// we'll import as VPC security groups, which is fine. We verify
|
||||
// VPC security group import in other tests
|
||||
IDRefreshName: "aws_instance.foo",
|
||||
IDRefreshIgnore: []string{"user_data", "security_groups", "vpc_security_group_ids"},
|
||||
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testAccCheckInstanceDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
|
@ -135,7 +142,10 @@ func TestAccAWSInstance_blockDevices(t *testing.T) {
|
|||
}
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
IDRefreshName: "aws_instance.foo",
|
||||
IDRefreshIgnore: []string{
|
||||
"ephemeral_block_device", "user_data", "security_groups", "vpc_security_groups"},
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testAccCheckInstanceDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
|
@ -202,9 +212,10 @@ func TestAccAWSInstance_sourceDestCheck(t *testing.T) {
|
|||
}
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testAccCheckInstanceDestroy,
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
IDRefreshName: "aws_instance.foo",
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testAccCheckInstanceDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testAccInstanceConfigSourceDestDisable,
|
||||
|
@ -255,9 +266,10 @@ func TestAccAWSInstance_disableApiTermination(t *testing.T) {
|
|||
}
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testAccCheckInstanceDestroy,
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
IDRefreshName: "aws_instance.foo",
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testAccCheckInstanceDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testAccInstanceConfigDisableAPITermination(true),
|
||||
|
@ -282,9 +294,11 @@ func TestAccAWSInstance_vpc(t *testing.T) {
|
|||
var v ec2.Instance
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testAccCheckInstanceDestroy,
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
IDRefreshName: "aws_instance.foo",
|
||||
IDRefreshIgnore: []string{"associate_public_ip_address", "user_data"},
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testAccCheckInstanceDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testAccInstanceConfigVPC,
|
||||
|
@ -337,9 +351,11 @@ func TestAccAWSInstance_NetworkInstanceSecurityGroups(t *testing.T) {
|
|||
var v ec2.Instance
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testAccCheckInstanceDestroy,
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
IDRefreshName: "aws_instance.foo_instance",
|
||||
IDRefreshIgnore: []string{"associate_public_ip_address"},
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testAccCheckInstanceDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testAccInstanceNetworkInstanceSecurityGroups,
|
||||
|
@ -356,9 +372,10 @@ func TestAccAWSInstance_NetworkInstanceVPCSecurityGroupIDs(t *testing.T) {
|
|||
var v ec2.Instance
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testAccCheckInstanceDestroy,
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
IDRefreshName: "aws_instance.foo_instance",
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testAccCheckInstanceDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testAccInstanceNetworkInstanceVPCSecurityGroupIDs,
|
||||
|
@ -419,9 +436,10 @@ func TestAccAWSInstance_privateIP(t *testing.T) {
|
|||
}
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testAccCheckInstanceDestroy,
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
IDRefreshName: "aws_instance.foo",
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testAccCheckInstanceDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testAccInstanceConfigPrivateIP,
|
||||
|
@ -448,9 +466,11 @@ func TestAccAWSInstance_associatePublicIPAndPrivateIP(t *testing.T) {
|
|||
}
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testAccCheckInstanceDestroy,
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
IDRefreshName: "aws_instance.foo",
|
||||
IDRefreshIgnore: []string{"associate_public_ip_address"},
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testAccCheckInstanceDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testAccInstanceConfigAssociatePublicIPAndPrivateIP,
|
||||
|
@ -482,9 +502,11 @@ func TestAccAWSInstance_keyPairCheck(t *testing.T) {
|
|||
}
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testAccCheckInstanceDestroy,
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
IDRefreshName: "aws_instance.foo",
|
||||
IDRefreshIgnore: []string{"source_dest_check"},
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testAccCheckInstanceDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testAccInstanceConfigKeyPair,
|
||||
|
@ -530,9 +552,10 @@ func TestAccAWSInstance_forceNewAndTagsDrift(t *testing.T) {
|
|||
var v ec2.Instance
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testAccCheckInstanceDestroy,
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
IDRefreshName: "aws_instance.foo",
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testAccCheckInstanceDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testAccInstanceConfigForceNewAndTagsDrift,
|
||||
|
|
|
@ -317,8 +317,16 @@ func testIDOnlyRefresh(c TestCase, opts terraform.ContextOpts, step TestStep, r
|
|||
expected := r.Primary.Attributes
|
||||
// Remove fields we're ignoring
|
||||
for _, v := range c.IDRefreshIgnore {
|
||||
delete(actual, v)
|
||||
delete(expected, v)
|
||||
for k, _ := range actual {
|
||||
if strings.HasPrefix(k, v) {
|
||||
delete(actual, k)
|
||||
}
|
||||
}
|
||||
for k, _ := range expected {
|
||||
if strings.HasPrefix(k, v) {
|
||||
delete(expected, k)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(actual, expected) {
|
||||
|
|
Loading…
Reference in New Issue