Alternate resource type configuration

166 views
Skip to first unread message

Trevor Hartman

unread,
Mar 8, 2016, 2:19:33 PM3/8/16
to Terraform
In the Jsonnet post from a few years ago, the output.json example shows resources being configured like:

   "web_elb": {
      "instances": [
         "web"
      ],
      "kind": "Terraform#Aws#ElasticLoadBalancer",
      "listener": {
         "instance_port": 80,
         "instance_protocol": "http",
         "lb_port": 80,
         "lb_protocol": "http"
      },
      "name": "terraform-example-elb"
   }


This is in contrast to the documented, more rigid way of configuring resources in Terraform:

"resource": {
  "aws_elb": {
    "web_elb": {
      ...
    }
  }
}


Based on output.json I started trying to define GCP resources the same way, e.g.:

      "dev-us-central1-private-subnet": {
         "ip_cidr_range": "10.0.0.0/13",
         "kind": "Terraform#Gcp#GoogleComputeSubnetwork",
         "name": "dev-us-central1-private",
         "network": "${google_compute_network.dev.self_link}",
         "region": "us-central1"
      },

But if I try this, Terraform complains:

* Unknown root level key: dev-us-central1-private-subnet

Is this not supported? Was it an old way of doing things? It happens to be much more flexible when generating config with Jsonnet and taking advantage of nested loops and maps, so I hope it works.

Thanks.

Dave Cunningham

unread,
Mar 11, 2016, 12:27:12 PM3/11/16
to terrafo...@googlegroups.com
Can you paste a complete JSON example of a TF config that doesn't work -- it's probably some confusion in the process of converting HCL to JSON (which is a bit subtle sometimes).

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/hashicorp/terraform/issues
IRC: #terraform-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Terraform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to terraform-too...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/44ef114d-8f96-4cc1-955d-c78776a93a47%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Trevor Hartman

unread,
Mar 11, 2016, 12:32:44 PM3/11/16
to Terraform
Here's a link to output.json from the post:

I've switched to using generating standard TF syntax, so this isn't an issue. Just curious if it is or was possible to configure resources using "kind", e.g. "kind": "Terraform#Gcp#GoogleComputeSubnetwork", instead of nesting them inside a parent "google_compute_subnetwork" item.

Dave Cunningham

unread,
Mar 11, 2016, 12:45:00 PM3/11/16
to terrafo...@googlegroups.com
Ah yeah that was a proposal for an alternative JSON format that never happened.  Terraform accepts JSON in a rigid format so you have to do the "resources": { "my_name": { } } bit.  You can abstract that in Jsonnet if you like but unsure if it's worth it.

I'm curious how you're generating standard TF syntax, are you referring to HCL or the TF JSON?

Trevor Hartman

unread,
Mar 11, 2016, 12:47:12 PM3/11/16
to Terraform
I'm generating TF JSON via jsonnet. Turns out it's not that hard or inconvenient to adhere to TF's rigid nested format using jsonnet's object concatenation.

Dave Cunningham

unread,
Mar 11, 2016, 12:48:25 PM3/11/16
to terrafo...@googlegroups.com

Trevor Hartman

unread,
Mar 11, 2016, 12:53:00 PM3/11/16
to terrafo...@googlegroups.com
Looks interesting! Is that Python transformation piece pure custom or did you open source anything? I'm trying to figure out how to tie this all into a CD pipeline.
You received this message because you are subscribed to a topic in the Google Groups "Terraform" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/terraform-tool/-RK1nIPkN10/unsubscribe.
To unsubscribe from this group and all its topics, send an email to terraform-too...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/CANarjTgEhcDiEPSKOAMWD3tLPD3QWvWKsykJw_Z%3DUi8ZxZ%2Bm9Q%40mail.gmail.com.

Dave Cunningham

unread,
Mar 11, 2016, 12:54:57 PM3/11/16
to terrafo...@googlegroups.com
It's an ongoing experiment in the jsonnet repo case_studies/micromanage that I wish I had more time to work on :)

Really high-level abstract descriptions of cloud services that are nestable and portable between cloud providers.

Ameir Abdeldayem

unread,
Mar 11, 2016, 1:40:20 PM3/11/16
to terrafo...@googlegroups.com
FWIW, generating compliant HCL isn't that bad.  I used to generate pure JSON for TF, but for the sake of others on my team who weren't comfortable with that approach, I explored generating HCL from a hash.

The bulk of that is here, if anyone is interested:

Dave Cunningham

unread,
Mar 11, 2016, 1:51:52 PM3/11/16
to terrafo...@googlegroups.com
I believe it'd be possible to generate HCL from Jsonnet using a "manifest" function like the ones that already exist in the standard library for emitting INI files, Python dicts, etc.  However I've never had to do that.  The only time I had a problem (putting multiple providers in the same JSON file) it was resolved by writing multiple JSON tf files and having Terraform merge them.

Reply all
Reply to author
Forward
0 new messages