Skip to content
This repository was archived by the owner on Apr 6, 2026. It is now read-only.
This repository was archived by the owner on Apr 6, 2026. It is now read-only.

Modules don't provide interpolation #66

Description

@rgreinho

I am trying to use the output of a Terraform module, and inject them into resources.

However, referring to a module object fails with the following error:

$ terraformpy
terraformpy - Processing: main.tf.py
Traceback (most recent call last):
  File "/private/tmp/terraformpy-bug/.venv/bin/terraformpy", line 10, in <module>
    sys.exit(main())
  File "/private/tmp/terraformpy-bug/.venv/lib/python3.8/site-packages/terraformpy/cli.py", line 41, in main
    imp.load_source(filename[:-6], filename)
  File "/usr/local/Cellar/python@3.8/3.8.2/Frameworks/Python.framework/Versions/3.8/lib/python3.8/imp.py", line 171, in load_source
    module = _load(spec)
  File "<frozen importlib._bootstrap>", line 702, in _load
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 783, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "main.tf.py", line 19, in <module>
    tags=[vpc.private],
  File "/private/tmp/terraformpy-bug/.venv/lib/python3.8/site-packages/terraformpy/objects.py", line 292, in __getattr__
    raise AttributeError(
AttributeError: Modules does not provide attribute interpolation through attribute access!

Context

Using python3 on OSX:

$ python3 --version
Python 3.8.2
$ system_profiler SPSoftwareDataType|grep macOS | xargs
System Version: macOS 10.15.4 (19E287)
$ pip list | grep -i terraformpy
terraformpy 1.3.0

Repro steps

The script:

from terraformpy import Module
from terraformpy import Resource


vpc = Module(
    "vpc",
    source="gruntwork-io/network/google//modules/vpc-network",
    version="0.4.0",
    project="vpc-demo",
    region="us-central1",
)
Resource(
    "google_compute_instance",
    "private",
    project="vpc-demo",
    name="vpc-private",
    machine_type="n1-standard-1",
    allow_stopping_for_update=True,
    tags=[vpc.private],
    boot_disk=dict(initialize_params=dict(image="debian-cloud/debian-9")),
    network_interface=dict(subnetwork=vpc.private_subnetwork,),
)

The steps:

mkdir -p /tmp/terraformpy-bug
cd /tmp/terraformpy-bug
pbpaste > main.tf.py
python3 -m venv .venv
source .venv/bin/activate
pip install terraformpy
terraformpy

Workaround

The workaround I am using is to manually interpolate the module reference:

network_interface=dict(subnetwork="${vpc.private_subnetwork})

But that defeats the purpose of using a python object.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions