Google Cloud サービスは、デフォルトではプロジェクトで無効になっています。ソリューションを使用するには、以下を有効にする必要があります。
Compute Engine — 仮想マシンとネットワーク
variable"gcp_service_list"{description="The list of apis necessary for the project"type=list(string)default=["compute.googleapis.com",]}resource"google_project_service""all"{for_each=toset(var.gcp_service_list)project=var.project_numberservice=each.keydisable_dependent_services=falsedisable_on_destroy=false}
仮想マシンを作成する
VM を作成します。
resource"google_compute_instance""instance"{name=var.instance-namemachine_type=var.instance-machine-typezone=var.zoneproject=var.project_idtags=var.instance-tagsboot_disk{auto_delete=truedevice_name=var.instance-nameinitialize_params{image=var.instance-imagesize=var.instance-disksizetype=var.instance-disktype}}network_interface{network="default"access_config{ // Ephemeral public IP}}depends_on=[google_project_service.all]}
まとめ
これで、単一 VM が作成されました。SSH で接続して、必要に応じて構成します。さらに、環境に合わせてソリューションを変更または拡張するためのコードもすべて用意されています。
[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["わかりにくい","hardToUnderstand","thumb-down"],["情報またはサンプルコードが不正確","incorrectInformationOrSampleCode","thumb-down"],["必要な情報 / サンプルがない","missingTheInformationSamplesINeed","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 2025-01-14 UTC。"],[],[],null,["# Single VM\n\n+\n\n[](./images/arch-single-vm.svg)\n\nSingle VM stack creates an individual VM with a smart default, but also the ability\nto customize the Virtual Machine. It uses:\n\n- Compute - VMs - Compute Engine\n\nExample sets up a simple single virtual machine, and allows you to ssh into it.\n\n*** ** * ** ***\n\nGet Started\n-----------\n\nClick on the following link to a copy of the source code in Cloud Shell. Once\nthere, a single command will spin up a working copy of the application in your\nproject..\n| **Key Point:** Clicking on the following link will open a Cloud Shell session and download code from GitHub. You will have to authorize DeployStack to run. No actions will be taken until you do so.\n\n[](https://ssh.cloud.google.com/cloudshell/editor?cloudshell_git_repo=https://github.com/googlecloudplatform/deploystack-single-vm&shellonly=true&cloudshell_image=gcr.io/ds-artifacts-cloudshell/deploystack_custom_image)\n\n[View source code on GitHub](https://github.com/googlecloudplatform/deploystack-single-vm)\n\n*** ** * ** ***\n\nSingle VM components\n--------------------\n\nThe Single VM architecture makes use of one key product. The following highlights that product, along with more information, including links to related videos, product documentation, and interactive walkthroughs.\n\n*** ** * ** ***\n\nScripts\n-------\n\nThe install script uses an executable written in `go` and Terraform CLI tools to\ntake an empty project and install the application in it. The output should be a\nworking application and a url for the load balancing IP address.\n| **Note:** The following is a breakdown of the commands that run when deploying Single VM. *You don't need to run each command individually; Click the Open in Cloud Shell button in the Getting Started section and run all commands.*\n\n### `./main.tf`\n\n#### Enable Services\n\nGoogle Cloud Services are disabled in a project by default. In order to use any\nof the solutions here, we have to activate the following:\n\n- **Compute Engine** --- virtual machines and networking\n\n variable \"gcp_service_list\" {\n description = \"The list of apis necessary for the project\"\n type = list(string)\n default = [\n \"compute.googleapis.com\",\n ]\n }\n\n resource \"google_project_service\" \"all\" {\n for_each = toset(var.gcp_service_list)\n project = var.project_number\n service = each.key\n disable_dependent_services = false\n disable_on_destroy = false\n }\n\n#### Create a virtual machine\n\nCreates a VM. \n\n resource \"google_compute_instance\" \"instance\" {\n name = var.instance-name\n machine_type = var.instance-machine-type\n zone = var.zone\n project = var.project_id\n tags = var.instance-tags\n\n\n boot_disk {\n auto_delete = true\n device_name = var.instance-name\n initialize_params {\n image = var.instance-image\n size = var.instance-disksize\n type = var.instance-disktype\n }\n }\n\n network_interface {\n network = \"default\"\n access_config {\n // Ephemeral public IP\n }\n }\n\n depends_on = [google_project_service.all]\n }\n\n*** ** * ** ***\n\nConclusion\n----------\n\nOnce run, you should now have a single VM. You can ssh into it and configure it\nhowever you'd like. Additionally you should have all of the code to modify\nor extend this solution to fit your environment."]]