Code Monkey home page Code Monkey logo

Comments (20)

andyt530 avatar andyt530 commented on June 27, 2024 1

Good find - I'll get that into all of the code this weekend ....

from az2tf.

andyt530 avatar andyt530 commented on June 27, 2024

the -s is expecting a subscription id - you can't use a subscription name

the az2th.sh - runs this command to get a list of subscriptions:

az account list --query '[].id' | jq '.[]' | tr -d '"'

Try running this command above - it should return a list of subscription id's

one of which should be a86bc126-XXXX-XXXX-XXXX-7e546be7a509

Is this so ?

from az2tf.

nexxai avatar nexxai commented on June 27, 2024

Wow, thanks for getting back to me so quickly!

➜  az2tf git:(master) az account list --query '[].id' | jq '.[]' | tr -d '"'
parse error: Invalid numeric literal at line 2, column 4

However if I do:

➜  az2tf git:(master) az account list --query '[].id' 
[
  "10963f71-XXXX-XXXX-XXXX-76109759447c",
  "464daa41-XXXX-XXXX-XXXX-5bb3ab855efb",
  "a86bc126-XXXX-XXXX-XXXX-7e546be7a509"
]

and then

➜  az2tf git:(master) az account list --query '[].id' | jq '.[]'
parse error: Invalid numeric literal at line 2, column 4

So it would seem that something is up with jq not parsing the list correctly?

I'm running the latest version:

➜  az2tf git:(master) jq --version
jq-1.6

Any ideas on what else I could check?

from az2tf.

andyt530 avatar andyt530 commented on June 27, 2024

Which Operating System are you using ?

Upgraded to jq 1.6 on my macOS - but it still works ok here.....

from az2tf.

nexxai avatar nexxai commented on June 27, 2024

macOS Mojave 10.14.2 (18C54)

from az2tf.

andyt530 avatar andyt530 commented on June 27, 2024

me too ... this is odd.
az version ?

from az2tf.

nexxai avatar nexxai commented on June 27, 2024

Ok now here's something even weirder: if I copy the text and manually pipe it through echo, it works fine:

➜  az2tf git:(master) echo '["10963f71-XXXX-XXXX-XXXX-76109759447c","464daa41-XXXX-XXXX-XXXX-5bb3ab855efb","a86bc126-XXXX-XXXX-XXXX-7e546be7a509"]' | jq '.[]'
"10963f71-XXXX-XXXX-XXXX-76109759447c"
"464daa41-XXXX-XXXX-XXXX-5bb3ab855efb"
"a86bc126-XXXX-XXXX-XXXX-7e546be7a509"
➜  az2tf git:(master) az -v     
azure-cli (2.0.52)

from az2tf.

nexxai avatar nexxai commented on June 27, 2024

For posterity's sake, I upgraded azure-cli to 2.0.54 but am still having the same problem. I've also opened a case on the jq GitHub repo (jqlang/jq#1787) in case this is something they can shed some light on.

from az2tf.

andyt530 avatar andyt530 commented on June 27, 2024

we could replace the line in az2tf.sh with:

az account list --query '[].id' | cut -f2 -d '"' | grep "-"

My concern would be that your jq issues will cause other problems as this tool uses jq everywhere !

from az2tf.

nexxai avatar nexxai commented on June 27, 2024

So yeah that definitely allowed it to proceed past the original failure point but it wasn't able to find any resource groups, etc. I think I'll wait to hear back from the jq team about what could be wrong.

from az2tf.

andyt530 avatar andyt530 commented on June 27, 2024

I installed jq with brew - did you ?

from az2tf.

nexxai avatar nexxai commented on June 27, 2024

Yeah, and I just tried uninstalling and reinstalling it, and the same thing happened.

¯\_(ツ)_/¯

from az2tf.

nexxai avatar nexxai commented on June 27, 2024

Ok so I figured out the problem: for some reason azure-cli is inserting ANSI color codes in the output before it's piped to jq. (Possibly because I'm using oh_my_zsh instead of the standard BASH shell?)

The solution is to add the option: -o json to each call of az like this:

az account list --query '[].id' -o json | jq '.[]' | tr -d '"'

which tells azure-cli to print to stdout without the color codes. I've tried adding to various combinations that you've got in your script but I still haven't figured out which ones need it and which don't. I'll keep working on it if I can find some time this week, but if you are able to check too, that would be a great help.

from az2tf.

nexxai avatar nexxai commented on June 27, 2024

Thank you so much!

from az2tf.

andyt530 avatar andyt530 commented on June 27, 2024

found some time - uploaded all the changes - let me know how you get on ?

from az2tf.

nexxai avatar nexxai commented on June 27, 2024

Oh wow, it got WAY farther this time. It generated a bunch of .tf files (PROGRESS!) but it eventually spit out this error:

Terraform Plan ...

Error: Error asking for user input: Error parsing address 'azurerm_resource_group': invalid resource address "azurerm_resource_group"

Is that a me-problem?

from az2tf.

andyt530 avatar andyt530 commented on June 27, 2024

If you didn’t - delete the tf.xxxxx-xxxx-xxxx-xxxxxx directory before you run az2tf.sh

That error looks like there may be a malformed .tf file hanging around from a previous run

from az2tf.

nexxai avatar nexxai commented on June 27, 2024

So it looks like it works beautifully (haven't found any problems) except this error is thrown near the beginning but the whole script continues and seems to work fine otherwise?

az lock list: error: argument --query: invalid jmespath_type value: '[].resourceGroup -o json'

Not sure if that's important or not?

from az2tf.

andyt530 avatar andyt530 commented on June 27, 2024

typo in az2tf.sh causing that - just posted fix. You only need to run again if you are using locks and want them terraform'ed.

from az2tf.

nexxai avatar nexxai commented on June 27, 2024

Love it!

I know we use Logic Apps, Function Apps, Data Lakes and Data Factories here pretty heavily so I'll work on adding them as scripts and will submit PRs in the next few weeks if you're OK with that? I'm leaving for holidays tomorrow so I won't have much time in the next week or two, but I'll do what I can.

Thank you again for such an awesome tool!

from az2tf.

Related Issues (15)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.