Skip to content

Commit

Permalink
Clean up terraform runtime files (#82)
Browse files Browse the repository at this point in the history
* clean up terraform runtime files

* replace deprecated template_file datasource from template provider with templatefile built-in function
  • Loading branch information
elstak authored Jun 21, 2024
1 parent e5c3b4c commit 897f228
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
10 changes: 1 addition & 9 deletions test/fixtures/apply/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,10 @@
* limitations under the License.
*/

data "template_file" "sample" {
for_each = toset(var.names)
template = "sample template $${name}"
vars = {
name = each.key
}
}

resource "null_resource" "sample" {
for_each = toset(var.names)
triggers = {
name = each.key
template = data.template_file.sample[each.key].rendered
template = templatefile("${path.module}/template.tftpl", { name = each.key })
}
}
1 change: 1 addition & 0 deletions test/fixtures/apply/template.tftpl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sample template ${name}
6 changes: 6 additions & 0 deletions tftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,9 +365,15 @@ def remove_readonly(func, path, excinfo):
path = os.path.join(tfdir, '.terraform')
if os.path.isdir(path):
shutil.rmtree(path, onerror=remove_readonly)
path = os.path.join(tfdir, '.terraform.lock.hcl')
if os.path.isfile(path):
os.unlink(path)
path = os.path.join(tfdir, 'terraform.tfstate')
if os.path.isfile(path):
os.unlink(path)
for path in glob.glob(os.path.join(tfdir, 'terraform.tfstate.backup*')):
if os.path.isfile(path):
os.unlink(path)
path = os.path.join(tfdir, '**', '.terragrunt-cache*')
for tg_dir in glob.glob(path, recursive=True):
if os.path.isdir(tg_dir):
Expand Down

0 comments on commit 897f228

Please sign in to comment.