Home
%3CLINGO-SUB%20id%3D%22lingo-sub-393845%22%20slang%3D%22en-US%22%3EConfiguring%20Terraform%20on%20Windows%2010%20Linux%20Sub-System%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-393845%22%20slang%3D%22en-US%22%3E%3CP%3EWant%20to%20%3CA%20href%3D%22https%3A%2F%2Fwww.terraform.io%2F%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3ETerraform%3C%2FA%3E%20using%20Visual%20Studio%20Code%20on%20Linux%20but%20have%20a%20Windows%2010%20machine%3F%26nbsp%3B%26nbsp%3B%20Follow%20these%20easy%20steps%20to%20quickly%20get%20your%20environment%20up%20in%20running.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%3CA%20id%3D%22step1%22%20target%3D%22_blank%22%3E%3C%2FA%3EStep%201%3A%3C%2FSTRONG%3E%20Install%20Visual%20Studio%20Code%20-%20%3CA%20href%3D%22https%3A%2F%2Fcode.visualstudio.com%2Fdownload%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fcode.visualstudio.com%2Fdownload%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%3CA%20id%3D%22step2%22%20target%3D%22_blank%22%3E%3C%2FA%3EStep%202%3A%3C%2FSTRONG%3E%20Install%20Windows%20Subsystem%20on%20your%20Windows%2010%20Machine.%26nbsp%3B%20I%20tend%20to%20lean%20towards%20%3CA%20href%3D%22https%3A%2F%2Fwww.microsoft.com%2Fen-us%2Fp%2Fubuntu%2F9nblggh4msv6%3Frtc%3D1%26amp%3Bactivetab%3Dpivot%3Aoverviewtab%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3EUbuntu%3C%2FA%3E%2C%20however%20there%20are%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fwindows%2Fwsl%2Finstall-win10%23install-your-linux-distribution-of-choice%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Eseveral%20distros%3C%2FA%3E%20to%20choose%20from.%26nbsp%3B%26nbsp%3B%20This%20article%20will%20walk%26nbsp%3B%20you%20through%20installing%20the%20Windows%20Subsystem%20for%20Linux%20-%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fwindows%2Fwsl%2Finstall-win10%23install-the-windows-subsystem-for-linux%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fwindows%2Fwsl%2Finstall-win10%23install-the-windows-subsystem-for-linux%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EOnce%20the%20subsystem%20is%20installed%20please%20ensure%20its%20updated.%26nbsp%3B%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3EClick%20Start%3C%2FLI%3E%0A%3CLI%3ESearch%20for%20Ubuntu%20(or%20your%20installed%20distro)%20and%20open%3C%2FLI%3E%0A%3CLI%3ERun%20the%20following%20commands%20to%20make%20sure%20Ubuntu%20is%20updated%3A%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CPRE%3Esudo%20apt-get%20update%20%0Asudo%20apt-get%20upgrade%20%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%3CA%20id%3D%22step3%22%20target%3D%22_blank%22%3E%3C%2FA%3EStep%203%3A%3C%2FSTRONG%3E%20Install%20Visual%20Studio%20Code%20Terraform%20Extension%20which%20will%20allow%20you%20to%20have%20intelli-sense%20and%20support%20for%20the%20different%20Terraform%20file%20types..%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3EOpen%20this%20%3CA%20href%3D%22https%3A%2F%2Fmarketplace.visualstudio.com%2Fitems%3FitemName%3Dms-azuretools.vscode-azureterraform%2520%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Elink.%3C%2FA%3E%3C%2FLI%3E%0A%3CLI%3EClick%20Install%3C%2FLI%3E%0A%3CLI%3EReload%20VScode%20window%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%3CSTRONG%3E%3CA%20id%3D%22step4%22%20target%3D%22_blank%22%3E%3C%2FA%3EStep%204%3A%3C%2FSTRONG%3E%20Will%20walk%20you%20through%20how%20to%20download%2C%20extract%20and%20install%20Terraform%20on%20the%20Linux%20Sub-System%20using%20the%20terminal.%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3EOpen%20Ubuntu%20application%20(or%20your%20installed%20distro)%3C%2FLI%3E%0A%3CLI%3ERun%20the%20following%20command%20which%20will%20install%20unzip%20(its%20my%20preference%20to%20extract%20files)%3CBR%20%2F%3E%0A%3CPRE%3Esudo%20apt-get%20install%20unzip%3C%2FPRE%3E%0A%3C%2FLI%3E%0A%3CLI%3ENavigate%20to%20the%20Terraform%20%3CA%20href%3D%22https%3A%2F%2Fwww.terraform.io%2Fdownloads.html%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Edownload%20page%3C%2FA%3E%20and%20grab%20the%20most%20recent%20download%20URL.%3C%2FLI%3E%0A%3CLI%3EUsing%20the%20above%20URL%2C%20run%20the%20following%20commands%20which%20will%20download%2C%20unzip%2C%20move%20the%20binary%20to%20users%20bin.%3CBR%20%2F%3E%0A%3CPRE%3Ewget%20%3CSTRONG%3E%3CTERRAFORM_URL%3E%3C%2FTERRAFORM_URL%3E%3C%2FSTRONG%3E%20-O%20terraform.zip%3B%0Aunzip%20terraform.zip%3B%0Asudo%20mv%20terraform%20%2Fusr%2Flocal%2Fbin%3B%0Arm%20terraform.zip%3B%3C%2FPRE%3E%0A%3CEM%3Eexample%3A%3C%2FEM%3E%3CBR%20%2F%3E%0A%3CPRE%3Ewget%20https%3A%2F%2Freleases.hashicorp.com%2Fterraform%2F0.11.13%2Fterraform_0.11.13_linux_amd64.zip%20-O%20terraform.zip%3B%20%0Aunzip%20terraform.zip%3B%20%0Asudo%20mv%20terraform%20%2Fusr%2Flocal%2Fbin%3B%20%0Arm%20terraform.zip%3B%3C%2FPRE%3E%0A%3C%2FLI%3E%0A%3CLI%20dir%3D%22ltr%22%3ERun%20the%20following%20command%20to%20verify%20terraform%20is%20installed.%3CBR%20%2F%3E%0A%3CPRE%3Eterraform%20-v%3C%2FPRE%3E%0A%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%3CBR%20%2F%3E%3CSTRONG%3E%3CA%20id%3D%22step5%22%20target%3D%22_blank%22%3E%3C%2FA%3EStep%205%3A%3C%2FSTRONG%3E%26nbsp%3B%20Terraform%20can%20authenticate%20a%20few%20%3CA%20href%3D%22https%3A%2F%2Fwww.terraform.io%2Fdocs%2Fproviders%2Fazurerm%2F%23authenticating-to-azure%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Edifferent%20ways%3C%2FA%3E.%26nbsp%3B%20For%20this%20example%20we%20will%20use%20%3CA%20href%3D%22https%3A%2F%2Fwww.terraform.io%2Fdocs%2Fproviders%2Fazurerm%2Fauth%2Fazure_cli.html%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3EAzure%20CLI%3C%2FA%3E%2C%20which%20needs%20to%20be%20installed%20on%20the%20linux%20sub-system.%26nbsp%3B%20Steps%20to%20install%20on%20several%20different%20distros%20can%20be%20found%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fcli%2Fazure%2Finstall-azure-cli%3Fview%3Dazure-cli-latest%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehere.%3C%2FA%3E%26nbsp%3B%20If%20you%20installed%20Ubuntu%20in%20Step%202%20then%20you%20can%20following%20these%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fcli%2Fazure%2Finstall-azure-cli-apt%3Fview%3Dazure-cli-latest%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Esteps%3C%2FA%3E.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EVerify%20that%20Azure%20CLI%20was%20installed%20correctly%20by%20running%20the%20following%3A%3C%2FP%3E%0A%3CPRE%3Eaz%20-v%3C%2FPRE%3E%0A%3CP%3E%3CSTRONG%3EStep%206%3A%26nbsp%3B%3C%2FSTRONG%3E%20Log%20in%20to%20Azure%20CLI%20for%20your%20target%20environment%20by%20running%20the%20below%20command.%26nbsp%3B%20If%20successful%20it%20should%20launch%20a%20browser%20window.%3C%2FP%3E%0A%3CPRE%3Eaz%20login%3C%2FPRE%3E%0A%3CP%3EEnter%20your%20credentials%20in%20the%20browser%20window%20and%20walk%20through%20the%20MFA%20process%20(if%20enabled).%26nbsp%3B%20Once%3C%2FP%3E%0A%3CP%3Eyou%20sign%20in%20your%20browser%20window%20should%20look%20like...%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F105918iB373D78F397908F5%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20alt%3D%222019-04-05_10h05_19.png%22%20title%3D%222019-04-05_10h05_19.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20Azure%20CLI%20window%20should%20now%20say%20your%20logged%20in%20and%20will%20automatically%20list%20all%20subscriptions%20you%20have%20access.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ERun%20the%20following%20command%20to%20show%20all%20subscriptions.%3C%2FP%3E%0A%3CPRE%3Eaz%20account%20list%20-o%20table%3C%2FPRE%3E%0A%3CP%3ELocate%20the%20subscription%20that%20you%20want%20to%20target%20and%20copy%20the%20subscription%20guid%20to%20your%20clipboard.%20Run%20the%20following%20command%20to%20set%20the%20subscription%20as%20your%20active%20account.%3C%2FP%3E%0A%3CPRE%3Eaz%20account%20set%20-s%20%3CSTRONG%3E%3CSUBSCRIPTION_GUID%3E%3C%2FSUBSCRIPTION_GUID%3E%3C%2FSTRONG%3E%3B%20az%20account%20show%20-o%20table%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ENow%20that%20we%20have%20completed%20the%20below%20steps%20we%20are%20ready%20to%20move%20onto%20%3CA%20href%3D%22%23wwt%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Eworking%20with%20Terraform%3C%2FA%3E%20in%20Visual%20Studio%20Code.%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3E%3CA%20href%3D%22%23step1%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3EInstalled%3C%2FA%3E%20Visual%20Studio%20Code%3C%2FLI%3E%0A%3CLI%3E%3CA%20href%3D%22%23step2%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3EInstalled%3C%2FA%3E%20Linux%20Sub-system%20on%20Windows%2010%3C%2FLI%3E%0A%3CLI%3E%3CA%20href%3D%22%23step3%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3EInstalled%3C%2FA%3E%20Visual%20Studio%20Code%20Terraform%20Extension%3C%2FLI%3E%0A%3CLI%3E%3CA%20href%3D%22%23step4%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3EInstalled%3C%2FA%3E%20Terraform%20in%20Linux%20Sub-system%3C%2FLI%3E%0A%3CLI%3E%3CA%20href%3D%22%23step5%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3EInstalled%3C%2FA%3E%20Azure%20CLI%20and%20Authenticated%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CA%20id%3D%22wwt%22%20target%3D%22_blank%22%3E%3C%2FA%3EWorking%20with%20Terraform...%26nbsp%3B%20In%20this%20example%20we%20will%20deploy%20a%20simple%20Resource%20Group%20from%20Visual%20Studio%20Code%20leveraging%20Terraform%20and%20Azure%20CLI%20on%20the%20Linux%20Sub-system.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3ELaunch%20Visual%20Studio%20Code.%3C%2FLI%3E%0A%3CLI%3EGo%20to%20the%20%3CSTRONG%3ETerminal%20%3C%2FSTRONG%3Emenu%20and%20select%20%3CSTRONG%3ENew%20Terminal%3C%2FSTRONG%3E%20which%20will%20launch%20a%20terminal%20at%20the%20bottom.%20By%20default%2C%20the%20terminal%20is%20set%20to%20%3CSTRONG%3Epowershell%3C%2FSTRONG%3E%2C%20type%3CSTRONG%3E%20bash%3C%2FSTRONG%3E%20to%20switch%20the%20terminal%20to%20bash%20shell.%26nbsp%3B%20You%20can%20make%20this%20permanent%20by%20modify%20a%20%3CA%20href%3D%22https%3A%2F%2Fcode.visualstudio.com%2Fdocs%2Feditor%2Fintegrated-terminal%23_configuration%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Efew%20settings%3C%2FA%3E%20in%20Visual%20Studio%20Code.%3CBR%20%2F%3E%3CEM%3E*Take%20note%20that%20your%20terminal%20path%20should%20now%20show%20the%20path%20from%20the%20Linux%20sub-system%20to%20your%20folder%20or%20current%20directory%20on%20your%20windows%20machine.%26nbsp%3B%20Just%20because%20your%20using%20bash%20doesn't%20mean%20your%20code%20needs%20to%20reside%20in%20the%20Linux%20sub-system%2C%20although%20it%20can.%26nbsp%3B%20It%20is%20my%20preference%20to%20have%20my%20code%20in%20a%20windows%20directory%20tied%20to%20a%20Git%20repo.%3CBR%20%2F%3E%3C%2FEM%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F105940i5A7718A28D29050F%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20alt%3D%222019-04-05_10h34_15.png%22%20title%3D%222019-04-05_10h34_15.png%22%20%2F%3E%3C%2FSPAN%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3C%2FLI%3E%0A%3CLI%3ECreate%20a%20folder%20on%20your%20computer%20called%20%3CSTRONG%3ETerraform%20Example%20%3C%2FSTRONG%3E(note%20the%20path).%3C%2FLI%3E%0A%3CLI%3EFrom%20Visual%20Studio%20Code%2C%20open%20the%20folder%20from%20File%20%26gt%3B%20Open%20Folder.%26nbsp%3B%26nbsp%3B%20You%20will%20need%20to%20reopen%20the%20terminal%20window%20and%20switch%20to%20bash%20%3CEM%3E(step%202%20from%20above)%3C%2FEM%3E.%3C%2FLI%3E%0A%3CLI%3ECreate%20a%20file%20inside%20of%20the%20folder%20with%20a%20name%20of%20%3CSTRONG%3Eresource_group.tf%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3CLI%3EPaste%20the%20following%20TCL%20code%20in%20the%20resource_group.tf%3CBR%20%2F%3E%0A%3CPRE%3Eresource%20%22azurerm_resource_group%22%20%22rg%22%20%7B%0A%20%20name%20%20%20%20%20%3D%20%22rg_test%22%0A%20%20location%20%3D%20%22West%20US%22%0A%0A%20%20tags%20%3D%20%7B%0A%20%20%20%20environment%20%3D%20%22Terraform%20Test%20RG%22%0A%20%20%7D%0A%7D%0A%3C%2FPRE%3E%0AYour%20vs-code%20window%20should%20look%20like%20this%3A%3CBR%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F105941iD19AD4160757EE53%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%222019-04-05_10h47_47.png%22%20title%3D%222019-04-05_10h47_47.png%22%20%2F%3E%3C%2FSPAN%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3C%2FLI%3E%0A%3CLI%3ERun%20a%20%3CA%20href%3D%22https%3A%2F%2Fwww.terraform.io%2Fdocs%2Fcommands%2Finit.html%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Eterraform%20init%3C%2FA%3E%20from%20the%20terminal%20which%20will%20prepare%20Terraform%20in%20this%20directory.%20%3CBR%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20style%3D%22width%3A%20580px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F105942i65D472393E64F586%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%222019-04-05_10h52_44.png%22%20title%3D%222019-04-05_10h52_44.png%22%20%2F%3E%3C%2FSPAN%3E%0A%3CP%3EBased%20on%20the%20code%20Terraform%20knows%20that%20we%20need%20the%20azurerm%20provider%20and%20automatically%20downloads%20it.%3C%2FP%3E%0A%3C%2FLI%3E%0A%3CLI%3ELets%20run%20our%20first%20plan%20to%20see%20what%20changes%20Terraform%20has%20pending.%3CBR%20%2F%3E%0A%3CPRE%3Eterraform%20plan%0A%3C%2FPRE%3E%0A%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20style%3D%22width%3A%20602px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F105945i8BDDBEF3F67D7317%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%222019-04-05_11h16_45.png%22%20title%3D%222019-04-05_11h16_45.png%22%20%2F%3E%3C%2FSPAN%3E%3CBR%20%2F%3E%3CEM%3EAs%20we%20can%20see%20the%20only%20pending%20change%20is%20the%20resource%20group%20called%20rg_test.%3CBR%20%2F%3E%3C%2FEM%3E%3C%2FLI%3E%0A%3CLI%3ENow%20that%20we%20have%20evaluated%20the%20plan%20we%20can%20run%20a%20apply.%3CBR%20%2F%3E%0A%3CPRE%3Eterraform%20apply%3C%2FPRE%3E%0A%3C%2FLI%3E%0A%3CLI%3EWhen%20prompted%20type%20yes%20to%20apply%20the%20the%20changes%20shown.%3CBR%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20style%3D%22width%3A%20954px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F105949i8CB38A4ACB68C1D0%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%222019-04-05_11h36_13.png%22%20title%3D%222019-04-05_11h36_13.png%22%20%2F%3E%3C%2FSPAN%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3C%2FLI%3E%0A%3CLI%3ERun%20this%20command%20to%20show%20the%20resource%20group%20which%20was%20just%20created%20or%20open%20the%20portal%20to%20validate.%3CBR%20%2F%3E%0A%3CPRE%3Eaz%20group%20list%20--query%20%22%5B%3Fname%3D%3D'rg_test'%5D%22%3C%2FPRE%3E%0A%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20style%3D%22width%3A%20715px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F105955i51DAC5718637C845%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%222019-04-05_11h48_04.png%22%20title%3D%222019-04-05_11h48_04.png%22%20%2F%3E%3C%2FSPAN%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-393845%22%20slang%3D%22en-US%22%3E%3CP%3EWant%20to%20Terraform%20using%20Visual%20Studio%20Code%20on%20Linux%20but%20have%20a%20Windows%2010%20machine%3F%26nbsp%3B%26nbsp%3B%20Follow%20these%20easy%20steps%20to%20quickly%20get%20your%20environment%20up%20in%20running.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F105941iD19AD4160757EE53%2Fimage-dimensions%2F999x640%3Fv%3D1.0%22%20width%3D%22999%22%20height%3D%22640%22%20alt%3D%222019-04-05_10h47_47.png%22%20title%3D%222019-04-05_10h47_47.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-393845%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAzure%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ETerraform%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Microsoft

Want to Terraform using Visual Studio Code on Linux but have a Windows 10 machine?   Follow these easy steps to quickly get your environment up in running.

 

Step 1: Install Visual Studio Code - https://code.visualstudio.com/download

 

Step 2: Install Windows Subsystem on your Windows 10 Machine.  I tend to lean towards Ubuntu, however there are several distros to choose from.   This article will walk  you through installing the Windows Subsystem for Linux - https://docs.microsoft.com/en-us/windows/wsl/install-win10#install-the-windows-subsystem-for-linux

 

Once the subsystem is installed please ensure its updated. 

  1. Click Start
  2. Search for Ubuntu (or your installed distro) and open
  3. Run the following commands to make sure Ubuntu is updated:
sudo apt-get update 
sudo apt-get upgrade 

 

Step 3: Install Visual Studio Code Terraform Extension which will allow you to have intelli-sense and support for the different Terraform file types..

  1. Open this link.
  2. Click Install
  3. Reload VScode window

Step 4: Will walk you through how to download, extract and install Terraform on the Linux Sub-System using the terminal.

  1. Open Ubuntu application (or your installed distro)
  2. Run the following command which will install unzip (its my preference to extract files)
    sudo apt-get install unzip
  3. Navigate to the Terraform download page and grab the most recent download URL.
  4. Using the above URL, run the following commands which will download, unzip, move the binary to users bin.
    wget <terraform_url> -O terraform.zip;
    unzip terraform.zip;
    sudo mv terraform /usr/local/bin;
    rm terraform.zip;
    example:
    wget https://releases.hashicorp.com/terraform/0.11.13/terraform_0.11.13_linux_amd64.zip -O terraform.zip; 
    unzip terraform.zip; 
    sudo mv terraform /usr/local/bin; 
    rm terraform.zip;
  5. Run the following command to verify terraform is installed.
    terraform -v


Step 5:  Terraform can authenticate a few different ways.  For this example we will use Azure CLI, which needs to be installed on the linux sub-system.  Steps to install on several different distros can be found here.  If you installed Ubuntu in Step 2 then you can following these steps.

 

Verify that Azure CLI was installed correctly by running the following:

az -v

Step 6:  Log in to Azure CLI for your target environment by running the below command.  If successful it should launch a browser window.

az login

Enter your credentials in the browser window and walk through the MFA process (if enabled).  Once

you sign in your browser window should look like...

 

2019-04-05_10h05_19.png

 

The Azure CLI window should now say your logged in and will automatically list all subscriptions you have access.

 

Run the following command to show all subscriptions.

az account list -o table

Locate the subscription that you want to target and copy the subscription guid to your clipboard. Run the following command to set the subscription as your active account.

az account set -s <subscription_guid>; az account show -o table

 

Now that we have completed the below steps we are ready to move onto working with Terraform in Visual Studio Code.

 

Working with Terraform...  In this example we will deploy a simple Resource Group from Visual Studio Code leveraging Terraform and Azure CLI on the Linux Sub-system.

 

  1. Launch Visual Studio Code.
  2. Go to the Terminal menu and select New Terminal which will launch a terminal at the bottom. By default, the terminal is set to powershell, type bash to switch the terminal to bash shell.  You can make this permanent by modify a few settings in Visual Studio Code.
    *Take note that your terminal path should now show the path from the Linux sub-system to your folder or current directory on your windows machine.  Just because your using bash doesn't mean your code needs to reside in the Linux sub-system, although it can.  It is my preference to have my code in a windows directory tied to a Git repo.
    2019-04-05_10h34_15.png

     

  3. Create a folder on your computer called Terraform Example (note the path).
  4. From Visual Studio Code, open the folder from File > Open Folder.   You will need to reopen the terminal window and switch to bash (step 2 from above).
  5. Create a file inside of the folder with a name of resource_group.tf
  6. Paste the following TCL code in the resource_group.tf
    resource "azurerm_resource_group" "rg" {
      name     = "rg_test"
      location = "West US"
    
      tags = {
        environment = "Terraform Test RG"
      }
    }
    
    Your vs-code window should look like this:
    2019-04-05_10h47_47.png

     

  7. Run a terraform init from the terminal which will prepare Terraform in this directory.
    2019-04-05_10h52_44.png

    Based on the code Terraform knows that we need the azurerm provider and automatically downloads it.

  8. Lets run our first plan to see what changes Terraform has pending.
    terraform plan
    
    2019-04-05_11h16_45.png
    As we can see the only pending change is the resource group called rg_test.
  9. Now that we have evaluated the plan we can run a apply.
    terraform apply
  10. When prompted type yes to apply the the changes shown.
    2019-04-05_11h36_13.png

     

  11. Run this command to show the resource group which was just created or open the portal to validate.
    az group list --query "[?name=='rg_test']"
    2019-04-05_11h48_04.png