Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modules don't provide interpolation #66

Open
rgreinho opened this issue May 29, 2020 · 1 comment
Open

Modules don't provide interpolation #66

rgreinho opened this issue May 29, 2020 · 1 comment

Comments

@rgreinho
Copy link

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/[email protected]/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.

@ghost
Copy link

ghost commented Sep 15, 2022

@rgreinho did you ever find a solution for this? running into the same error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant