{"action":"opened","issue":{"url":"https://api.github.com/repos/mjuenema/python-terrascript/issues/26","repository_url":"https://api.github.com/repos/mjuenema/python-terrascript","labels_url":"https://api.github.com/repos/mjuenema/python-terrascript/issues/26/labels{/name}","comments_url":"https://api.github.com/repos/mjuenema/python-terrascript/issues/26/comments","events_url":"https://api.github.com/repos/mjuenema/python-terrascript/issues/26/events","html_url":"https://github.com/mjuenema/python-terrascript/issues/26","id":297656326,"number":26,"title":"Problem when using resource in a loop","user":{"login":"robinbowes","id":104948,"avatar_url":"https://avatars3.githubusercontent.com/u/104948?v=4","gravatar_id":"","url":"https://api.github.com/users/robinbowes","html_url":"https://github.com/robinbowes","followers_url":"https://api.github.com/users/robinbowes/followers","following_url":"https://api.github.com/users/robinbowes/following{/other_user}","gists_url":"https://api.github.com/users/robinbowes/gists{/gist_id}","starred_url":"https://api.github.com/users/robinbowes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/robinbowes/subscriptions","organizations_url":"https://api.github.com/users/robinbowes/orgs","repos_url":"https://api.github.com/users/robinbowes/repos","events_url":"https://api.github.com/users/robinbowes/events{/privacy}","received_events_url":"https://api.github.com/users/robinbowes/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-02-16T01:35:12Z","updated_at":"2018-02-16T01:35:12Z","closed_at":null,"author_association":"NONE","body":"Hi,\r\n\r\nI'm using terrascript to dump existing datadog monitors into terraform code.\r\n\r\nHere's some sample code:\r\n\r\n```python\r\nimport terrascript\r\nfrom datadog import initialize, api\r\nfrom terrascript.datadog.r import datadog_monitor\r\n\r\n\r\ndef get_all():\r\n    \"\"\" get all monitors \"\"\"\r\n    initialize()\r\n    response = api.Monitor.get_all()\r\n    return response\r\n\r\n\r\ndef dump_as_tf(monitor):\r\n    \"\"\" Dump the specified monitor as terraform code \"\"\"\r\n    kwargs = {}\r\n    kwargs['type'] = monitor['type']\r\n    datadog_monitor(\r\n       monitor['name'],\r\n       **kwargs\r\n    )\r\n    print(terrascript.dump())\r\n\r\n\r\ndef dump_all_as_tf():\r\n    \"\"\" get all monitors and dump as terraform code \"\"\"\r\n    response = get_all()\r\n    # response is an array of hashes, one hash for each monitor\r\n    for monitor in response:\r\n        dump_as_tf(monitor)\r\n```\r\n\r\nWhat I see is that the `datadog_monitor` resource doesn't clean up between invocations so I end up with this sort of output:\r\n\r\n```json\r\n{\r\n  \"resource\": {\r\n    \"datadog_monitor\": {\r\n      \"name of first monitor\": {\r\n        \"type\": \"query alert\"\r\n      }\r\n    }\r\n  }\r\n}\r\n{\r\n  \"resource\": {\r\n    \"datadog_monitor\": {\r\n      \"name of second monitor\": {\r\n        \"type\": \"service check\"\r\n      },\r\n      \"name of first monitor\": {\r\n        \"type\": \"query alert\"\r\n      }\r\n    }\r\n  }\r\n}\r\n{\r\n  \"resource\": {\r\n    \"datadog_monitor\": {\r\n      \"name of second monitor\": {\r\n        \"type\": \"service check\"\r\n      },\r\n      \"name of third monitor\": {\r\n        \"type\": \"service check\"\r\n      },\r\n      \"name of first monitor\": {\r\n        \"type\": \"query alert\"\r\n      }\r\n    }\r\n  }\r\n}\r\n```\r\n\r\nAm I doing something wrong here?"}}
{"actor":{"display_login":"robinbowes"}}