Hashicorp Terraform은 클라우드 인프라를 프로비저닝하고 관리할 수 있게 해주는 코드형 인프라(IaC) 도구입니다. Terraform은 클라우드 제공업체 및 기타 API와 상호작용할 수 있는 제공업체라는 플러그인을 제공합니다. Google Cloud용 Terraform 제공업체(Google Cloud 제공업체)를 사용하여 Google Cloud인프라를 프로비저닝하고 관리할 수 있습니다.
Terraform 사용의 이점
이 섹션에서는 Terraform을 사용하여 Google Cloud 인프라를 프로비저닝하고 관리할 때의 몇 가지 이점에 대해 설명합니다.
Terraform은Google Cloud 인프라를 프로비저닝하고 자동화하는 데 가장 일반적으로 사용되는 도구입니다. Google Cloud제공업체를 사용하여 동일한 선언적 문법과 도구로 모든 Google Cloud 리소스를 구성하고 관리할 수 있습니다.
Terraform을 사용하면 인프라에 대해 원하는 최종 상태를 지정할 수 있습니다.
그런 다음 동일한 구성을 여러 번 배포하여 재현 가능한 개발, 테스트, 프로덕션 환경을 만들 수 있습니다.
Terraform을 사용하면 구성을 적용할 때 Terraform이 수행할 작업을 보여주는 실행 계획을 생성할 수 있습니다. 이렇게 하면 Terraform을 통해 인프라를 수정할 때 예상치 못한 상황을 방지할 수 있습니다.
Terraform을 사용하면 모듈 형태로 공통 코드를 패키징하고 재사용할 수 있습니다.
모듈은 클라우드 리소스를 만들기 위한 표준 인터페이스를 제공합니다. 이는 가독성을 높여 프로젝트를 단순화하며 팀이 읽을 수 있는 블록으로 인프라를 구성할 수 있도록 합니다. 또한 Google Cloud는 배포 가능한 독자적인 여러 모듈을 청사진으로 게시하고 시작하는 예시를 점프 스타트 솔루션으로 게시합니다.
Terraform은 인프라의 현재 상태를 기록하고 상태를 효과적으로 관리할 수 있게 해줍니다. Terraform 상태 파일은 배포의 모든 리소스를 추적합니다.
Terraform 사용
Terraform에는 프로비저닝할 인프라를 작성하는 데 사용할 수 있는 선언적이고 구성 중심인 구문이 있습니다. 이 구문을 사용하면 Terraform 구성 파일에서 인프라의 기본 최종 상태를 정의합니다. 그런 후 Terraform CLI를 사용하여 구성 파일을 기반으로 인프라를 프로비저닝합니다.
다음 단계에서는 Terraform의 작동 방식을 설명합니다.
Terraform 구성 파일에서 프로비저닝할 Google Cloud 인프라를 설명합니다. 이 구성을 프로비저닝하는 방법을 설명하는 코드를 작성할 필요가 없습니다.
terraform plan 명령어를 실행합니다. 이 명령어는 구성을 평가하고 실행 계획을 생성합니다. 계획을 검토하고 필요에 따라 변경할 수 있습니다.
그런 다음 terraform apply 명령어를 실행하여 다음 작업을 수행합니다.
백그라운드에서 해당 Google Cloud API를 호출하여 실행 계획에 따라 인프라를 프로비저닝합니다.
구성 파일의 리소스를 실제 인프라의 리소스에 매핑한 JSON 형식인 Terraform 상태 파일을 만듭니다. Terraform은 이 파일을 사용하여 인프라의 최신 상태를 확인하고 리소스를 생성, 업데이트, 삭제할 시기를 결정합니다.
이후에 terraform apply를 실행하면 Terraform은 상태 파일의 매핑을 사용하여 기존 인프라를 코드와 비교하고 필요에 따라 업데이트합니다.
구성 파일에 정의된 리소스 객체가 상태 파일에 존재하지 않는 경우 Terraform이 이를 만듭니다.
리소스 객체가 상태 파일에 있지만 구성 파일의 구성과 다른 경우 Terraform은 구성 파일과 일치하도록 리소스를 업데이트합니다.
상태 파일의 리소스 객체가 구성 파일과 일치하면 Terraform은 리소스를 변경하지 않은 상태로 둡니다.
Google Cloud 제공업체
Google Cloud인프라를 프로비저닝하고 관리할 수 있는 제공업체에는 두 가지가 있습니다.
google: 이 제공업체를 사용하여 Google Cloud API를 프로비저닝하고 관리합니다.
google-beta: 이 제공업체를 사용하여 Google Cloud베타 API를 프로비저닝하고 관리합니다.
[[["이해하기 쉬움","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-09-04(UTC)"],[[["\u003cp\u003eTerraform is an Infrastructure as Code (IaC) tool for provisioning and managing cloud infrastructure, particularly effective for Google Cloud through its dedicated providers.\u003c/p\u003e\n"],["\u003cp\u003eUsing Terraform on Google Cloud offers benefits such as creating reproducible environments, generating execution plans, reusing code through modules, and effectively managing the state of your infrastructure.\u003c/p\u003e\n"],["\u003cp\u003eTerraform utilizes a declarative syntax where you define your desired infrastructure end-state, and it uses its CLI to provision and manage your configuration accordingly.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eterraform apply\u003c/code\u003e command provisions infrastructure based on an execution plan, interfacing with Google Cloud APIs and maintaining a state file to track resource changes.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003egoogle\u003c/code\u003e and \u003ccode\u003egoogle-beta\u003c/code\u003e providers are used to provision and manage both general and beta Google Cloud APIs, respectively, and are developed using the Magic Modules tool.\u003c/p\u003e\n"]]],[],null,["# Overview of Terraform on Google Cloud\n\nHashicorp Terraform is an Infrastructure as code (IaC) tool that lets you\nprovision and manage cloud infrastructure. Terraform provides plugins called\n*providers* that lets you interact with cloud providers and other\nAPIs. You can use the *Terraform provider for Google Cloud*\n(*Google Cloud provider*) to provision and manage Google Cloud\ninfrastructure.\n\nBenefits of using Terraform\n---------------------------\n\nThis section explains some of the benefits of using Terraform to provision and\nmanage Google Cloud infrastructure:\n\n- Terraform is the most commonly used tool to provision and automate Google Cloud infrastructure. You can use the [Google Cloud\n provider](https://registry.terraform.io/providers/hashicorp/google/latest/docs) to configure and manage all Google Cloud resources using the same declarative syntax and tooling.\n- Terraform lets you specify your preferred end state for your infrastructure. You can then deploy the same configuration multiple times to create reproducible development, test, and production environments.\n- Terraform lets you generate an execution plan that shows what Terraform will do when you apply your configuration. This lets you avoid any surprises when you modify your infrastructure through Terraform.\n- Terraform lets you package and reuse common code in the form of [modules](https://registry.terraform.io/namespaces/terraform-google-modules). Modules present standard interfaces for creating cloud resources. They simplify projects by increasing readability and allow teams to organize infrastructure in readable blocks. Additionally, Google Cloud publishes a number of opinionated deployable modules as [blueprints](/docs/terraform/blueprints/terraform-blueprints) and getting-started examples as [Jump Start\n Solutions](/solutions?jump-start-solutions#section-3).\n- Terraform records the current state of your infrastructure and lets you manage state effectively. The Terraform state file keeps track of all resources in a deployment.\n\nUsing Terraform\n---------------\n\nTerraform has a declarative and configuration-oriented syntax, which you can use\nto [author the infrastructure](https://developer.hashicorp.com/terraform/language)\nthat you want to provision. Using this syntax, you'll define your preferred\nend-state for your infrastructure in a *Terraform configuration file* . You'll then\nuse the [Terraform CLI](/docs/terraform/basic-commands) to provision\ninfrastructure based on the configuration file.\n\nThe following steps explain how Terraform works:\n\n1. You describe the Google Cloud infrastructure you want to provision in a Terraform configuration file. You don't need to author code describing *how* to provision this configuration.\n2. You run the `terraform plan` command, which evaluates your configuration and generates an execution plan. You can review the plan and make changes as needed.\n3. Then, you run the `terraform apply` command, which performs the following actions:\n - It provisions your infrastructure based on your execution plan by invoking the corresponding Google Cloud APIs in the background.\n - It creates a *Terraform state file*, which is a JSON formatted mapping of resources in your configuration file to the resources in the real world infrastructure. Terraform uses this file to know the latest state of your infrastructure, and to determine when to create, update, and destroy resources.\n4. Subsequently, when you run `terraform apply`, Terraform uses the mapping in the state file to compare the existing infrastructure to the code, and make updates as necessary:\n - If a resource object defined in the configuration file does not exist in the state file, Terraform creates it.\n - If a resource object exists in the state file, but has a different configuration from your configuration file, Terraform updates the resource to match your configuration file.\n - If a resource object in the state file matches your configuration file, Terraform leaves the resource unchanged.\n\nGoogle Cloud providers\n----------------------\n\nThere are two providers that let you provision and manage Google Cloud\ninfrastructure:\n\n- `google`: Use this provider to provision and manage Google Cloud APIs.\n- `google-beta`: Use this provider to provision and manage Google Cloud beta APIs.\n\nFor instructions on using these providers, see the\n[Google Cloud provider configuration reference](https://registry.terraform.io/providers/hashicorp/google/latest/docs/guides/provider_reference).\n\n`google` and `google-beta` providers are developed using a tool called\n*Magic Modules* . Magic Modules allows contributors to make changes against a\nsingle codebase and develop both `google` and `google-beta` providers\nsimultaneously.\n\nYou can contribute to the Google Cloud providers using Magic Modules\nby following the instructions in the\n[Magic Modules contribution guide](https://googlecloudplatform.github.io/magic-modules/get-started/generate-providers/).\n\nWhat's next\n-----------\n\n- Learn how to [create a basic web server on Compute Engine using Terraform](/docs/terraform/get-started-with-terraform)\n- Learn how to [store Terraform state in a Cloud Storage bucket](/docs/terraform/resource-management/store-state)\n- Look through the various [Terraform for Google Cloud samples](/docs/samples?language=terraform)\n- Look through the [Terraform modules and blueprints for Google Cloud](/docs/terraform/blueprints/terraform-blueprints)"]]