tffile

class tfutility.core.tffile.TfFile(path: Path, autoparse=True)
property blocks
get_blocks_with_decorator(name: str)
get_tffile()
property hcl
property lines
parse()
read_tf(path: Path)
property tffile
write_back()
class tfutility.core.tffile.TfBlock(fileref, id: str, block_data: dict)

Represents a block in a terraform file

DECORATOR_REGEX = re.compile('#\\s?\\@([a-z]+)(\\((.*)\\))?')
property content

Returns a dict of the parsed block

property decorators
property end

End linenumber of the block

Returns:

The end linenumber of the block

Return type:

int

get_decorator(name: str) TfUtilityDecorator | None

find a decorator with the given name above the current block

Parameters:

name (str) – The name of the decorator to find

Returns:

The decorator with the given name or None if not found

Return type:

TfUtilDecorator

get_tfile()
has_decorator(name: str) bool

Check if this block has a decorator with the given name

Parameters:

name (str) – The name of the decorator to check for

Returns:

True if the block has a decorator with the given name, False otherwise

Return type:

bool

property id

id of the block. usually tfblocktype.blocktype.blockname

Returns:

The id of the block

Return type:

str

property start

Start linenumber of the block

Returns:

The start linenumber of the block

Return type:

int

property tffile
class tfutility.core.tffile.TfUtilityDecorator(blockref, name: str, data)

Represents a tfutility decorator used in tf files above blocks

PARAM_REGEX = re.compile('(\\b\\w+)(?:=((?:\\"[^\\"\\\\]*(?:\\\\.[^\\"\\\\]*)*\\"|\\w+)))?')
get_name()
property name

Name of the Decorator ( string after @ sign without arguments from braces text )

parameter(key: str, default=None)

Returns the value of a given parameter or the default value if the parameter is not set

Parameters:
  • key – The name of the parameter

  • default – The default value to return if the parameter is not set

Returns:

The value of the parameter or the default value if the parameter is not set