You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importosimportre# Find all Terraform files in the repository skipping any directories named .terraformfiles= []
forroot, dirs, filenamesinos.walk('.'):
if'.terraform'indirs:
dirs.remove('.terraform')
forfilenameinfilenames:
iffilename.endswith('.tf'):
files.append(os.path.join(root, filename))
# Loop through each fileforfileinfiles:
print(f'Processing {file}')
withopen(file, 'r') asf:
content=f.readlines()
# Loop through each line in the filei=0whilei<len(content):
line=content[i]
# Check if the line defines a resourceifre.match(r'resource "[^"]+" "[^"]+" \{', line):
# Find the position of the closing curly brace of the resourcebrace_count=0j=iwhile (j==iorbrace_count>0) andj<len(content):
if'{'incontent[j]:
brace_count+=content[j].count('{')
if'}'incontent[j]:
brace_count-=content[j].count('}')
j+=1end=j# Define the resource variableresource=''.join(content[i:end])
# Check if the resource has a "tags" attribute but no "lifecycle" attributeifre.search(r'tags\s*=', resource) andnotre.search(r'lifecycle\s*{', resource):
# Add the "lifecycle" block to the resourcecontent[i:end] =content[i:end-1] + [f'\n lifecycle {{ ignore_changes = [tags] }}\n'] +content[end-1:end]
# output the resource and file nameprint(f'Added lifecycle block to resource in {file}')
# Move the index to the end of the resourcei=endelse:
i+=1withopen(file, 'w') asf:
f.writelines(content)
Resources are missing ignore_changes = [tags] leading to churn when tags are applied using policy.
lifecycle { ignore_changes = [tags] }
Needs adding to all resources that have tags applied by the Azure TRE.
The text was updated successfully, but these errors were encountered: