설치 스크립트는 go 및 Terraform CLI 도구로 작성된 실행 파일을 사용하여 빈 프로젝트를 가져오고 여기에 애플리케이션을 설치합니다. 출력은 작동하는 애플리케이션과 부하 분산 IP 주소의 URL입니다.
./main.tf
서비스 사용 설정
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."]]