Terraform을 사용하여 워크플로 만들기
이 빠른 시작에서는 Terraform을 사용하여 첫 번째 워크플로를 생성, 배포, 실행하는 방법을 보여줍니다. Terraform은 코드를 사용하여 클라우드 인프라를 예측적으로 생성, 변경, 개선할 수 있게 해주는 코드형 인프라 도구입니다. Terraform을 사용하여 Google Cloud에서 인프라를 프로비저닝하는 방법을 알아봅니다.
이 빠른 시작에서 샘플 워크플로는 공개 API에 요청을 전송한 후 API의 응답을 반환합니다.
다음을 완료합니다.
- Terraform을 사용하여 Workflows API를 사용 설정합니다.
- Terraform을 사용하여 워크플로의 서비스 계정을 만듭니다.
- Terraform을 사용하여 워크플로를 정의하고 배포합니다.
- Google Cloud CLI를 사용하여 워크플로를 실행합니다.
시작하기 전에
조직에서 정의한 보안 제약조건으로 인해 다음 단계를 완료하지 못할 수 있습니다. 문제 해결 정보는 제한된 Google Cloud 환경에서 애플리케이션 개발을 참조하세요.
Cloud Shell에는 Terraform이 이미 통합되어 있습니다. Terraform을 설치해야 하는 경우 HashiCorp Terraform 문서를 참조하세요.
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
-
Install the Google Cloud CLI.
-
외부 ID 공급업체(IdP)를 사용하는 경우 먼저 제휴 ID로 gcloud CLI에 로그인해야 합니다.
-
gcloud CLI를 초기화하려면, 다음 명령어를 실행합니다.
gcloud init -
Create or select a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Create a Google Cloud project:
gcloud projects create PROJECT_ID
Replace
PROJECT_IDwith a name for the Google Cloud project you are creating. -
Select the Google Cloud project that you created:
gcloud config set project PROJECT_ID
Replace
PROJECT_IDwith your Google Cloud project name.
-
이 가이드에 기존 프로젝트를 사용하는 경우 이 가이드를 완료하는 데 필요한 권한이 있는지 확인합니다. 새 프로젝트를 만든 경우 필요한 권한이 이미 있습니다.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Cloud Resource Manager, Identity and Access Management (IAM), and Service Usage APIs:
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles.gcloud services enable cloudresourcemanager.googleapis.com
iam.googleapis.com serviceusage.googleapis.com -
Install the Google Cloud CLI.
-
외부 ID 공급업체(IdP)를 사용하는 경우 먼저 제휴 ID로 gcloud CLI에 로그인해야 합니다.
-
gcloud CLI를 초기화하려면, 다음 명령어를 실행합니다.
gcloud init -
Create or select a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Create a Google Cloud project:
gcloud projects create PROJECT_ID
Replace
PROJECT_IDwith a name for the Google Cloud project you are creating. -
Select the Google Cloud project that you created:
gcloud config set project PROJECT_ID
Replace
PROJECT_IDwith your Google Cloud project name.
-
이 가이드에 기존 프로젝트를 사용하는 경우 이 가이드를 완료하는 데 필요한 권한이 있는지 확인합니다. 새 프로젝트를 만든 경우 필요한 권한이 이미 있습니다.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Cloud Resource Manager, Identity and Access Management (IAM), and Service Usage APIs:
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles.gcloud services enable cloudresourcemanager.googleapis.com
iam.googleapis.com serviceusage.googleapis.com -
프로젝트 IAM 관리자(
roles/resourcemanager.projectIamAdmin) -
서비스 계정 관리자(
roles/iam.serviceAccountAdmin) -
서비스 계정 사용자(
roles/iam.serviceAccountUser) -
Workflows 관리자 (
roles/workflows.admin) 디렉터리를 만듭니다.
mkdir terraformterraform디렉터리로 이동합니다.cd terraform
새 파일
main.tf를 디렉터리에 추가합니다.nano main.tfmain.tf파일에 다음 리소스를 추가합니다.프로젝트 ID를 할당합니다.
provider "google" { project = "PROJECT_ID" }
PROJECT_ID를 프로젝트 ID로 바꿉니다.Workflows API를 사용 설정합니다.
워크플로의 서비스 계정을 만듭니다.
google_workflows_workflow리소스를 사용하여 워크플로를 정의합니다.샘플 워크플로에서는 다음 인수가 사용됩니다.
name: 워크플로의 이름입니다.region: 워크플로의 위치입니다.description: 워크플로에 대한 설명입니다.service_account: 최신 워크플로 버전과 연결된 서비스 계정의 이메일 주소 또는 고유 ID입니다. 이 서비스 계정은 워크플로의 ID를 나타내며 워크플로에 포함된 권한을 확인합니다. 워크플로를 만들 때 서비스 계정을 지정하지 않으면 워크플로에 해당 ID의 기본 Compute Engine 서비스 계정이 사용됩니다. 자세한 내용은 워크플로에 Google Cloud 리소스 액세스 권한 부여를 참고하세요.labels: Google Cloud 인스턴스를 구성하는 데 도움이 되도록 이 워크플로에 할당할 키-값 라벨 쌍 목록입니다. 자세한 내용은 라벨이란 무엇인가요?를 참조하세요.user_env_vars: 이 워크플로 버전과 연결된 사용자 정의 환경 변수입니다. 자세한 내용은 환경 변수 사용을 참조하세요.source_contents: 실행할 Workflows 코드입니다. 파일 크기 한도는 리소스 한도를 참조하세요.
다른 선택적 인수는 다음과 같습니다.
crypto_key_name: 다음 형식의 Cloud Key Management Service 키에 대한 리소스 ID입니다.projects/PROJECT_NAME/locations/LOCATION/keyRings/KEY_RING/cryptoKeys/KEY_NAME
자세한 내용은 고객 관리 암호화 키 사용을 참조하세요.
call_log_level: 워크플로 실행 중에 호출 및 호출 응답에 적용할 로깅 수준입니다. 가능한 값은 다음과 같습니다.CALL_LOG_LEVEL_UNSPECIFIEDLOG_ALL_CALLSLOG_ERRORS_ONLYLOG_NONE
자세한 내용은 호출 로깅을 참조하세요.
project: 리소스가 속해 있는 프로젝트의 ID입니다. 입력하지 않으면 제공업체 프로젝트가 사용됩니다.name_prefix: 지정된 프리픽스로 시작하는 고유한 이름을 만듭니다. 이 프리픽스와name이 지정되지 않으면 이름으로 임의의 값이 선택됩니다.
워크플로 만들기 및 실행
Terraform 리소스를 배포하여 워크플로를 만든 후 워크플로를 실행합니다.
디렉터리에서 Terraform을 초기화합니다.
terraform initTerraform으로 제안한 변경사항이 예상 계획과 일치하는지 확인합니다.
terraform plan-out옵션을 사용하지 않는 것에 관한 참고 사항은 무시해도 됩니다.워크플로를 만듭니다.
terraform apply값 입력 프롬프트에서
yes를 입력하여 리소스 생성을 진행합니다.워크플로가 생성되었는지 확인합니다.
gcloud workflows list --location us-central1
출력은 다음과 비슷하게 표시됩니다.
NAME STATE REVISION_ID UPDATE_TIME projects/project-name/locations/us-central1/workflows/sample-workflow ACTIVE 000001-f9a 2024-02-24T13:38:58.353765906Z
원하는 경우 워크플로를 실행할 수 있습니다.
gcloud workflows execute sample-workflow
삭제
이 페이지에서 사용한 리소스 비용이 Google Cloud 계정에 청구되지 않도록 하려면 리소스가 포함된 Google Cloud 프로젝트를 삭제하세요.
- Terraform으로 만든 모든 리소스를 삭제합니다.
terraform destroy - 만든 워크플로를 삭제합니다.
계속 진행할지 묻는 메시지가 표시되면gcloud workflows delete sample-workflow
y를 입력합니다. - 또는 Google Cloud 프로젝트를 삭제하여 비용 청구를 방지할 수 있습니다. Google Cloud 프로젝트를 삭제하면 해당 프로젝트 내에서 사용되는 모든 리소스에 대한 청구가 중단됩니다.
Delete a Google Cloud project:
gcloud projects delete PROJECT_ID
다음 단계
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2025-12-04(UTC)
[[["이해하기 쉬움","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-12-04(UTC)"],[],[]]
필요한 역할
빠른 시작을 완료하는 데 필요한 권한을 얻으려면 관리자에게 프로젝트에 대한 다음 IAM 역할을 부여해 달라고 요청하세요.
역할 부여에 대한 자세한 내용은 프로젝트, 폴더, 조직에 대한 액세스 관리를 참조하세요.
커스텀 역할이나 다른 사전 정의된 역할을 통해 필요한 권한을 얻을 수도 있습니다.
Terraform 구성 파일 만들기
main.tf라는 Terraform 구성 파일을 만들고 이 빠른 시작에 사용된 Terraform용 Google 제공업체 리소스를 포함합니다.
참조 변수, 리소스 속성, 호출 함수와 같은 대체 항목에 대해 보간을 사용할 수 있습니다.