starhawking / python-terrascript

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

Add ESXI Provider #145

Closed alby97 closed 3 years ago

alby97 commented 3 years ago

Hi, I think that this project is very interesting and I want to use it but I'm currently using this provider (https://github.com/josenk/terraform-provider-esxi) that unfortunately is not included in your project, so I will ask if you can add this provider to this tool, I think that it would be very helpful, also because the esxi provider is a very good tool. Thanks in advance for the attention.

ilons commented 3 years ago

@alby97 I did add some feedback to the PR https://github.com/mjuenema/python-terrascript/pull/144 , would you mind giving it a try to generate the providers and update the PR?

alby97 commented 3 years ago

Hi, sorry, my reply could be a little silly but could you explain what you mean with generate the providers? Sorry again for this reply, probably is my fault that I didn't understand what you mean. However thanks for the reply.

ilons commented 3 years ago

Ahh, no worries! So basically, terrascript generates bindings for providers, which are included in the lib. They are generated by running the script I linked in the PR.

alby97 commented 3 years ago

I cloned the project from the develop branch, installed the required packages, tried to add the provider in the yaml file and run the script but at the end it gives me this error: Traceback (most recent call last): File "C:\Users\alby9\Desktop\Prova Terrascript\python-terrascript\tools\makecode.py", line 362, in <module> main() File "C:\Users\alby9\Desktop\Prova Terrascript\python-terrascript\tools\makecode.py", line 342, in main raise exc File "C:\Python39\lib\concurrent\futures\thread.py", line 52, in run result = self.fn(*self.args, **self.kwargs) File "C:\Users\alby9\Desktop\Prova Terrascript\python-terrascript\tools\makecode.py", line 284, in process with open(provider_path, "rb") as fp: FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\alby9\\AppData\\Local\\Temp\\tmpzgv6sqtz\\archive\\provider.go'

It generates me the "esxi" folder but one file is empty (d.py) and the other seems fine. I don't know what is the problem.

ilons commented 3 years ago

@alby97 Thank you for giving it a try, I think this might not have been tested on Windows before. I'll try to have a look at this during the day, or as soon as possible.

alby97 commented 3 years ago

@ilons It's a pleasure. I tried also on Ubuntu but the error is basically the same, it didn't found the file "provider.go". I gave a quick look to the code but I didn't understand what could be the problem, maybe the provider misses something that the script needs to generate the files but the structure of the provider seems very similar to the others that are already in the yaml file. When I have some free time I try to give a better look at that, let me know if you have some news.

ilons commented 3 years ago

@alby97 Yes, you are probably correct that the provider is structured differently (than what the script expects). As mentioned earlier, that script really do need to get an overhaul (together with how we generate the bindings), as it make a lot of assumptions right now.

mjuenema commented 3 years ago

The underlying problem is that the "parser" is using regular expressions for extracting the information from the Terraform Go source code. It would be much nicer to either (a) have a proper Go language parser, or (b) use a Go pretty-printer to convert the Terraform source code (the module's source cod to be precise) into a standardised format. I did some research on option (a) but it's just too difficult. Option (b), pretty-printing the Go source code before parsing, is the more promising approach.

Does anyone know of a Go pretty-printing solution? A quick search found Gofmt

mjuenema commented 3 years ago

FYI: I started a separate discussion (#149) on the issue of making makecode.py more robust.