Skip to content

Commit 1733150

Browse files
authored
Merge pull request #28 from akihiro17/show-index
show instance key of resources
2 parents c8eeb1d + 4194698 commit 1733150

File tree

4 files changed

+369
-6
lines changed

4 files changed

+369
-6
lines changed

internal/terraform/unified_diff_renderer.go

+2-6
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,9 @@ func (r *UnifiedDiffRenderer) Render() (string, error) {
4343
}
4444

4545
func (r *UnifiedDiffRenderer) Header() string {
46-
header := fmt.Sprintf("%s.%s %s", r.ResourceChange.Type, r.ResourceChange.Name, r.headerSuffix())
46+
header := fmt.Sprintf("%s %s", r.ResourceChange.Address, r.headerSuffix())
4747

48-
if r.ResourceChange.ModuleAddress == "" {
49-
return header
50-
} else {
51-
return fmt.Sprintf("%s.%s", r.ResourceChange.ModuleAddress, header)
52-
}
48+
return header
5349
}
5450

5551
func (r *UnifiedDiffRenderer) headerSuffix() string {

test/plan_test/plan_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ func Test_render(t *testing.T) {
6565
{name: "include_module", wantErr: false},
6666
{name: "known_after_apply", wantErr: false},
6767
{name: "moved_block", wantErr: false},
68+
{name: "resource_with_index", wantErr: false},
6869
}
6970
for _, tt := range tests {
7071
t.Run(tt.name, func(t *testing.T) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
### 2 to add, 0 to change, 0 to destroy, 0 to replace.
2+
- add
3+
- aws_instance.web["t3.micro"]
4+
- aws_instance.web["t3.small"]
5+
<details><summary>Change details</summary>
6+
7+
````````diff
8+
# aws_instance.web["t3.micro"] will be created
9+
@@ -1,2 +1,14 @@
10+
-null
11+
+{
12+
+ "ami": "ami-04fc53a873660e525",
13+
+ "credit_specification": [],
14+
+ "get_password_data": false,
15+
+ "hibernation": null,
16+
+ "instance_type": "t3.micro",
17+
+ "launch_template": [],
18+
+ "source_dest_check": true,
19+
+ "tags": null,
20+
+ "timeouts": null,
21+
+ "user_data_replace_on_change": false,
22+
+ "volume_tags": null
23+
+}
24+
25+
````````
26+
27+
````````diff
28+
# aws_instance.web["t3.small"] will be created
29+
@@ -1,2 +1,14 @@
30+
-null
31+
+{
32+
+ "ami": "ami-04fc53a873660e525",
33+
+ "credit_specification": [],
34+
+ "get_password_data": false,
35+
+ "hibernation": null,
36+
+ "instance_type": "t3.small",
37+
+ "launch_template": [],
38+
+ "source_dest_check": true,
39+
+ "tags": null,
40+
+ "timeouts": null,
41+
+ "user_data_replace_on_change": false,
42+
+ "volume_tags": null
43+
+}
44+
45+
````````
46+
47+
</details>
+319
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,319 @@
1+
{
2+
"format_version": "1.2",
3+
"terraform_version": "1.8.5",
4+
"planned_values": {
5+
"root_module": {
6+
"resources": [
7+
{
8+
"address": "aws_instance.web[\"t3.micro\"]",
9+
"mode": "managed",
10+
"type": "aws_instance",
11+
"name": "web",
12+
"index": "t3.micro",
13+
"provider_name": "registry.terraform.io/hashicorp/aws",
14+
"schema_version": 1,
15+
"values": {
16+
"ami": "ami-04fc53a873660e525",
17+
"credit_specification": [],
18+
"get_password_data": false,
19+
"hibernation": null,
20+
"instance_type": "t3.micro",
21+
"launch_template": [],
22+
"source_dest_check": true,
23+
"tags": null,
24+
"timeouts": null,
25+
"user_data_replace_on_change": false,
26+
"volume_tags": null
27+
},
28+
"sensitive_values": {
29+
"capacity_reservation_specification": [],
30+
"credit_specification": [],
31+
"ebs_block_device": [],
32+
"enclave_options": [],
33+
"ephemeral_block_device": [],
34+
"ipv6_addresses": [],
35+
"launch_template": [],
36+
"maintenance_options": [],
37+
"metadata_options": [],
38+
"network_interface": [],
39+
"private_dns_name_options": [],
40+
"root_block_device": [],
41+
"secondary_private_ips": [],
42+
"security_groups": [],
43+
"tags_all": {},
44+
"vpc_security_group_ids": []
45+
}
46+
},
47+
{
48+
"address": "aws_instance.web[\"t3.small\"]",
49+
"mode": "managed",
50+
"type": "aws_instance",
51+
"name": "web",
52+
"index": "t3.small",
53+
"provider_name": "registry.terraform.io/hashicorp/aws",
54+
"schema_version": 1,
55+
"values": {
56+
"ami": "ami-04fc53a873660e525",
57+
"credit_specification": [],
58+
"get_password_data": false,
59+
"hibernation": null,
60+
"instance_type": "t3.small",
61+
"launch_template": [],
62+
"source_dest_check": true,
63+
"tags": null,
64+
"timeouts": null,
65+
"user_data_replace_on_change": false,
66+
"volume_tags": null
67+
},
68+
"sensitive_values": {
69+
"capacity_reservation_specification": [],
70+
"credit_specification": [],
71+
"ebs_block_device": [],
72+
"enclave_options": [],
73+
"ephemeral_block_device": [],
74+
"ipv6_addresses": [],
75+
"launch_template": [],
76+
"maintenance_options": [],
77+
"metadata_options": [],
78+
"network_interface": [],
79+
"private_dns_name_options": [],
80+
"root_block_device": [],
81+
"secondary_private_ips": [],
82+
"security_groups": [],
83+
"tags_all": {},
84+
"vpc_security_group_ids": []
85+
}
86+
}
87+
]
88+
}
89+
},
90+
"resource_changes": [
91+
{
92+
"address": "aws_instance.web[\"t3.micro\"]",
93+
"mode": "managed",
94+
"type": "aws_instance",
95+
"name": "web",
96+
"index": "t3.micro",
97+
"provider_name": "registry.terraform.io/hashicorp/aws",
98+
"change": {
99+
"actions": [
100+
"create"
101+
],
102+
"before": null,
103+
"after": {
104+
"ami": "ami-04fc53a873660e525",
105+
"credit_specification": [],
106+
"get_password_data": false,
107+
"hibernation": null,
108+
"instance_type": "t3.micro",
109+
"launch_template": [],
110+
"source_dest_check": true,
111+
"tags": null,
112+
"timeouts": null,
113+
"user_data_replace_on_change": false,
114+
"volume_tags": null
115+
},
116+
"after_unknown": {
117+
"arn": true,
118+
"associate_public_ip_address": true,
119+
"availability_zone": true,
120+
"capacity_reservation_specification": true,
121+
"cpu_core_count": true,
122+
"cpu_threads_per_core": true,
123+
"credit_specification": [],
124+
"disable_api_stop": true,
125+
"disable_api_termination": true,
126+
"ebs_block_device": true,
127+
"ebs_optimized": true,
128+
"enclave_options": true,
129+
"ephemeral_block_device": true,
130+
"host_id": true,
131+
"host_resource_group_arn": true,
132+
"iam_instance_profile": true,
133+
"id": true,
134+
"instance_initiated_shutdown_behavior": true,
135+
"instance_state": true,
136+
"ipv6_address_count": true,
137+
"ipv6_addresses": true,
138+
"key_name": true,
139+
"launch_template": [],
140+
"maintenance_options": true,
141+
"metadata_options": true,
142+
"monitoring": true,
143+
"network_interface": true,
144+
"outpost_arn": true,
145+
"password_data": true,
146+
"placement_group": true,
147+
"placement_partition_number": true,
148+
"primary_network_interface_id": true,
149+
"private_dns": true,
150+
"private_dns_name_options": true,
151+
"private_ip": true,
152+
"public_dns": true,
153+
"public_ip": true,
154+
"root_block_device": true,
155+
"secondary_private_ips": true,
156+
"security_groups": true,
157+
"subnet_id": true,
158+
"tags_all": true,
159+
"tenancy": true,
160+
"user_data": true,
161+
"user_data_base64": true,
162+
"vpc_security_group_ids": true
163+
},
164+
"before_sensitive": false,
165+
"after_sensitive": {
166+
"capacity_reservation_specification": [],
167+
"credit_specification": [],
168+
"ebs_block_device": [],
169+
"enclave_options": [],
170+
"ephemeral_block_device": [],
171+
"ipv6_addresses": [],
172+
"launch_template": [],
173+
"maintenance_options": [],
174+
"metadata_options": [],
175+
"network_interface": [],
176+
"private_dns_name_options": [],
177+
"root_block_device": [],
178+
"secondary_private_ips": [],
179+
"security_groups": [],
180+
"tags_all": {},
181+
"vpc_security_group_ids": []
182+
}
183+
}
184+
},
185+
{
186+
"address": "aws_instance.web[\"t3.small\"]",
187+
"mode": "managed",
188+
"type": "aws_instance",
189+
"name": "web",
190+
"index": "t3.small",
191+
"provider_name": "registry.terraform.io/hashicorp/aws",
192+
"change": {
193+
"actions": [
194+
"create"
195+
],
196+
"before": null,
197+
"after": {
198+
"ami": "ami-04fc53a873660e525",
199+
"credit_specification": [],
200+
"get_password_data": false,
201+
"hibernation": null,
202+
"instance_type": "t3.small",
203+
"launch_template": [],
204+
"source_dest_check": true,
205+
"tags": null,
206+
"timeouts": null,
207+
"user_data_replace_on_change": false,
208+
"volume_tags": null
209+
},
210+
"after_unknown": {
211+
"arn": true,
212+
"associate_public_ip_address": true,
213+
"availability_zone": true,
214+
"capacity_reservation_specification": true,
215+
"cpu_core_count": true,
216+
"cpu_threads_per_core": true,
217+
"credit_specification": [],
218+
"disable_api_stop": true,
219+
"disable_api_termination": true,
220+
"ebs_block_device": true,
221+
"ebs_optimized": true,
222+
"enclave_options": true,
223+
"ephemeral_block_device": true,
224+
"host_id": true,
225+
"host_resource_group_arn": true,
226+
"iam_instance_profile": true,
227+
"id": true,
228+
"instance_initiated_shutdown_behavior": true,
229+
"instance_state": true,
230+
"ipv6_address_count": true,
231+
"ipv6_addresses": true,
232+
"key_name": true,
233+
"launch_template": [],
234+
"maintenance_options": true,
235+
"metadata_options": true,
236+
"monitoring": true,
237+
"network_interface": true,
238+
"outpost_arn": true,
239+
"password_data": true,
240+
"placement_group": true,
241+
"placement_partition_number": true,
242+
"primary_network_interface_id": true,
243+
"private_dns": true,
244+
"private_dns_name_options": true,
245+
"private_ip": true,
246+
"public_dns": true,
247+
"public_ip": true,
248+
"root_block_device": true,
249+
"secondary_private_ips": true,
250+
"security_groups": true,
251+
"subnet_id": true,
252+
"tags_all": true,
253+
"tenancy": true,
254+
"user_data": true,
255+
"user_data_base64": true,
256+
"vpc_security_group_ids": true
257+
},
258+
"before_sensitive": false,
259+
"after_sensitive": {
260+
"capacity_reservation_specification": [],
261+
"credit_specification": [],
262+
"ebs_block_device": [],
263+
"enclave_options": [],
264+
"ephemeral_block_device": [],
265+
"ipv6_addresses": [],
266+
"launch_template": [],
267+
"maintenance_options": [],
268+
"metadata_options": [],
269+
"network_interface": [],
270+
"private_dns_name_options": [],
271+
"root_block_device": [],
272+
"secondary_private_ips": [],
273+
"security_groups": [],
274+
"tags_all": {},
275+
"vpc_security_group_ids": []
276+
}
277+
}
278+
}
279+
],
280+
"configuration": {
281+
"provider_config": {
282+
"aws": {
283+
"name": "aws",
284+
"full_name": "registry.terraform.io/hashicorp/aws",
285+
"expressions": {
286+
"region": {
287+
"constant_value": "ap-northeast-1"
288+
}
289+
}
290+
}
291+
},
292+
"root_module": {
293+
"resources": [
294+
{
295+
"address": "aws_instance.web",
296+
"mode": "managed",
297+
"type": "aws_instance",
298+
"name": "web",
299+
"provider_config_key": "aws",
300+
"expressions": {
301+
"ami": {
302+
"constant_value": "ami-04fc53a873660e525"
303+
},
304+
"instance_type": {
305+
"references": [
306+
"each.value"
307+
]
308+
}
309+
},
310+
"schema_version": 1
311+
}
312+
]
313+
}
314+
},
315+
"timestamp": "2024-06-20T12:10:40Z",
316+
"applyable": true,
317+
"complete": true,
318+
"errored": false
319+
}

0 commit comments

Comments
 (0)