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

Move HCL support to be compatible with 0.12+ syntax #312

Open
drubin opened this issue Jan 4, 2020 · 6 comments
Open

Move HCL support to be compatible with 0.12+ syntax #312

drubin opened this issue Jan 4, 2020 · 6 comments
Milestone

Comments

@drubin
Copy link
Contributor

drubin commented Jan 4, 2020

The terraform example doesn't produce valid terraform code. With no clear example of how to make it work.

Example from https://jkcfg.github.io/#/documentation/quick-start

Invalid

"provider" "github" {
  "organization" = "myorg"
}

"github_membership" "myorg_alice84" {
  "username" = "alice84"

  "role" = "admin"
}

"github_membership" "myorg_bob93" {
  "username" = "bob93"

  "role" = "member"
}

expected valid output

provider "github" {
  organization = "myorg"
}

resource github_membership "myorg_alice84" {
  username = "alice84"
  role     = "admin"
}

resource github_membership "myorg_bob93" {
  username = "bob93"
  role     = "member"
}

Quick fixes

We can change the example to the following to get closer to valid terraform 0.11.xx syntax (this is not valid 0.12 syntax yet though because of the quotes around "resources")

const config = {
  provider: {
    github: {
      organization,
      anonymous: true
    },
  },
  resource: {
    github_membership: {},
  }
};

for (const dev of developers) {
  config.resource.github_membership[membershipId(dev)] = {
    username: dev.github.handle,
    role: role(dev),
  };
}

However, replacing the example to export .tf.json produces valid terraform parseable results.

export default [
  { value: config, file: 'github.tf.json' },
];
{
  "provider": {
    "github": {
      "anonymous": true,
      "organization": "myorg"
    }
  },
  "resource": {
    "github_membership": {
      "myorg_alice84": {
        "role": "admin",
        "username": "alice84"
      },
      "myorg_bob93": {
        "role": "member",
        "username": "bob93"
      }
    }
  }
}

Which can then be used with terraform plan

$ ls
developers.js  github.js      github.tf.json 
$ terraform plan
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.


------------------------------------------------------------------------

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # github_membership.myorg_alice84 will be created
  + resource "github_membership" "myorg_alice84" {
      + etag     = (known after apply)
      + id       = (known after apply)
      + role     = "admin"
      + username = "alice84"
    }

  # github_membership.myorg_bob93 will be created
  + resource "github_membership" "myorg_bob93" {
      + etag     = (known after apply)
      + id       = (known after apply)
      + role     = "member"
      + username = "bob93"
    }

Plan: 2 to add, 0 to change, 0 to destroy.

------------------------------------------------------------------------

Note: You didn't specify an "-out" parameter to save this plan, so Terraform
can't guarantee that exactly these actions will be performed if
"terraform apply" is subsequently run.

Docs

https://www.terraform.io/docs/providers/github/
https://www.terraform.io/docs/providers/github/r/membership.html

Extra info

  • References std: Support writing HCL files #151 for when this was added
  • The above example fix (pr pending) will produce valid terraform 0.11 syntax but this isn't valid for 0.12 yet (excess quotes)

I tried to find how to make this possible but I couldn't find a test or example test case in the codebase. I would love to try to help make this valid as I think this is an incredible way to dynamically generate terraform.

@dlespiau
Copy link
Member

dlespiau commented Jan 5, 2020

Thanks for the detailed issue. Everything you said makes sense to me.

@errordeveloper
Copy link
Contributor

Can we close it, or there are some things here that #313 didn't address?

@drubin
Copy link
Contributor Author

drubin commented Jan 16, 2020

Nope this isn't fully addressed but we can rename it to something that clearly states it doesn't support Terraform 0.12.?

@drubin drubin changed the title Terraform provider in the example isn't valid Terraform provider in the example isn't valid 0.12 syntax Jan 16, 2020
@dlespiau
Copy link
Member

I think two things need to happen with this issue:

@dlespiau dlespiau changed the title Terraform provider in the example isn't valid 0.12 syntax Move HCL support to be compatible with 0.12+ syntax Jan 16, 2020
@drubin
Copy link
Contributor Author

drubin commented Jan 16, 2020

@dlespiau sounds perfect.
I hadn't gotten around to it yet but I am very eggerly waiting to try move some of our Terraform code to this. But we use 0.12 so currently it isn't possible.

@dlespiau
Copy link
Member

No promises on an ETA, but this is definitely on my radar :)

@squaremo squaremo added this to the 0.4.0 milestone Mar 10, 2020
@squaremo squaremo modified the milestones: 0.4.0, 0.5.0 Apr 3, 2020
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

4 participants