tfpy.core package¶
group module¶
Define the group module.
-
tfpy.core.group.
correlate
(groups_, users)¶ Correlate the role with the users via the groups.
- Example:
>>> # Define the groups and their roles. >>> groups = { >>> "admin": ["role/owner", "role/manager"], >>> "dev": ["role/viewer"], >>> "ops": ["role/editor"], >>> } >>> # Define the users and their groups. >>> users = { >>> "admin1": ["admin"], >>> "admin2": ["admin"], >>> "dev1": ["dev"], >>> "dev2": ["dev"], >>> "ops1": ["dev", "ops",], >>> } >>> result = { >>> 'role/owner': ['admin1', 'admin2'], >>> 'role/manager': ['admin1', 'admin2'], >>> 'role/viewer': ['dev1', 'dev2', 'ops1'], >>> 'role/editor': ['ops1'] >>> } >>> assert correlate(groups, users) == result
- Parameters
dict (users) – dict mapping a group to a list of roles
dict – dict mapping a user to a list of groups
- Return dict
a dict mapping a role do a list of users.
interpolation module¶
Define the module containing interpolation functions.
This module was created to mitigate the following TerrafomPy bugs:
-
tfpy.core.interpolation.
i
(tfobject, *args)¶ Interpolate a tfobject.
- Example:
>>> from terraformpy import Module >>> from terraformpy import Variable >>> v = Variable("region") >>> i(v) ${var.region} >>> m = Module("vpc") >>> i(m, "network") ${module.vpc.network}
- Parameters
TFObject (tfobject) – terroformpy object to interpolate
list(str) (args) – a list of strings representing the TFObject attributes to interpolate.
- Return str
a string representation of the TFObject and its arguments if any.
-
tfpy.core.interpolation.
interpolate
(resource, *args)¶ Return a string representing the resource.
- Example:
>>> interpolate("var", "region") ${var.region} >>> interpolate("module", "vpc", "network") ${module.vpc.network}
- Parameters
str (resource) – resource name
list(str) (args) – a list of strings representing the Variable attributes to interpolate.
- Return str
a string representation of the resource and its arguments if any.
-
tfpy.core.interpolation.
m
(*args)¶ Interpolate a module.
- Example:
>>> m("vpc", "network") ${module.vpc.network}
- Parameters
list(str) (args) – a list of strings representing the Module attributes to interpolate.
- Return str
a string representation of the Variable and its arguments if any.
-
tfpy.core.interpolation.
v
(*args)¶ Interpolate a variable.
- Example:
>>> v("region") ${var.region}
- Parameters
list(str) (args) – a list of strings representing the Variable attributes to interpolate.
- Return str
a string representation of the Variable and its arguments if any.
stack module¶
Define the module managing the stack vars.
-
class
tfpy.core.stack.
StackVars
(stack, environment='', var_dir='.')¶ Bases:
object
Define the object managing the stack vars.
-
get
(var, default=None, separator='.')¶ Retrieve a value matching a key in the config file.
- Parameters
var – the var to look for
default – the default value to return if the key is not found
- Returns
the value matching the key
-
list_variable_files
()¶ List the variable files that have been detected for the stack.
-
load
()¶ Load the stack variables.
-
-
tfpy.core.stack.
get_stacks
(var_dir='vars')¶ Retrieve the stacks.