{"id":20926238,"url":"https://github.com/will8ug/demo-azure-linux-vm-terraform","last_synced_at":"2026-04-29T16:39:35.051Z","repository":{"id":248526011,"uuid":"826415552","full_name":"will8ug/demo-azure-linux-vm-terraform","owner":"will8ug","description":null,"archived":false,"fork":false,"pushed_at":"2024-07-24T13:13:51.000Z","size":258,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-13T01:16:52.443Z","etag":null,"topics":["azure","linux","terraform","virtual-machine"],"latest_commit_sha":null,"homepage":"","language":"HCL","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/will8ug.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-07-09T17:02:54.000Z","updated_at":"2024-07-24T13:13:54.000Z","dependencies_parsed_at":"2024-07-24T14:00:18.454Z","dependency_job_id":"1f27f370-5dcd-4d7c-b90a-337c7cbdf3c0","html_url":"https://github.com/will8ug/demo-azure-linux-vm-terraform","commit_stats":null,"previous_names":["will8ug/demo-azure-linux-vm-terraform"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/will8ug/demo-azure-linux-vm-terraform","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/will8ug%2Fdemo-azure-linux-vm-terraform","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/will8ug%2Fdemo-azure-linux-vm-terraform/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/will8ug%2Fdemo-azure-linux-vm-terraform/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/will8ug%2Fdemo-azure-linux-vm-terraform/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/will8ug","download_url":"https://codeload.github.com/will8ug/demo-azure-linux-vm-terraform/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/will8ug%2Fdemo-azure-linux-vm-terraform/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268047866,"owners_count":24187207,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-31T02:00:08.723Z","response_time":66,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["azure","linux","terraform","virtual-machine"],"created_at":"2024-11-18T20:37:21.143Z","updated_at":"2026-04-29T16:39:35.008Z","avatar_url":"https://github.com/will8ug.png","language":"HCL","funding_links":[],"categories":[],"sub_categories":[],"readme":"# demo-azure-linux-vm-terraform\n\n## Prerequisites\n\n* [Terraform](https://developer.hashicorp.com/terraform/install) is installed\n* [Azure CLI](https://learn.microsoft.com/en-us/cli/azure/install-azure-cli) is installed\n* A valid Azure subscription.\n    - [Get a free one](https://azure.microsoft.com/en-us/free/).\n    - [Pay as you go](https://azure.microsoft.com/en-us/pricing/purchase-options/pay-as-you-go).\n\n## Let's run it\n\n:bell: **Notice:** Don't change any `*.tfstate.*` files manually during the whole process. \nThey are managed by Terraform automatically.\n\n### 1. Setup Azure authentication\n\n```shell\naz login\n```\n\nIf you have successfully logged in, you'll see output like this:\n\n![az-login-successfully](resources/az-login-successfully.jpg)\n\nWrite down the `id` (subscription id) and `tenantId` here, you'll need them later. If you don't see or have missed the above output for some reason, you can try this command to recall it (a successful login is still required):\n\n```shell\naz account list\n```\n\nOnce you've got your subscription id and tenant id, carry on with the following steps:\n\n```shell\n# set current active subscription\naz account set --subscription \"\u003cSUBSCRIPTION_ID\u003e\"\n```\n\n```shell\n# create a service principal\naz ad sp create-for-rbac --role=\"Contributor\" --scopes=\"/subscriptions/\u003cSUBSCRIPTION_ID\u003e\"\n```\n\nWrite down the `appId` and `password` in the output. Now set some necessary environment variables.\n\nFor shell:\n\n```shell\nexport ARM_CLIENT_ID=\"\u003cAPPID_VALUE\u003e\"\nexport ARM_CLIENT_SECRET=\"\u003cPASSWORD_VALUE\u003e\"\nexport ARM_SUBSCRIPTION_ID=\"\u003cSUBSCRIPTION_ID\u003e\"\nexport ARM_TENANT_ID=\"\u003cTENANT_ID\u003e\"\n\n# check it\nprintenv | grep '^ARM*'\n```\n\nFor PowerShell:\n\n```powershell\n$Env:ARM_CLIENT_ID = \"\u003cAPPID_VALUE\u003e\"\n$Env:ARM_CLIENT_SECRET = \"\u003cPASSWORD_VALUE\u003e\"\n$Env:ARM_SUBSCRIPTION_ID = \"\u003cSUBSCRIPTION_ID\u003e\"\n$Env:ARM_TENANT_ID = \"\u003cTENANT_ID\u003e\"\n\n# check it\ngci env:ARM_*\n```\n\n### 2. Generate a pair of SSH keys for login to VM later\n\nFor PoC (Proof of Concept) test purposes, note 2 things:\n- When it prompts `Enter file in which to save the key`, better to give a specific path other than the default one, so that you will not override your default key files.\n- When it prompts `Enter passphrase`, you can press Enter directly to skip it, so it will make the test easier.\n\n```shell\nssh-keygen -t rsa\n```\n\nPut the generated public key file to this project folder (the Terraform scripts would try to find it by name of `key.pub`), and save the private key file for later use.\n\n### 3. Run Terraform to create a basic Linux VM without Bastion\n\n```shell\nterraform init\n\n# optional:\nterraform plan\n\nterraform apply\n```\n\nIf the last command `terraform apply` succeeds, you should be able to see a group of resources are generated like this:\n\n![end-of-1st-apply](resources/end-of-1st-apply.jpg)\n\nExplore anything on Azure portal if you would like to. Please note that there's no way for you to login this VM at this moment without further configuration changes.\n\n### 4. Run Terraform again to add Bastion\n\n```shell\n# This step was a bit slow according to my test (~8 mins). Please keep patient.\nterraform apply -var='create_bastion=true'\n```\n\nNow you can login the VM via Bastion referring this [guide](https://learn.microsoft.com/en-us/azure/bastion/bastion-connect-vm-ssh-linux). Select \"SSH private key from local file\", input the private key generated earlier.\n\n![login-with-bastion](resources/login-with-bastion.jpg)\n\n### 5. Destroy everything you've just created\n```shell\nterraform destroy\n```\n\n## Relevant repositories\n\n* [will8ug/basic-linux-vm](https://github.com/will8ug/basic-linux-vm)\n\n* [will8ug/demo-azure-aks-terraform](https://github.com/will8ug/demo-azure-aks-terraform)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwill8ug%2Fdemo-azure-linux-vm-terraform","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwill8ug%2Fdemo-azure-linux-vm-terraform","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwill8ug%2Fdemo-azure-linux-vm-terraform/lists"}