Skip to content

Commit 9ec1990

Browse files
committed
providers/aws/aws_instance: fix security group and key name issues in count
1 parent e8eae17 commit 9ec1990

3 files changed

Lines changed: 40 additions & 0 deletions

File tree

‎builtin/providers/aws/resource_aws_instance.go‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,13 +202,18 @@ func resource_aws_instance_diff(
202202

203203
ComputedAttrs: []string{
204204
"availability_zone",
205+
"key_name",
205206
"public_dns",
206207
"public_ip",
207208
"private_dns",
208209
"private_ip",
210+
"security_groups",
211+
"subnet_id",
209212
},
210213
}
211214

215+
// TODO(mitchellh): figure out way to diff user_data_hash
216+
212217
return b.Diff(s, c)
213218
}
214219

‎helper/diff/resource_builder.go‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,13 @@ func (b *ResourceBuilder) Diff(
120120
comp = true
121121
break
122122
}
123+
124+
// If the key is prefixed with the computed key, don't
125+
// mark it for delete, ever.
126+
if strings.HasPrefix(k, ck+".") {
127+
comp = true
128+
break
129+
}
123130
}
124131
if comp {
125132
continue

‎helper/diff/resource_builder_test.go‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,34 @@ func TestResourceBuilder_attrSetComputed(t *testing.T) {
3737
}
3838
}
3939

40+
func TestResourceBuilder_attrSetComputedComplex(t *testing.T) {
41+
rb := &ResourceBuilder{
42+
Attrs: map[string]AttrType{
43+
"foo": AttrTypeCreate,
44+
},
45+
ComputedAttrs: []string{
46+
"foo",
47+
},
48+
}
49+
50+
state := &terraform.ResourceState{
51+
ID: "foo",
52+
Attributes: map[string]string{
53+
"foo.#": "0",
54+
},
55+
}
56+
57+
c := testConfig(t, map[string]interface{}{}, nil)
58+
59+
diff, err := rb.Diff(state, c)
60+
if err != nil {
61+
t.Fatalf("err: %s", err)
62+
}
63+
if diff != nil {
64+
t.Fatalf("diff shold be nil: %s", diff)
65+
}
66+
}
67+
4068
func TestResourceBuilder_replaceComputed(t *testing.T) {
4169
rb := &ResourceBuilder{
4270
Attrs: map[string]AttrType{

0 commit comments

Comments
 (0)