Skip to content

Commit 65b18e0

Browse files
authored
Merge pull request #31 from ahinh43/tf-15-import-support
Add support for Terraform 1.5 `import {}` actions
2 parents d4602a4 + 43e53bb commit 65b18e0

15 files changed

Lines changed: 614 additions & 20 deletions

File tree

go.mod

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ require (
1212
github.com/golang/mock v1.6.0
1313
github.com/google/go-cmp v0.5.9
1414
github.com/google/go-github/v49 v49.0.0
15-
github.com/hashicorp/go-tfe v1.16.0
16-
github.com/hashicorp/terraform-json v0.14.0
15+
github.com/hashicorp/go-tfe v1.30.0
16+
github.com/hashicorp/terraform-json v0.17.1
1717
github.com/heptiolabs/healthcheck v0.0.0-20211123025425-613501dd5deb
1818
github.com/jessevdk/go-flags v1.5.0
1919
github.com/kr/pretty v0.3.1
@@ -27,7 +27,7 @@ require (
2727
github.com/sl1pm4t/gongs v0.0.0-20221205005205-6f4e6d147fab
2828
github.com/spf13/cobra v1.6.1
2929
github.com/spf13/viper v1.14.0
30-
github.com/stretchr/testify v1.8.1
30+
github.com/stretchr/testify v1.8.4
3131
github.com/xanzy/go-gitlab v0.77.0
3232
github.com/ziflex/lecho/v3 v3.3.0
3333
golang.org/x/oauth2 v0.3.0
@@ -40,6 +40,7 @@ require (
4040
github.com/Microsoft/go-winio v0.6.0 // indirect
4141
github.com/ProtonMail/go-crypto v0.0.0-20230201104953-d1d05f4e2bfb // indirect
4242
github.com/acomagu/bufpipe v1.0.3 // indirect
43+
github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect
4344
github.com/beorn7/perks v1.0.1 // indirect
4445
github.com/cespare/xxhash/v2 v2.2.0 // indirect
4546
github.com/cloudflare/circl v1.3.2 // indirect
@@ -51,8 +52,8 @@ require (
5152
github.com/golang/protobuf v1.5.2 // indirect
5253
github.com/google/go-querystring v1.1.0 // indirect
5354
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
54-
github.com/hashicorp/go-retryablehttp v0.7.1 // indirect
55-
github.com/hashicorp/go-slug v0.10.1 // indirect
55+
github.com/hashicorp/go-retryablehttp v0.7.4 // indirect
56+
github.com/hashicorp/go-slug v0.11.1 // indirect
5657
github.com/hashicorp/go-version v1.6.0 // indirect
5758
github.com/hashicorp/hcl v1.0.0 // indirect
5859
github.com/hashicorp/jsonapi v0.0.0-20210826224640-ee7dae0fb22d // indirect
@@ -91,11 +92,11 @@ require (
9192
github.com/valyala/bytebufferpool v1.0.0 // indirect
9293
github.com/valyala/fasttemplate v1.2.2 // indirect
9394
github.com/xanzy/ssh-agent v0.3.3 // indirect
94-
github.com/zclconf/go-cty v1.12.1 // indirect
95+
github.com/zclconf/go-cty v1.13.2 // indirect
9596
golang.org/x/crypto v0.5.0 // indirect
9697
golang.org/x/mod v0.8.0 // indirect
9798
golang.org/x/net v0.5.0 // indirect
98-
golang.org/x/sync v0.1.0 // indirect
99+
golang.org/x/sync v0.3.0 // indirect
99100
golang.org/x/sys v0.5.0 // indirect
100101
golang.org/x/text v0.6.0 // indirect
101102
golang.org/x/time v0.3.0 // indirect

go.sum

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,12 @@ github.com/ProtonMail/go-crypto v0.0.0-20230201104953-d1d05f4e2bfb h1:Vx1Bw/nGUL
4646
github.com/ProtonMail/go-crypto v0.0.0-20230201104953-d1d05f4e2bfb/go.mod h1:I0gYDMZ6Z5GRU7l58bNFSkPTFN6Yl12dsUlAZ8xy98g=
4747
github.com/acomagu/bufpipe v1.0.3 h1:fxAGrHZTgQ9w5QqVItgzwj235/uYZYgbXitB+dLupOk=
4848
github.com/acomagu/bufpipe v1.0.3/go.mod h1:mxdxdup/WdsKVreO5GpW4+M/1CE2sMG4jeGJ2sYmHc4=
49+
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
50+
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho=
4951
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFIImctFaOjnTIavg87rW78vTPkQqLI8=
5052
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be/go.mod h1:ySMOLuWl6zY27l47sB3qLNK6tF2fkHG55UZxx8oIVo4=
5153
github.com/apparentlymart/go-textseg v1.0.0/go.mod h1:z96Txxhf3xSFMPmb5X/1W05FF/Nj9VFpLOpjS5yuumk=
54+
github.com/apparentlymart/go-textseg/v13 v13.0.0 h1:Y+KvPE1NYz0xl601PVImeQfFyEy6iT90AvPUL1NNfNw=
5255
github.com/apparentlymart/go-textseg/v13 v13.0.0/go.mod h1:ZK2fH7c4NqDTLtiYLvIkEghdlcqw7yxLeM89kiTRPUo=
5356
github.com/appleboy/gofight/v2 v2.1.2 h1:VOy3jow4vIK8BRQJoC/I9muxyYlJ2yb9ht2hZoS3rf4=
5457
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
@@ -111,6 +114,7 @@ github.com/go-git/go-git/v5 v5.5.2/go.mod h1:BE5hUJ5yaV2YMxhmaP4l6RBQ08kMxKSPD4B
111114
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
112115
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
113116
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
117+
github.com/go-logfmt/logfmt v0.5.1/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs=
114118
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
115119
github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY=
116120
github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I=
@@ -189,10 +193,16 @@ github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrj
189193
github.com/hashicorp/go-hclog v1.2.0 h1:La19f8d7WIlm4ogzNHB0JGqs5AUDAZ2UfCY4sJXcJdM=
190194
github.com/hashicorp/go-retryablehttp v0.7.1 h1:sUiuQAnLlbvmExtFQs72iFW/HXeUn8Z1aJLQ4LJJbTQ=
191195
github.com/hashicorp/go-retryablehttp v0.7.1/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY=
196+
github.com/hashicorp/go-retryablehttp v0.7.4 h1:ZQgVdpTdAL7WpMIwLzCfbalOcSUdkDZnpUv3/+BxzFA=
197+
github.com/hashicorp/go-retryablehttp v0.7.4/go.mod h1:Jy/gPYAdjqffZ/yFGCFV2doI5wjtH1ewM9u8iYVjtX8=
192198
github.com/hashicorp/go-slug v0.10.1 h1:05SCRWCBpCxOeP7stQHvMgOz0raCBCekaytu8Rg/RZ4=
193199
github.com/hashicorp/go-slug v0.10.1/go.mod h1:Ib+IWBYfEfJGI1ZyXMGNbu2BU+aa3Dzu41RKLH301v4=
200+
github.com/hashicorp/go-slug v0.11.1 h1:c6lLdQnlhUWbS5I7hw8SvfymoFuy6EmiFDedy6ir994=
201+
github.com/hashicorp/go-slug v0.11.1/go.mod h1:Ib+IWBYfEfJGI1ZyXMGNbu2BU+aa3Dzu41RKLH301v4=
194202
github.com/hashicorp/go-tfe v1.16.0 h1:B4yEfNNHuCiBjXXci+UiE5MsScAM+pfXwDXhBdNmOOg=
195203
github.com/hashicorp/go-tfe v1.16.0/go.mod h1:77snluBqtTTvMrY0w/mxQA5jlHQ8NT44AqQ8UdrPf0o=
204+
github.com/hashicorp/go-tfe v1.30.0 h1:vEieLxZ0Xly4+njypVwHH0RcUip7za1p6Pw52iqLOAY=
205+
github.com/hashicorp/go-tfe v1.30.0/go.mod h1:z0182DGE/63AKUaWblUVBIrt+xdSmsuuXg5AoxGqDF4=
196206
github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/Co8=
197207
github.com/hashicorp/go-version v1.5.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
198208
github.com/hashicorp/go-version v1.6.0 h1:feTTfFNnjP967rlCxM/I9g701jU+RN74YKx2mOkIeek=
@@ -205,6 +215,8 @@ github.com/hashicorp/jsonapi v0.0.0-20210826224640-ee7dae0fb22d h1:9ARUJJ1VVynB1
205215
github.com/hashicorp/jsonapi v0.0.0-20210826224640-ee7dae0fb22d/go.mod h1:Yog5+CPEM3c99L1CL2CFCYoSzgWm5vTU58idbRUaLik=
206216
github.com/hashicorp/terraform-json v0.14.0 h1:sh9iZ1Y8IFJLx+xQiKHGud6/TSUCM0N8e17dKDpqV7s=
207217
github.com/hashicorp/terraform-json v0.14.0/go.mod h1:5A9HIWPkk4e5aeeXIBbkcOvaZbIYnAIkEyqP2pNSckM=
218+
github.com/hashicorp/terraform-json v0.17.1 h1:eMfvh/uWggKmY7Pmb3T85u86E2EQg6EQHgyRwf3RkyA=
219+
github.com/hashicorp/terraform-json v0.17.1/go.mod h1:Huy6zt6euxaY9knPAFKjUITn8QxUFIe9VuSzb4zn/0o=
208220
github.com/heptiolabs/healthcheck v0.0.0-20211123025425-613501dd5deb h1:tsEKRC3PU9rMw18w/uAptoijhgG4EvlA5kfJPtwrMDk=
209221
github.com/heptiolabs/healthcheck v0.0.0-20211123025425-613501dd5deb/go.mod h1:NtmN9h8vrTveVQRLHcX2HQ5wIPBDCsZ351TGbZWgg38=
210222
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
@@ -218,8 +230,11 @@ github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOl
218230
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo=
219231
github.com/jessevdk/go-flags v1.5.0 h1:1jKYvbxEjfUl0fmqTCOfonvskHHXMjBySTLW4y9LFvc=
220232
github.com/jessevdk/go-flags v1.5.0/go.mod h1:Fw0T6WPc1dYxT4mKEZRfG5kJhaTDP9pj1c2EWnYs/m4=
233+
github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4=
234+
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
221235
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
222236
github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
237+
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
223238
github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4=
224239
github.com/kevinburke/ssh_config v1.2.0/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM=
225240
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
@@ -263,6 +278,9 @@ github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HK
263278
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
264279
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
265280
github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
281+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
282+
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
283+
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
266284
github.com/nats-io/jwt/v2 v2.3.0 h1:z2mA1a7tIf5ShggOFlR1oBPgd6hGqcDYsISxZByUzdI=
267285
github.com/nats-io/jwt/v2 v2.3.0/go.mod h1:0tqz9Hlu6bCBFLWAASKhE5vUA4c24L9KPUUgvwumE/k=
268286
github.com/nats-io/nats-server/v2 v2.9.8 h1:jgxZsv+A3Reb3MgwxaINcNq/za8xZInKhDg9Q0cGN1o=
@@ -341,6 +359,8 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
341359
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
342360
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
343361
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
362+
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
363+
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
344364
github.com/subosito/gotenv v1.4.1 h1:jyEFiXpy21Wm81FBN71l9VoMMV8H8jG+qIK3GCpY6Qs=
345365
github.com/subosito/gotenv v1.4.1/go.mod h1:ayKnFf/c6rvx/2iiLrJUk1e6plDbT3edrFNGqEflhK0=
346366
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
@@ -365,6 +385,8 @@ github.com/zclconf/go-cty v1.2.0/go.mod h1:hOPWgoHbaTUnI5k4D2ld+GRpFJSCe6bCM7m1q
365385
github.com/zclconf/go-cty v1.10.0/go.mod h1:vVKLxnk3puL4qRAv72AO+W99LUD4da90g3uUAzyuvAk=
366386
github.com/zclconf/go-cty v1.12.1 h1:PcupnljUm9EIvbgSHQnHhUr3fO6oFmkOrvs2BAFNXXY=
367387
github.com/zclconf/go-cty v1.12.1/go.mod h1:s9IfD1LK5ccNMSWCVFCE2rJfHiZgi7JijgeWIMfhLvA=
388+
github.com/zclconf/go-cty v1.13.2 h1:4GvrUxe/QUDYuJKAav4EYqdM47/kZa672LwmXFmEKT0=
389+
github.com/zclconf/go-cty v1.13.2/go.mod h1:YKQzy/7pZ7iq2jNFzy5go57xdxdWoLLpaEp4u238AE0=
368390
github.com/zclconf/go-cty-debug v0.0.0-20191215020915-b22d67c1ba0b/go.mod h1:ZRKQfBXbGkpdV6QMzT3rU1kSTAnfu1dO8dPKjYprgj8=
369391
github.com/ziflex/lecho/v3 v3.3.0 h1:Z6KnMf0ubJX93W8Np37DBIZalFubYDq0a92hv3S/9CY=
370392
github.com/ziflex/lecho/v3 v3.3.0/go.mod h1:VyOQDbC51eP3iJ4NdcyQbhmTqUZiapn7zJ3oHknCmXU=
@@ -490,6 +512,8 @@ golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJ
490512
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
491513
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
492514
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
515+
golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E=
516+
golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
493517
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
494518
golang.org/x/sys v0.0.0-20190130150945-aca44879d564/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
495519
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
@@ -719,6 +743,7 @@ google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175
719743
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
720744
gopkg.in/DATA-DOG/go-sqlmock.v1 v1.3.0 h1:FVCohIoYO7IJoDDVpV2pdq7SgrMH6wHnuTyrdrxJNoY=
721745
gopkg.in/DATA-DOG/go-sqlmock.v1 v1.3.0/go.mod h1:OdE7CF6DbADk7lN8LIKRzRJTTZXIjtWgA5THM5lhBAw=
746+
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
722747
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
723748
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
724749
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

localdev/terraform/main.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
locals {
2-
tfbuddy_base_url = "${chomp(var.ngrok_url)}"
2+
tfbuddy_base_url = chomp(var.ngrok_url)
33

44
child_tfvars = <<EOF
55
parent_vars = {
@@ -67,7 +67,7 @@ resource "local_file" "child_tfvars" {
6767
for_each = toset(local.child_tf_dirs)
6868

6969
filename = "${each.value}/parent.auto.tfvars"
70-
content = local.child_tfvars
70+
content = local.child_tfvars
7171
}
7272

7373

@@ -81,5 +81,5 @@ terraform {
8181
}
8282

8383
provider "tfe" {
84-
# requires TFC_TOKEN variable is set
84+
# requires TFC_TOKEN variable is set
8585
}

localdev/terraform/modules/vcs_files/main.tf

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,28 @@ resource "random_pet" "rando" {
5858
}
5959
}
6060
61+
import {
62+
to = random_integer.import
63+
id = "15390,2,5"
64+
}
65+
66+
resource "random_integer" "import" {
67+
min = 2
68+
max = 5
69+
keepers = {}
70+
}
71+
72+
import {
73+
to = random_integer.import_replacement
74+
id = "15390,2,5"
75+
}
76+
77+
resource "random_integer" "import_replacement" {
78+
min = 1
79+
max = 5
80+
keepers = {}
81+
}
82+
6183
resource "tls_private_key" "rsa-4096-example" {
6284
algorithm = "RSA"
6385
rsa_bits = 4096
@@ -94,4 +116,4 @@ output "files" {
94116
"terraform.tf" = local.terraform_tf,
95117
"main.tf" = local.main_tf
96118
}
97-
}
119+
}

pkg/comment_formatter/tfc_status_update.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func FormatRunStatusCommentBody(tfc tfc_api.ApiClient, run *tfe.Run, rmd runstre
2929
case tfe.RunApplying:
3030
// no extra info
3131
case tfe.RunApplied:
32-
extraInfo = fmt.Sprintf(successPlanSummaryFormat, run.Apply.ResourceAdditions, run.Apply.ResourceChanges, run.Apply.ResourceDestructions)
32+
extraInfo = fmt.Sprintf(successPlanSummaryFormat, run.Apply.ResourceImports, run.Apply.ResourceAdditions, run.Apply.ResourceChanges, run.Apply.ResourceDestructions)
3333
if len(run.TargetAddrs) > 0 {
3434
extraInfo += needToApplyFullWorkSpace
3535
extraInfo += fmt.Sprintf(howToApplyFormat, wsName)
@@ -49,7 +49,7 @@ func FormatRunStatusCommentBody(tfc tfc_api.ApiClient, run *tfe.Run, rmd runstre
4949
extraInfo = "Auto Apply Enabled - plan will automatically Apply if it passes policy checks."
5050
}
5151
case tfe.RunPlanned:
52-
extraInfo = fmt.Sprintf(successPlanSummaryFormat, run.Plan.ResourceAdditions, run.Plan.ResourceChanges, run.Plan.ResourceDestructions)
52+
extraInfo = fmt.Sprintf(successPlanSummaryFormat, run.Apply.ResourceImports, run.Plan.ResourceAdditions, run.Plan.ResourceChanges, run.Plan.ResourceDestructions)
5353
if !run.AutoApply {
5454
if len(run.TargetAddrs) > 0 {
5555
extraInfo += fmt.Sprintf(howToApplyFormatWithTarget, strings.Join(run.TargetAddrs, ","), wsName, strings.Join(run.TargetAddrs, ","))
@@ -139,6 +139,7 @@ var failedPlanSummaryFormat = `
139139
`
140140

141141
var successPlanSummaryFormat = `
142+
* Imports: %d
142143
* Additions: %d
143144
* Changes: %d
144145
* Destructions: %d`

pkg/terraform_plan/plan_parser.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,26 @@ func PresentPlanChangesAsMarkdown(b []byte, tfcUrl string) string {
3535
TfcUrl: tfcUrl,
3636
}
3737
for _, chg := range plan.ResourceChanges {
38+
3839
switch {
3940
case chg.Change.Actions.NoOp():
40-
continue
41+
// There can be scenarios where a resource can be imported and have nothing else happen to it.
42+
if chg.Change.Importing != nil {
43+
tplData.ImportCount += 1
44+
tplData.Imports = append(tplData.Imports, chg.Address)
45+
} else {
46+
continue
47+
}
4148

4249
case chg.Change.Actions.Create():
4350
tplData.AdditionCount += 1
4451
tplData.Additions = append(tplData.Additions, chg.Address)
4552

4653
case chg.Change.Actions.Update():
54+
if chg.Change.Importing != nil {
55+
tplData.ImportCount += 1
56+
tplData.Imports = append(tplData.Imports, chg.Address)
57+
}
4758
tplData.ChangeCount += 1
4859
tplData.Changes[chg.Address] = processChanges(chg)
4960

@@ -52,6 +63,10 @@ func PresentPlanChangesAsMarkdown(b []byte, tfcUrl string) string {
5263
tplData.Destructions = append(tplData.Destructions, chg.Address)
5364

5465
case chg.Change.Actions.Replace():
66+
if chg.Change.Importing != nil {
67+
tplData.ImportCount += 1
68+
tplData.Imports = append(tplData.Imports, chg.Address)
69+
}
5570
tplData.ReplacementCount += 1
5671
tplData.Replacements[chg.Address] = processChanges(chg)
5772
}
@@ -122,6 +137,8 @@ func isReplace(chg *tfjson.ResourceChange) bool {
122137
}
123138

124139
type PlanTemplateData struct {
140+
ImportCount int
141+
Imports []string
125142
AdditionCount int
126143
Additions []string
127144
ChangeCount int

pkg/terraform_plan/plan_parser_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ func Test_parseJSONPlan(t *testing.T) {
3939
want: nil,
4040
wantErr: false,
4141
},
42+
{
43+
name: "import",
44+
tfplan: "testdata/TestPresentPlanChangesAsMarkdown/import.tfplan.json",
45+
want: nil,
46+
wantErr: false,
47+
},
4248
}
4349
for _, tt := range tests {
4450
t.Run(tt.name, func(t *testing.T) {
@@ -66,6 +72,9 @@ func TestPresentPlanChangesAsMarkdown(t *testing.T) {
6672
{
6773
name: "replace",
6874
},
75+
{
76+
name: "import",
77+
},
6978
}
7079
for _, tt := range tests {
7180
t.Run(tt.name, func(t *testing.T) {

pkg/terraform_plan/templates/plan_output.tpl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55
{{- end}}
66
{{ end }}
77

8+
:airplane_arriving: <b>Imports:</b> {{.ImportCount}}
9+
<ul>
10+
{{- range .Imports}}
11+
<li><code>{{ . }}</code></li>
12+
{{- end}}
13+
</ul>
14+
815
:seedling: <b>Additions:</b> {{.AdditionCount}}
916
<ul>
1017
{{- range .Additions}}
@@ -29,7 +36,7 @@
2936
{{- end}}
3037
</ul>
3138
</br>
32-
<b>Plan: </b> {{.AdditionCount}} to add, {{.ChangeCount}} to change, {{.ReplacementCount}} to replace and {{.DestructionCount}} to destroy.
39+
<b>Plan: </b> {{.ImportCount}} to import, {{.AdditionCount}} to add, {{.ChangeCount}} to change, {{.ReplacementCount}} to replace and {{.DestructionCount}} to destroy.
3340
</br>
3441

3542
See [Terraform Cloud Output]({{.TfcUrl}}) for more info.

pkg/terraform_plan/testdata/TestPresentPlanChangesAsMarkdown/basic.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11

22

3+
:airplane_arriving: <b>Imports:</b> 0
4+
<ul>
5+
</ul>
6+
37
:seedling: <b>Additions:</b> 1
48
<ul>
59
<li><code>random_pet.will_it_be_cats</code></li>
@@ -21,7 +25,7 @@
2125
<ul>
2226
</ul>
2327
</br>
24-
<b>Plan: </b> 1 to add, 0 to change, 0 to replace and 0 to destroy.
28+
<b>Plan: </b> 0 to import, 1 to add, 0 to change, 0 to replace and 0 to destroy.
2529
</br>
2630

2731
See [Terraform Cloud Output](http://app.terraform.io/x/y/z) for more info.

pkg/terraform_plan/testdata/TestPresentPlanChangesAsMarkdown/basic.tfplan.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,4 +608,4 @@
608608
}
609609
}
610610
}
611-
}
611+
}

0 commit comments

Comments
 (0)