Skip to content

Commit 897f228

Browse files
authored
Clean up terraform runtime files (#82)
* clean up terraform runtime files * replace deprecated template_file datasource from template provider with templatefile built-in function
1 parent e5c3b4c commit 897f228

3 files changed

Lines changed: 8 additions & 9 deletions

File tree

test/fixtures/apply/main.tf

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,10 @@
1414
* limitations under the License.
1515
*/
1616

17-
data "template_file" "sample" {
18-
for_each = toset(var.names)
19-
template = "sample template $${name}"
20-
vars = {
21-
name = each.key
22-
}
23-
}
24-
2517
resource "null_resource" "sample" {
2618
for_each = toset(var.names)
2719
triggers = {
2820
name = each.key
29-
template = data.template_file.sample[each.key].rendered
21+
template = templatefile("${path.module}/template.tftpl", { name = each.key })
3022
}
3123
}

test/fixtures/apply/template.tftpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sample template ${name}

tftest.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,9 +365,15 @@ def remove_readonly(func, path, excinfo):
365365
path = os.path.join(tfdir, '.terraform')
366366
if os.path.isdir(path):
367367
shutil.rmtree(path, onerror=remove_readonly)
368+
path = os.path.join(tfdir, '.terraform.lock.hcl')
369+
if os.path.isfile(path):
370+
os.unlink(path)
368371
path = os.path.join(tfdir, 'terraform.tfstate')
369372
if os.path.isfile(path):
370373
os.unlink(path)
374+
for path in glob.glob(os.path.join(tfdir, 'terraform.tfstate.backup*')):
375+
if os.path.isfile(path):
376+
os.unlink(path)
371377
path = os.path.join(tfdir, '**', '.terragrunt-cache*')
372378
for tg_dir in glob.glob(path, recursive=True):
373379
if os.path.isdir(tg_dir):

0 commit comments

Comments
 (0)