raymondbutcher / pretf

Generate Terraform code with Python
https://pretf.readthedocs.io/
MIT License
104 stars 14 forks source link

Change signature for creating blocks #13

Closed raymondbutcher closed 5 years ago

raymondbutcher commented 5 years ago

After reading this a bit more https://www.terraform.io/docs/configuration/syntax.html#arguments-and-blocks

I think I want to change how blocks are created.

# current
tf(f"resource.aws_iam_user.{username}", {
  "name": "test"
})

# proposed
tf("resource", "aws_iam_user", username, {
  "name": "test"
})

The function might be like:

def tf(*args) -> Block:
    block_type = None
    labels = list(args)
    body = None # or {} not sure
    if labels:
        block_type = labels.pop(0)
    if labels:
        body = labels.pop()
    return Block(block_type, labels, body)

Should the function be called block() rather than tf()? Would it make the *.tf.py files a bit uglier?

Does this work for all potential blocks? Need to look at providers, terraform block, etc.

What about when generating tfvars files?

raymondbutcher commented 5 years ago

Done in 90cd11216b1c01b776618df0611b1c96e2146bb3