How to use the tftest.__init__.TerraformJSONBase function in tftest

To help you get started, we’ve selected a few tftest examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github GoogleCloudPlatform / terraform-python-testing-helper / tftest / __init__.py View on Github external
"""Minimal wrapper for Terraform state modules."""

  def __init__(self, path, raw):
    self._raw = raw
    self.path = path
    self.outputs = TerraformOutputs(raw['outputs'])
    self.depends_on = raw['depends_on']
    # key type provider attributes depends_on
    self.resources = {}
    for k, v in raw['resources'].items():
      self.resources[k] = TerraformStateResource(
          k, v['provider'], v['type'],
          v.get('primary', {}).get('attributes', {}), v['depends_on'], v)


class TerraformState(TerraformJSONBase):
  """Minimal wrapper for Terraform state JSON format."""

  def __init__(self, raw):
    super(TerraformState, self).__init__(raw)
    self.modules = {}
    for k, v in raw.items():
      if k != 'modules':
        setattr(self, k, v)
        continue
      for mod in v:
        path = '.'.join(mod['path'])
        self.modules[path] = TerraformStateModule(path, mod)


class TerraformTest(object):
  """Helper class for use in testing Terraform modules.
github GoogleCloudPlatform / terraform-python-testing-helper / tftest / __init__.py View on Github external
"""Base class for JSON wrappers."""

  def __init__(self, raw):
    self.raw = raw

  def __bytes__(self):
    return bytes(self.raw)

  def __len__(self):
    return len(self.raw)

  def __str__(self):
    return str(self.raw)


class TerraformOutputs(TerraformJSONBase):
  """Minimal wrapper to directly expose output values."""

  def __init__(self, raw):
    super(TerraformOutputs, self).__init__(raw)
    self.sensitive = tuple(k for k, v in raw.items() if v.get('sensitive'))

  def __getitem__(self, name):
    return self.raw[name]['value']


class TerraformStateModule(object):
  """Minimal wrapper for Terraform state modules."""

  def __init__(self, path, raw):
    self._raw = raw
    self.path = path