starhawking / python-terrascript

Create Terraform files using Python scripts.
BSD 2-Clause "Simplified" License
515 stars 76 forks source link

Get references to data right. #89

Closed mjuenema closed 4 years ago

mjuenema commented 4 years ago

Currently the Python data source example in the Tutorial does not work. The reference to image.self_link results in "image": null in the JSON output.

    # Google Cloud Compute provider
config += terrascript.provider.google(credentials='${file("account.json")}',
                                      project='myproject', region='us-central1')

# Google Compute Image (Debian 9) data source
image = terrascript.data.google_compute_image("image", family=IMAGE_FAMILY)
config += image

# Add Google Compute Instance resource
config += terrascript.resource.google_compute_instance("myinstance",
                                                       name="myinstance",
                                                       machine_type=MACHINE_TYPE,
                                                       zone="us-central1-a",
                                                       boot_disk={
                                                            "initialize_params": {
                                                                "image": image.self_link        # <======
                                                            }    
                                                       },
                                                       network_interface={
                                                           "network": "default",
                                                           "access_config": {}
                                                       })
{
  "provider": {
    "google": [
      {
        "credentials": "${file(\"account.json\")}",
        "project": "myproject",
        "region": "us-central1"
      }
    ]
  },
  "data": {
    "google_compute_image": {
      "image": {
        "family": "debian-9"
      }
    }
  },
  "resource": {
    "google_compute_instance": {
      "myinstance": {
        "name": "myinstance",
        "machine_type": "n1-standard-1",
        "zone": "us-central1-a",
        "boot_disk": {
          "initialize_params": {
            "image": null        # <======
          }
        },
        "network_interface": {
          "network": "default",
          "access_config": {}
        }
      }
    }
  }
}
mjuenema commented 4 years ago

I think that's fixed