이 가이드에서는 이 구성 파일을 사용하여 provider 설정과 Terraform에서 만들려는 모든 인프라를 지정합니다. 그러나 제공업체 설정을 포함하는 방법에 관한 옵션이 있습니다.
provider 설정을 포함하는 방법에 관한 옵션 보기
나머지 Terraform 구성에 provider 설정을 포함하는 방법에 관한 옵션은 다음과 같습니다.
옵션 1: 단일 Terraform .tf 구성 파일 상단에 포함합니다(이 가이드 참조).
Terraform을 처음 시작하거나 Firebase에서 Terraform을 사용해 보려는 경우 이 옵션을 사용하세요.
옵션 2: 생성할 인프라를 지정하는 .tf 파일(예: main.tf 파일) 외에 별도의 .tf 파일(예: provider.tf 파일)에 포함합니다.
설정을 표준화해야 하는 대규모 팀에 속한 경우 이 옵션을 사용합니다.
Terraform 명령어를 실행할 때 provider.tf 파일과 main.tf 파일이 모두 같은 디렉터리에 있어야 합니다.
main.tf 파일 상단에 다음 provider 설정을 포함합니다.
Firebase에서 Terraform을 사용하는 베타 버전이므로 google-beta 제공업체를 사용해야 합니다. 프로덕션에서 사용할 때는 주의해야 합니다.
# Terraform configuration to set up providers by version.terraform{required_providers{google-beta={source="hashicorp/google-beta"version="~> 5.0"}}}# Configures the provider to use the resource block's specified project for quota checks.provider"google-beta"{user_project_override=true}# Configures the provider to not use the resource block's specified project for quota checks.# This provider should only be used during project creation and initializing services.provider"google-beta"{alias="no_user_project_override"user_project_override=false}
Firebase에서 Terraform을 사용할 때 프로젝트 관련 속성 유형(이 가이드에서 언급된 '할당량 확인 프로젝트' 포함)에 대해 자세히 알아보세요.
다음 섹션으로 이동하여 구성 파일을 작성하고 생성할 인프라를 지정합니다.
resource 블록을 사용하여 만들 인프라 지정
Terraform 구성 파일(이 가이드의 경우 main.tf 파일)에서 Terraform에서 만들려는 모든 인프라(프로비저닝할 모든 리소스 및 사용 설정할 모든 서비스)를 지정해야 합니다. 이 가이드에서 Terraform을 지원하는 모든 Firebase 리소스의 전체 목록을 확인하세요.
main.tf 파일을 엽니다.
provider 설정에서 다음 resource 블록 구성을 포함합니다.
이 기본 예시에서는 새 Firebase 프로젝트를 만든 다음 해당 프로젝트 내에 Firebase Android 앱을 만듭니다.
# Terraform configuration to set up providers by version....# Configures the provider to use the resource block's specified project for quota checks....# Configures the provider to not use the resource block's specified project for quota checks....# Creates a new Google Cloud project.resource"google_project""default"{provider=google-beta.no_user_project_overridename="Project Display Name"project_id="project-id-for-new-project" # Required for any service that requires the Blaze pricing plan # (like Firebase Authentication with GCIP)billing_account="000000-000000-000000" # Required for the project to display in any list of Firebase projects.labels={"firebase"="enabled"}}# Enables required APIs.resource"google_project_service""default"{provider=google-beta.no_user_project_overrideproject=google_project.default.project_idfor_each=toset(["cloudbilling.googleapis.com","cloudresourcemanager.googleapis.com","firebase.googleapis.com", # Enabling the ServiceUsage API allows the new project to be quota checked from now on."serviceusage.googleapis.com",])service=each.key # Don't disable the service if the resource block is removed by accident.disable_on_destroy=false}# Enables Firebase services for the new project created above.resource"google_firebase_project""default"{provider=google-betaproject=google_project.default.project_id # Waits for the required APIs to be enabled.depends_on=[google_project_service.default]}# Creates a Firebase Android App in the new project created above.resource"google_firebase_android_app""default"{provider=google-betaproject=google_project.default.project_iddisplay_name="My Awesome Android app"package_name="awesome.package.name" # Wait for Firebase to be enabled in the Google Cloud project before creating this App.depends_on=[google_firebase_project.default,]}
# Terraform configuration to set up providers by version....# Configures the provider to use the resource block's specified project for quota checks....# Configures the provider to not use the resource block's specified project for quota checks....# Creates a new Google Cloud project.resource"google_project""default"{ # Use the provider that enables the setup of quota checks for a new projectprovider=google-beta.no_user_project_overridename="Project Display Name" // learn more about the project nameproject_id="project-id-for-new-project" // learn more about the project ID # Required for any service that requires the Blaze pricing plan # (like Firebase Authentication with GCIP)billing_account="000000-000000-000000" # Required for the project to display in any list of Firebase projects.labels={"firebase"="enabled" // learn more about the Firebase-enabled label}}# Enables required APIs.resource"google_project_service""default"{ # Use the provider without quota checks for enabling APISprovider=google-beta.no_user_project_overrideproject=google_project.default.project_idfor_each=toset(["cloudbilling.googleapis.com","cloudresourcemanager.googleapis.com","firebase.googleapis.com", # Enabling the ServiceUsage API allows the new project to be quota checked from now on."serviceusage.googleapis.com",])service=each.key # Don't disable the service if the resource block is removed by accident.disable_on_destroy=false}# Enables Firebase services for the new project created above.# This action essentially "creates a Firebase project" and allows the project to use# Firebase services (like Firebase Authentication) and# Firebase tooling (like the Firebase console).# Learn more about the relationship between Firebase projects and Google Cloud.resource"google_firebase_project""default"{ # Use the provider that performs quota checks from now onprovider=google-betaproject=google_project.default.project_id # Waits for the required APIs to be enabled.depends_on=[google_project_service.default]}# Creates a Firebase Android App in the new project created above.# Learn more about the relationship between Firebase Apps and Firebase projects.resource"google_firebase_android_app""default"{provider=google-betaproject=google_project.default.project_iddisplay_name="My Awesome Android app" # learn more about an app's display namepackage_name="awesome.package.name" # learn more about an app's package name # Wait for Firebase to be enabled in the Google Cloud project before creating this App.depends_on=[google_firebase_project.default,]}
2단계: Terraform 명령어를 실행하여 지정한 인프라 만들기
main.tf 파일에 지정된 리소스를 프로비저닝하고 서비스를 사용 설정하려면 main.tf 파일과 동일한 디렉터리에서 다음 명령어를 실행합니다.
이러한 명령어에 대한 자세한 내용은 Terraform 문서를 참조하세요.
디렉터리에서 Terraform 명령어를 처음 실행하는 경우 구성 디렉터리를 초기화하고 Google Terraform 제공업체를 설치해야 합니다. 다음 명령어를 실행하면 됩니다.
다음 Firebase 및 Google 리소스에 Terraform이 지원됩니다. 계속해서 더 많은 리소스를 추가하고 있습니다. 따라서 Terraform으로 관리하려는 리소스가 표시되지 않으면 나중에 다시 확인하여 리소스를 사용할 수 있는지 확인하거나 GitHub 저장소에서 문제를 제출하여 요청하세요.
Terraform이 GCIP 및/또는 Firebase Authentication를 사용 설정할 프로젝트입니다.
Blaze 요금제를 사용해야 합니다. 즉, 프로젝트에
연결된 Cloud Billing 계정). 이렇게 하려면 프로그래매틱 방식으로 다음을 수행합니다.
설정
billing_account 드림
속성을 google_project 리소스에서 사용하세요.
이 리소스를 사용하면 익명, 이메일/비밀번호, 전화 인증과 같은 로컬 로그인 방식, 차단 함수, 승인된 도메인과 같은 더 많은 구성을 사용할 수 있습니다.
이 구성은 새 Google Cloud 프로젝트를 만들고, 프로젝트를 Cloud Billing 계정과 연결하고(GCIP를 사용하는 Firebase Authentication에는 Blaze 요금제가 필요함), 프로젝트에 Firebase 서비스를 사용 설정하고, GCIP를 사용하여 Firebase Authentication를 설정하고, 프로젝트에 세 가지 앱 유형을 등록합니다.
Terraform을 통해 Firebase Authentication를 설정하려면 GCIP를 사용 설정해야 합니다.
# Creates a new Google Cloud project.resource"google_project""auth"{provider=google-beta.no_user_project_overridefolder_id="folder-id-for-new-project"name="Project Display Name"project_id="project-id-for-new-project" # Associates the project with a Cloud Billing account # (required for Firebase Authentication with GCIP).billing_account="000000-000000-000000" # Required for the project to display in a list of Firebase projects.labels={"firebase"="enabled"}}# Enables required APIs.resource"google_project_service""auth"{provider=google-beta.no_user_project_overrideproject=google_project.auth.project_idfor_each=toset(["cloudbilling.googleapis.com","cloudresourcemanager.googleapis.com","serviceusage.googleapis.com","identitytoolkit.googleapis.com",])service=each.key # Don't disable the service if the resource block is removed by accident.disable_on_destroy=false}# Enables Firebase services for the new project created above.resource"google_firebase_project""auth"{provider=google-betaproject=google_project.auth.project_iddepends_on=[google_project_service.auth,]}# Creates an Identity Platform config.# Also enables Firebase Authentication with Identity Platform in the project if not.resource"google_identity_platform_config""auth"{provider=google-betaproject=google_project.auth.project_id # Auto-deletes anonymous usersautodelete_anonymous_users=true # Configures local sign-in methods, like anonymous, email/password, and phone authentication.sign_in{allow_duplicate_emails=trueanonymous{enabled=true}email{enabled=truepassword_required=false}phone_number{enabled=truetest_phone_numbers={"+11231231234"="000000"}}} # Sets an SMS region policy.sms_region_config{allowlist_only{allowed_regions=["US","CA",]}} # Configures blocking functions.blocking_functions{triggers{event_type="beforeSignIn"function_uri="https://us-east1-${google_project.auth.project_id}.cloudfunctions.net/before-sign-in"}forward_inbound_credentials{refresh_token=trueaccess_token=trueid_token=true}} # Configures a temporary quota for new signups for anonymous, email/password, and phone number.quota{sign_up_quota_config{quota=1000start_time=""quota_duration="7200s"}} # Configures authorized domains.authorized_domains=["localhost","${google_project.auth.project_id}.firebaseapp.com","${google_project.auth.project_id}.web.app",] # Wait for identitytoolkit.googleapis.com to be enabled before initializing Authentication.depends_on=[google_project_service.auth,]}# Creates a Firebase Android App in the new project created above.resource"google_firebase_android_app""auth"{provider=google-betaproject=google_project.auth.project_iddisplay_name="My Android app"package_name="android.package.name" # Wait for Firebase to be enabled in the Google Cloud project before creating this App.depends_on=[google_firebase_project.auth,]}# Creates a Firebase Apple-platforms App in the new project created above.resource"google_firebase_apple_app""auth"{provider=google-betaproject=google_project.auth.project_iddisplay_name="My Apple app"bundle_id="apple.app.12345" # Wait for Firebase to be enabled in the Google Cloud project before creating this App.depends_on=[google_firebase_project.auth,]}# Creates a Firebase Web App in the new project created above.resource"google_firebase_web_app""auth"{provider=google-betaproject=google_project.auth.project_iddisplay_name="My Web app" # The other App types (Android and Apple) use "DELETE" by default. # Web apps don't use "DELETE" by default due to backward-compatibility.deletion_policy="DELETE" # Wait for Firebase to be enabled in the Google Cloud project before creating this App.depends_on=[google_firebase_project.auth,]}
기본 Firebase Realtime Database 인스턴스 프로비저닝
이 구성은 새 Google Cloud 프로젝트를 만듭니다.
프로젝트에 Firebase 서비스를 사용 설정합니다.
프로젝트의 기본 Realtime Database 인스턴스를 프로비저닝합니다.
프로젝트에 세 가지 다른 앱 유형을 등록합니다.
# Creates a new Google Cloud project.resource"google_project""rtdb"{provider=google-beta.no_user_project_overridefolder_id="folder-id-for-new-project"name="Project Display Name"project_id="project-id-for-new-project" # Required for the project to display in a list of Firebase projects.labels={"firebase"="enabled"}}# Enables required APIs.resource"google_project_service""rtdb"{provider=google-beta.no_user_project_overrideproject=google_project.rtdb.project_idfor_each=toset(["serviceusage.googleapis.com","cloudresourcemanager.googleapis.com","firebasedatabase.googleapis.com",])service=each.key # Don't disable the service if the resource block is removed by accident.disable_on_destroy=false}# Enables Firebase services for the new project created above.resource"google_firebase_project""rtdb"{provider=google-betaproject=google_project.rtdb.project_id}# Provisions the default Realtime Database default instance.resource"google_firebase_database_instance""database"{provider=google-betaproject=google_project.rtdb.project_id # See available locations: https://firebase.google.com/docs/projects/locations#rtdb-locationsregion="name-of-region" # This value will become the first segment of the database's URL.instance_id="${google_project.rtdb.project_id}-default-rtdb"type="DEFAULT_DATABASE" # Wait for Firebase to be enabled in the Google Cloud project before initializing Realtime Database.depends_on=[google_firebase_project.rtdb,]}# Creates a Firebase Android App in the new project created above.resource"google_firebase_android_app""rtdb"{provider=google-betaproject=google_project.rtdb.project_iddisplay_name="My Android app"package_name="android.package.name" # Wait for Firebase to be enabled in the Google Cloud project before creating this App.depends_on=[google_firebase_project.rtdb,]}# Creates a Firebase Apple-platforms App in the new project created above.resource"google_firebase_apple_app""rtdb"{provider=google-betaproject=google_project.rtdb.project_iddisplay_name="My Apple app"bundle_id="apple.app.12345" # Wait for Firebase to be enabled in the Google Cloud project before creating this App.depends_on=[google_firebase_project.rtdb,]}# Creates a Firebase Web App in the new project created above.resource"google_firebase_web_app""rtdb"{provider=google-betaproject=google_project.rtdb.project_iddisplay_name="My Web app" # The other App types (Android and Apple) use "DELETE" by default. # Web apps don't use "DELETE" by default due to backward-compatibility.deletion_policy="DELETE" # Wait for Firebase to be enabled in the Google Cloud project before creating this App.depends_on=[google_firebase_project.rtdb,]}
여러 항목 프로비저닝
인스턴스 Firebase Realtime Database개
이 구성은 새 Google Cloud 프로젝트를 만들고, 프로젝트를 Cloud Billing 계정과 연결하고(여러 Realtime Database 인스턴스에는 Blaze 요금제가 필요함), 프로젝트에 Firebase 서비스를 사용 설정하고, 여러 Realtime Database 인스턴스(프로젝트의 기본 Realtime Database 인스턴스 포함)를 프로비저닝하며, 프로젝트에 세 가지 앱 유형을 등록합니다.
# Creates a new Google Cloud project.resource"google_project""rtdb-multi"{provider=google-beta.no_user_project_overridefolder_id="folder-id-for-new-project"name="Project Display Name"project_id="project-id-for-new-project" # Associate the project with a Cloud Billing account # (required for multiple Realtime Database instances).billing_account="000000-000000-000000" # Required for the project to display in a list of Firebase projects.labels={"firebase"="enabled"}}# Enables required APIs.resource"google_project_service""rtdb-multi"{provider=google-beta.no_user_project_overrideproject=google_project.rtdb-multi.project_idfor_each=toset(["cloudbilling.googleapis.com","serviceusage.googleapis.com","cloudresourcemanager.googleapis.com","firebasedatabase.googleapis.com",])service=each.key # Don't disable the service if the resource block is removed by accident.disable_on_destroy=false}# Enables Firebase services for the new project created above.resource"google_firebase_project""rtdb-multi"{provider=google-betaproject=google_project.rtdb-multi.project_id}# Provisions the default Realtime Database default instance.resource"google_firebase_database_instance""database-default"{provider=google-betaproject=google_project.rtdb-multi.project_id # See available locations: https://firebase.google.com/docs/projects/locations#rtdb-locationsregion="name-of-region" # This value will become the first segment of the database's URL.instance_id="${google_project.rtdb-multi.project_id}-default-rtdb"type="DEFAULT_DATABASE" # Wait for Firebase to be enabled in the Google Cloud project before initializing Realtime Database.depends_on=[google_firebase_project.rtdb-multi,]}# Provisions an additional Realtime Database instance.resource"google_firebase_database_instance""database-additional"{provider=google-betaproject=google_project.rtdb-multi.project_id # See available locations: https://firebase.google.com/docs/projects/locations#rtdb-locations # This location doesn't need to be the same as the default database instance.region="name-of-region" # This value will become the first segment of the database's URL.instance_id="name-of-additional-database-instance"type="USER_DATABASE" # Wait for Firebase to be enabled in the Google Cloud project before initializing Realtime Database.depends_on=[google_firebase_project.rtdb-multi,]}# Creates a Firebase Android App in the new project created above.resource"google_firebase_android_app""rtdb-multi"{provider=google-betaproject=google_project.rtdb-multi.project_iddisplay_name="My Android app"package_name="android.package.name" # Wait for Firebase to be enabled in the Google Cloud project before creating this App.depends_on=[google_firebase_project.rtdb-multi,]}# Creates a Firebase Apple-platforms App in the new project created above.resource"google_firebase_apple_app""rtdb-multi"{provider=google-betaproject=google_project.rtdb-multi.project_iddisplay_name="My Apple app"bundle_id="apple.app.12345" # Wait for Firebase to be enabled in the Google Cloud project before creating this App.depends_on=[google_firebase_project.rtdb-multi,]}# Creates a Firebase Web App in the new project created above.resource"google_firebase_web_app""rtdb-multi"{provider=google-betaproject=google_project.rtdb-multi.project_iddisplay_name="My Web app" # The other App types (Android and Apple) use "DELETE" by default. # Web apps don't use "DELETE" by default due to backward-compatibility.deletion_policy="DELETE" # Wait for Firebase to be enabled in the Google Cloud project before creating this App.depends_on=[google_firebase_project.rtdb-multi,]}
먼저
인스턴스 Cloud Firestore개
이 구성은 새 Google Cloud 프로젝트를 만듭니다.
프로젝트에 Firebase 서비스를 사용 설정합니다.
프로젝트의 Cloud Firestore 인스턴스를 프로비저닝합니다.
프로젝트에 세 가지 앱 유형을 등록합니다.
또한 Cloud Firestore 인스턴스에 Firebase Security Rules를 프로비저닝하고, Cloud Firestore 색인을 만들며, 시드 데이터가 있는 Cloud Firestore 문서를 추가합니다.
# Creates a new Google Cloud project.resource"google_project""firestore"{provider=google-beta.no_user_project_overridefolder_id="folder-id-for-new-project"name="Project Display Name"project_id="project-id-for-new-project" # Required for the project to display in a list of Firebase projects.labels={"firebase"="enabled"}}# Enables required APIs.resource"google_project_service""firestore"{provider=google-beta.no_user_project_overrideproject=google_project.firestore.project_idfor_each=toset(["cloudresourcemanager.googleapis.com","serviceusage.googleapis.com","firestore.googleapis.com","firebaserules.googleapis.com",])service=each.key # Don't disable the service if the resource block is removed by accident.disable_on_destroy=false}# Enables Firebase services for the new project created above.resource"google_firebase_project""firestore"{provider=google-betaproject=google_project.firestore.project_id}# Provisions the Firestore database instance.resource"google_firestore_database""firestore"{provider=google-betaproject=google_project.firestore.project_idname="(default)" # See available locations: https://firebase.google.com/docs/projects/locations#default-cloud-locationlocation_id="name-of-region" # "FIRESTORE_NATIVE" is required to use Firestore with Firebase SDKs, authentication, and Firebase Security Rules.type="FIRESTORE_NATIVE"concurrency_mode="OPTIMISTIC" # Wait for Firebase to be enabled in the Google Cloud project before initializing Firestore.depends_on=[google_firebase_project.firestore,]}# Creates a ruleset of Firestore Security Rules from a local file.resource"google_firebaserules_ruleset""firestore"{provider=google-betaproject=google_project.firestore.project_idsource{files{name="firestore.rules" # Write security rules in a local file named "firestore.rules". # Learn more: https://firebase.google.com/docs/firestore/security/get-startedcontent=file("firestore.rules")}} # Wait for Firestore to be provisioned before creating this ruleset.depends_on=[google_firestore_database.firestore,]}# Releases the ruleset for the Firestore instance.resource"google_firebaserules_release""firestore"{provider=google-betaname="cloud.firestore" # must be cloud.firestoreruleset_name=google_firebaserules_ruleset.firestore.nameproject=google_project.firestore.project_id # Wait for Firestore to be provisioned before releasing the ruleset.depends_on=[google_firestore_database.firestore,]}# Adds a new Firestore index.resource"google_firestore_index""indexes"{provider=google-betaproject=google_project.firestore.project_idcollection="quiz"query_scope="COLLECTION"fields{field_path="question"order="ASCENDING"}fields{field_path="answer"order="ASCENDING"} # Wait for Firestore to be provisioned before adding this index.depends_on=[google_firestore_database.firestore,]}# Adds a new Firestore document with seed data.# Don't use real end-user or production data in this seed document.resource"google_firestore_document""doc"{provider=google-betaproject=google_project.firestore.project_idcollection="quiz"document_id="question-1"fields="{\"question\":{\"stringValue\":\"Favorite Database\"},\"answer\":{\"stringValue\":\"Firestore\"}}" # Wait for Firestore to be provisioned before adding this document.depends_on=[google_firestore_database.firestore,]}# Creates a Firebase Android App in the new project created above.resource"google_firebase_android_app""firestore"{provider=google-betaproject=google_project.firestore.project_iddisplay_name="My Android app"package_name="android.package.name" # Wait for Firebase to be enabled in the Google Cloud project before creating this App.depends_on=[google_firebase_project.firestore,]}# Creates a Firebase Apple-platforms App in the new project created above.resource"google_firebase_apple_app""firestore"{provider=google-betaproject=google_project.firestore.project_iddisplay_name="My Apple app"bundle_id="apple.app.12345" # Wait for Firebase to be enabled in the Google Cloud project before creating this App.depends_on=[google_firebase_project.firestore,]}# Creates a Firebase Web App in the new project created above.resource"google_firebase_web_app""firestore"{provider=google-betaproject=google_project.firestore.project_iddisplay_name="My Web app" # The other App types (Android and Apple) use "DELETE" by default. # Web apps don't use "DELETE" by default due to backward-compatibility.deletion_policy="DELETE" # Wait for Firebase to be enabled in the Google Cloud project before creating this App.depends_on=[google_firebase_project.firestore,]}
로컬 파일에 있어야 하는 Cloud Firestore Security Rules의 규칙 세트입니다.
이름이 firestore.rules입니다.
이 구성은 새 Google Cloud 프로젝트를 만듭니다.
프로젝트에 Firebase 서비스를 사용 설정합니다.
프로젝트의 기본 Cloud Storage 버킷을 프로비저닝합니다.
프로젝트에 세 가지 앱 유형을 등록합니다.
또한 Cloud Storage 버킷에 Firebase Security Rules를 프로비저닝합니다.
버킷에 파일을 업로드합니다
# Creates a new Google Cloud project.resource"google_project""storage"{provider=google-beta.no_user_project_overridefolder_id="folder-id-for-new-project"name="Project Display Name"project_id="project-id-for-new-project" # Required for the project to display in a list of Firebase projects.labels={"firebase"="enabled"}}# Enables required APIs.resource"google_project_service""storage"{provider=google-beta.no_user_project_overrideproject=google_project.storage.project_idfor_each=toset(["serviceusage.googleapis.com","cloudresourcemanager.googleapis.com","firebaserules.googleapis.com","firebasestorage.googleapis.com","storage.googleapis.com",])service=each.key # Don't disable the service if the resource block is removed by accident.disable_on_destroy=false}# Enables Firebase services for the new project created above.resource"google_firebase_project""storage"{provider=google-betaproject=google_project.storage.project_id}# Provisions the default Cloud Storage bucket for the project via Google App Engine.resource"google_app_engine_application""default"{provider=google-betaproject=google_project.storage.project_id # See available locations: https://firebase.google.com/docs/projects/locations#default-cloud-location # This will set the location for the default Storage bucket and the App Engine App.location_id="name-of-region-for-default-bucket" # If you use Firestore, uncomment this to make sure Firestore is provisioned first. # depends_on = [ # google_firestore_database.firestore # ]}# Makes the default Storage bucket accessible for Firebase SDKs, authentication, and Firebase Security Rules.resource"google_firebase_storage_bucket""default-bucket"{provider=google-betaproject=google_project.storage.project_idbucket_id=google_app_engine_application.default.default_bucket}# Creates a ruleset of Cloud Storage Security Rules from a local file.resource"google_firebaserules_ruleset""storage"{provider=google-betaproject=google_project.storage.project_idsource{files{ # Write security rules in a local file named "storage.rules". # Learn more: https://firebase.google.com/docs/storage/security/get-startedname="storage.rules"content=file("storage.rules")}} # Wait for the default Storage bucket to be provisioned before creating this ruleset.depends_on=[google_firebase_project.storage,]}# Releases the ruleset to the default Storage bucket.resource"google_firebaserules_release""default-bucket"{provider=google-betaname="firebase.storage/${google_app_engine_application.default.default_bucket}"ruleset_name="projects/${google_project.storage.project_id}/rulesets/${google_firebaserules_ruleset.storage.name}"project=google_project.storage.project_id}# Uploads a new file to the default Storage bucket.# Don't use real end-user or production data in this file.resource"google_storage_bucket_object""cat-picture"{provider=google-betaname="cat.png"source="path/to/cat.png"bucket=google_app_engine_application.default.default_bucket}# Creates a Firebase Android App in the new project created above.resource"google_firebase_android_app""storage"{provider=google-betaproject=google_project.storage.project_iddisplay_name="My Android app"package_name="android.package.name" # Wait for Firebase to be enabled in the Google Cloud project before creating this App.depends_on=[google_firebase_project.storage,]}# Creates a Firebase Apple-platforms App in the new project created above.resource"google_firebase_apple_app""storage"{provider=google-betaproject=google_project.storage.project_iddisplay_name="My Apple app"bundle_id="apple.app.12345" # Wait for Firebase to be enabled in the Google Cloud project before creating this App.depends_on=[google_firebase_project.storage,]}# Creates a Firebase Web App in the new project created above.resource"google_firebase_web_app""storage"{provider=google-betaproject=google_project.storage.project_iddisplay_name="My Web app" # The other App types (Android and Apple) use "DELETE" by default. # Web apps don't use "DELETE" by default due to backward-compatibility.deletion_policy="DELETE" # Wait for Firebase to be enabled in the Google Cloud project before creating this App.depends_on=[google_firebase_project.storage,]}
로컬 파일에 있어야 하는 Cloud Storage Security Rules의 규칙 세트입니다.
이름이 storage.rules입니다.
이 구성은 새 Google Cloud 프로젝트를 만들고, 프로젝트를 Cloud Billing 계정과 연결하고(여러 버킷에는 Blaze 요금제가 필요함), 프로젝트에 Firebase 서비스를 사용 설정하고, 여러 Cloud Storage 버킷(프로젝트의 기본 Cloud Storage 버킷 포함)을 프로비저닝하며, 프로젝트에 세 가지 앱 유형을 등록합니다.
또한 Cloud Storage 버킷에 Firebase Security Rules를 프로비저닝하고 기본 Cloud Storage 버킷에 파일을 업로드합니다.
# Creates a new Google Cloud project.resource"google_project""storage-multi"{provider=google-beta.no_user_project_overridefolder_id="folder-id-for-new-project"name="Project Display Name"project_id="project-id-for-new-project" # Associates the project with a Cloud Billing account # (required for multiple Cloud Storage buckets).billing_account="000000-000000-000000" # Required for the project to display in a list of Firebase projects.labels={"firebase"="enabled"}}# Enables required APIs.resource"google_project_service""storage-multi"{provider=google-beta.no_user_project_overrideproject=google_project.storage-multi.project_idfor_each=toset(["cloudbilling.googleapis.com","serviceusage.googleapis.com","cloudresourcemanager.googleapis.com","firebaserules.googleapis.com","firebasestorage.googleapis.com","storage.googleapis.com",])service=each.key # Don't disable the service if the resource block is removed by accident.disable_on_destroy=false}# Enables Firebase services for the new project created above.resource"google_firebase_project""storage-multi"{provider=google-betaproject=google_project.storage-multi.project_id}# Provisions the default Cloud Storage bucket for the project via Google App Engine.resource"google_app_engine_application""default-multi"{provider=google-betaproject=google_project.storage-multi.project_id # See available locations: https://firebase.google.com/docs/projects/locations#default-cloud-location # This will set the location for the default Storage bucket and the App Engine App.location_id="name-of-region-for-default-bucket" # If you use Firestore, uncomment this to make sure Firestore is provisioned first. # depends_on = [ # google_firestore_database.firestore # ]}# Provisions an additional Cloud Storage bucket.# Additional Cloud Storage buckets are not provisioned via App Engine.resource"google_storage_bucket""bucket-multi"{provider=google-betaproject=google_project.storage-multi.project_idname="name-of-additional-storage-bucket" # See available locations: https://cloud.google.com/storage/docs/locations#available-locations # This location does not need to be the same as the default Storage bucket.location="name-of-region-for-additional-bucket"}# Makes the default Storage bucket accessible for Firebase SDKs, authentication, and Firebase Security Rules.resource"google_firebase_storage_bucket""default-bucket-multi"{provider=google-betaproject=google_project.storage-multi.project_idbucket_id=google_app_engine_application.default-multi.default_bucket}# Makes the additional Storage bucket accessible for Firebase SDKs, authentication, and Firebase Security Rules.resource"google_firebase_storage_bucket""bucket-multi"{provider=google-betaproject=google_project.storage-multi.project_idbucket_id=google_storage_bucket.bucket-multi.name}# Creates a ruleset of Firebase Security Rules from a local file.resource"google_firebaserules_ruleset""storage-multi"{provider=google-betaproject=google_project.storage-multi.project_idsource{files{ # Write security rules in a local file named "storage.rules" # Learn more: https://firebase.google.com/docs/storage/security/get-startedname="storage.rules"content=file("storage.rules")}} # Wait for the Storage buckets to be provisioned before creating this ruleset.depends_on=[google_firebase_project.storage-multi,]}# Releases the ruleset to the default Storage bucket.resource"google_firebaserules_release""default-bucket-multi"{provider=google-betaname="firebase.storage/${google_app_engine_application.default-multi.default_bucket}"ruleset_name="projects/${google_project.storage-multi.project_id}/rulesets/${google_firebaserules_ruleset.storage-multi.name}"project=google_project.storage-multi.project_id}# Releases the ruleset to the additional Storage bucket.resource"google_firebaserules_release""bucket-multi"{provider=google-betaname="firebase.storage/${google_storage_bucket.bucket-multi.name}"ruleset_name="projects/${google_project.storage-multi.project_id}/rulesets/${google_firebaserules_ruleset.storage-multi.name}"project=google_project.storage-multi.project_id}# Uploads a new file to the default Storage bucket.# Do not use real end-user or production data in this file.resource"google_storage_bucket_object""cat-picture-multi"{provider=google-betaname="cat.png"source="path/to/cat.png"bucket=google_app_engine_application.default-multi.default_bucket}# Creates a Firebase Android App in the new project created above.resource"google_firebase_android_app""storage-multi"{provider=google-betaproject=google_project.storage-multi.project_iddisplay_name="My Android app"package_name="android.package.name" # Wait for Firebase to be enabled in the Google Cloud project before creating this App.depends_on=[google_firebase_project.storage-multi,]}# Creates a Firebase Apple-platforms App in the new project created above.resource"google_firebase_apple_app""storage-multi"{provider=google-betaproject=google_project.storage-multi.project_iddisplay_name="My Apple app"bundle_id="apple.app.12345" # Wait for Firebase to be enabled in the Google Cloud project before creating this App.depends_on=[google_firebase_project.storage-multi,]}# Creates a Firebase Web App in the new project created above.resource"google_firebase_web_app""storage-multi"{provider=google-betaproject=google_project.storage-multi.project_iddisplay_name="My Web app" # The other App types (Android and Apple) use "DELETE" by default. # Web apps don't use "DELETE" by default due to backward-compatibility.deletion_policy="DELETE" # Wait for Firebase to be enabled in the Google Cloud project before creating this App.depends_on=[google_firebase_project.storage-multi,]}
로컬 파일에 있어야 하는 Cloud Storage Security Rules의 규칙 세트입니다.
이름이 storage.rules입니다.
이 구성은 새 Google Cloud 프로젝트를 만듭니다.
프로젝트에 Firebase 서비스를 사용 설정합니다.
Cloud Firestore 인스턴스를 프로비저닝합니다.
그런 다음 기본 Cloud Storage 버킷을 프로비저닝합니다.
또한 Cloud Firestore 인스턴스 및 기본값을 위해 Firebase Security Rules를 프로비저닝합니다.
Cloud Storage 버킷
# Creates a new Google Cloud project.resource"google_project""fs"{ # fs = Firestore + Storageprovider=google-beta.no_user_project_overridefolder_id="folder-id-for-new-project"name="Project Display Name"project_id="project-id-for-new-project" # Required for the project to display in a list of Firebase projects.labels={"firebase"="enabled"}}# Enables required APIs.resource"google_project_service""fs"{provider=google-beta.no_user_project_overrideproject=google_project.fs.project_idfor_each=toset(["serviceusage.googleapis.com","cloudresourcemanager.googleapis.com","firebaserules.googleapis.com","firebasestorage.googleapis.com","storage.googleapis.com","firestore.googleapis.com",])service=each.key # Don't disable the service if the resource block is removed by accidentdisable_on_destroy=false}# Enables Firebase services for the new project created above.resource"google_firebase_project""fs"{provider=google-betaproject=google_project.fs.project_id}#### Set up Firestore before default Cloud Storage bucket ##### Provisions the Firestore database instance.resource"google_firestore_database""firestore-fs"{provider=google-betaproject=google_project.fs.project_idname="(default)" # See available locations: https://firebase.google.com/docs/projects/locations#default-cloud-locationlocation_id="name-of-region" # "FIRESTORE_NATIVE" is required to use Firestore with Firebase SDKs, authentication, and Firebase Security Rules.type="FIRESTORE_NATIVE"concurrency_mode="OPTIMISTIC" # Wait for Firebase to be enabled in the Google Cloud project before initializing Firestore.depends_on=[google_firebase_project.fs,]}# Creates a ruleset of Firestore Security Rules from a local file.resource"google_firebaserules_ruleset""firestore-fs"{provider=google-betaproject=google_project.fs.project_idsource{files{ # Write security rules in a local file named "firestore.rules". # Learn more: https://firebase.google.com/docs/firestore/security/get-startedname="firestore.rules"content=file("firestore.rules")}} # Wait for Firestore to be provisioned before creating this ruleset.depends_on=[google_firestore_database.firestore-fs]}# Releases the ruleset for the Firestore instance.resource"google_firebaserules_release""firestore-fs"{provider=google-betaname="cloud.firestore" # must be cloud.firestoreruleset_name=google_firebaserules_ruleset.firestore-fs.nameproject=google_project.fs.project_id # Wait for Firestore to be provisioned before releasing the ruleset.depends_on=[google_firestore_database.firestore-fs,]}#### Set up default Cloud Storage default bucket after Firestore ##### Provisions the default Cloud Storage bucket for the project via Google App Engine.resource"google_app_engine_application""default-bucket-fs"{provider=google-betaproject=google_project.fs.project_id # See available locations: https://firebase.google.com/docs/projects/locations#default-cloud-location # This will set the location for the default Storage bucket and the App Engine App.location_id="name-of-region" # Must be in the same location as Firestore (above) # Wait for Firestore to be provisioned first. # Otherwise, the Firestore instance will be provisioned in Datastore mode (unusable by Firebase).depends_on=[google_firestore_database.firestore-fs,]}# Makes the default Storage bucket accessible for Firebase SDKs, authentication, and Firebase Security Rules.resource"google_firebase_storage_bucket""default-bucket-fs"{provider=google-betaproject=google_project.fs.project_idbucket_id=google_app_engine_application.default-bucket-fs.default_bucket}# Creates a ruleset of Cloud Storage Security Rules from a local file.resource"google_firebaserules_ruleset""default-bucket-fs"{provider=google-betaproject=google_project.fs.project_idsource{files{ # Write security rules in a local file named "storage.rules". # Learn more: https://firebase.google.com/docs/storage/security/get-startedname="storage.rules"content=file("storage.rules")}} # Wait for the Cloud Storage bucket to be provisioned before creating this ruleset.depends_on=[google_firebase_project.fs,]}# Releases the ruleset to the default Storage bucket.resource"google_firebaserules_release""default-bucket-fs"{provider=google-betaname="firebase.storage/${google_app_engine_application.default-bucket-fs.default_bucket}"ruleset_name="projects/${google_project.fs.project_id}/rulesets/${google_firebaserules_ruleset.default-bucket-fs.name}"project=google_project.fs.project_id}
로컬 파일에 있어야 하는 Cloud Firestore Security Rules의 규칙 세트입니다.
이름이 firestore.rules입니다.
이 구성은 새 Google Cloud 프로젝트를 만듭니다.
프로젝트에 Firebase 서비스를 사용 설정합니다.
Cloud Firestore에 Firebase App Check 적용을 설정하고 사용 설정합니다.
내 Android 앱에서만 액세스할 수 있도록 합니다.
# Creates a new Google Cloud project.resource"google_project""appcheck"{provider=google-beta.no_user_project_overridefolder_id="folder-id-for-new-project"name="Project Display Name"project_id="project-id-for-new-project" # Required for the project to display in a list of Firebase projects.labels={"firebase"="enabled"}}# Enables required APIs.resource"google_project_service""services"{provider=google-beta.no_user_project_overrideproject=google_project.appcheck.project_idfor_each=toset(["cloudresourcemanager.googleapis.com","firebase.googleapis.com","firebaseappcheck.googleapis.com","firestore.googleapis.com","serviceusage.googleapis.com",])service=each.key # Don't disable the service if the resource block is removed by accident.disable_on_destroy=false}# Enables Firebase services for the new project created earlier.resource"google_firebase_project""appcheck"{provider=google-betaproject=google_project.appcheck.project_iddepends_on=[google_project_service.services]}# Provisions the Firestore database instance.resource"google_firestore_database""database"{provider=google-betaproject=google_firebase_project.appcheck.projectname="(default)" # See available locations: https://firebase.google.com/docs/projects/locations#default-cloud-locationlocation_id="name-of-region" # "FIRESTORE_NATIVE" is required to use Firestore with Firebase SDKs, authentication, and Firebase Security Rules.type="FIRESTORE_NATIVE"concurrency_mode="OPTIMISTIC" # Wait for Firebase to be enabled in the Google Cloud project before initializing Firestore.depends_on=[google_firebase_project.appcheck,]}# Creates a Firebase Android App in the new project created earlier.resource"google_firebase_android_app""appcheck"{provider=google-betaproject=google_firebase_project.appcheck.projectdisplay_name="Play Integrity app"package_name="package.name.playintegrity"sha256_hashes=[ # TODO: insert your Android app's SHA256 certificate]}# It takes a while for App Check to recognize the new app# If your app already exists, you don't have to wait 30 seconds.resource"time_sleep""wait_30s"{depends_on=[google_firebase_android_app.appcheck]create_duration="30s"}# Register the Android app with the Play Integrity providerresource"google_firebase_app_check_play_integrity_config""appcheck"{provider=google-betaproject=google_firebase_project.appcheck.projectapp_id=google_firebase_android_app.appcheck.app_iddepends_on=[time_sleep.wait_30s,google_firestore_database.database]lifecycle{precondition{condition=length(google_firebase_android_app.appcheck.sha256_hashes)>0error_message="Provide a SHA-256 certificate on the Android App to use App Check"}}}# Enable enforcement of App Check for Firestoreresource"google_firebase_app_check_service_config""firestore"{provider=google-betaproject=google_firebase_project.appcheck.projectservice_id="firestore.googleapis.com"depends_on=[google_project_service.services]}
설치
Firebase Extension의 인스턴스
이 구성은 새 Google Cloud 프로젝트를 만듭니다.
프로젝트에 Firebase 서비스를 사용 설정합니다.
Firebase Extension의 새 인스턴스를 설치합니다.
역할을 합니다 인스턴스가 이미 있는 경우 구성에 제공된 값을 기반으로 매개변수가 업데이트됩니다.
# Creates a new Google Cloud project.resource"google_project""extensions"{provider=google-beta.no_user_project_overridefolder_id="folder-id-for-new-project"name="Project Display Name"project_id="project-id-for-new-project" # Associates the project with a Cloud Billing account # (required to use Firebase Extensions).billing_account="000000-000000-000000" # Required for the project to display in a list of Firebase projects.labels={"firebase"="enabled"}}# Enables required APIs.resource"google_project_service""extensions"{provider=google-beta.no_user_project_overrideproject=google_project.extensions.project_idfor_each=toset(["cloudbilling.googleapis.com","cloudresourcemanager.googleapis.com","serviceusage.googleapis.com","firebase.googleapis.com","firebaseextensions.googleapis.com",])service=each.key # Don't disable the service if the resource block is removed by accident.disable_on_destroy=false}# Enables Firebase services for the new project created above.resource"google_firebase_project""extensions"{provider=google-betaproject=google_project.extensions.project_iddepends_on=[google_project_service.extensions,]}# Installs an instance of the "Translate Text in Firestore" extension.# Or updates the extension if the specified instance already exists.resource"google_firebase_extensions_instance""translation"{provider=google-betaproject=google_project.extensions.project_idinstance_id="translate-text-in-firestore"config{extension_ref="firebase/firestore-translate-text"params={COLLECTION_PATH="posts/comments/translations"DO_BACKFILL=trueLANGUAGES="ar,en,es,de,fr"INPUT_FIELD_NAME="input"LANGUAGES_FIELD_NAME="languages"OUTPUT_FIELD_NAME="translated"}system_params={"firebaseextensions.v1beta.function/location"="us-central1""firebaseextensions.v1beta.function/memory"="256""firebaseextensions.v1beta.function/minInstances"="0""firebaseextensions.v1beta.function/vpcConnectorEgressSettings"="VPC_CONNECTOR_EGRESS_SETTINGS_UNSPECIFIED"}}}
문제해결 및 FAQ
다양한 프로젝트 관련 속성(예: project, user_project_override)에 대해 자세히 알아보세요.
이 가이드에서는 '프로젝트'를 수행할 때 다음 Terraform 속성을 사용합니다.
resource 블록 내 project
권장: 가능하면 각 resource 블록 내에 project 속성을 포함하세요.
프로젝트 속성을 포함하면 Terraform은 지정된 프로젝트 내의 리소스 블록에 지정된 인프라를 만듭니다. 이 가이드와 샘플 구성 파일은 모두 이 방법을 사용합니다.
대부분의 리소스 프로비저닝은 user_project_override = true를 사용해야 합니다. 즉, 자체 Firebase 프로젝트와 비교하여 할당량을 확인합니다. 그러나 할당량 확인을 허용할 수 있도록 새 프로젝트를 설정하려면 먼저 user_project_override = false를 사용해야 합니다.
generic::permission_denied: Firebase Tos Not Accepted 오류가 발생합니다.
gcloud CLI를 실행하는 데 사용 중인 사용자 계정이 있어야 합니다.
명령어가 Firebase 서비스 약관 (Firebase 서비스 약관)에 동의했습니다.
사용자 계정에 로그인한 브라우저를 사용하여 확인할 수 있습니다.
Firebase 프로젝트에서
Firebase 콘솔. 기존 Firebase 프로젝트를 볼 수 있으면 사용자 계정이 Firebase 서비스 약관에 동의한 것입니다.
기존 Firebase 프로젝트를 볼 수 없는 경우 사용자 계정이 Firebase 서비스 약관에 동의하지 않은 것일 수 있습니다. 이 문제를 해결하려면 Firebase Console을 통해 새 Firebase 프로젝트를 만들고 프로젝트 생성 과정에서 Firebase 서비스 약관에 동의합니다. 이 항목을 즉시 삭제할 수 있습니다.
프로젝트 관리 콘솔에서 프로젝트 설정을 통해
terraform apply를 실행한 후 generic::permission_denied: IAM authority does not have the
permission 오류가 발생합니다.
몇 분 정도 기다린 후 terraform apply를 다시 실행해 봅니다.
리소스 생성에 실패했지만 terraform apply를 다시 실행하면 ALREADY_EXISTS가 표시됩니다.
이는 여러 시스템의 전파 지연으로 인해 발생할 수 있습니다. terraform import를 실행하여 Terraform 상태로 리소스를 가져와 이 문제를 해결해 보세요. 그런 다음 terraform apply를 다시 실행해 보세요.
이 ID와 연결된 프로젝트가 현재 사용자 아래에 올바르게 존재합니다. 이 오류는 이전 terraform apply가 중단된 것이 원인일 수 있습니다.
해결 방법: 다음 명령어를 실행합니다. terraform import google_project.default PROJECT_ID
다음 terraform import google_firebase_project.default PROJECT_ID
날짜
Cloud Firestore를 프로비저닝한 다음 Cloud Storage을 (를) 프로비저닝하려고 합니다
google_app_engine_application)가 포함된 경우 다음 오류가 발생합니다.
Error: Error creating App Engine application: googleapi: Error 409:
Cannot create Firestore database resource <resource-name> since it
already exists at location <location-id>, alreadyExists입니다.
App Engine 애플리케이션에는 Cloud Firestore 인스턴스가 필요하지만 다음 중 한 가지만 할 수 있습니다.
프로젝트당 1개의 Cloud Firestore 인스턴스가 있어야 합니다 따라서 오류 메시지에서 알 수 있듯이
프로젝트의 Cloud Firestore 인스턴스를 이미 한 인스턴스에서 프로비저닝한 경우
Cloud Firestore을 프로비저닝하려고 하면 App Engine에서 오류가 발생합니다.
다른 위치에 있는 인스턴스를
사용할 수 있습니다 App Engine에서는 이미 기존 Cloud Firestore 인스턴스를 '다시 프로비저닝'하려고 한다고 판단합니다.
이 오류를 해결하려면 Cloud Firestore와
App Engine 애플리케이션. Cloud Storage 버킷이
Cloud Firestore와(과) 다른 위치에 있다면 추가 버킷을 프로비저닝할 수 있습니다.
(
여러 Cloud Storage을 만들기 위한 샘플 구성
버킷)에서 사용할 수 있습니다.
날짜
다음을 통해 Cloud Storage을 (를) 프로비저닝하려고 합니다.
google_app_engine_application)하고 Cloud Firestore의 경우 다음과 같은 결과가 발생합니다.
오류:
Error: Error creating Database: googleapi: Error 409: Database already
exists. Please use another database_id입니다.
프로젝트의 기본 Cloud Storage 버킷을 프로비저닝할 때 (새 IP 주소를 통해
google_app_engine_application)이고 프로젝트에 아직
Cloud Firestore 인스턴스, 이후 자동으로 google_app_engine_application
프로젝트의 Cloud Firestore 인스턴스를 프로비저닝합니다.
따라서 프로젝트의 Cloud Firestore 인스턴스가 이미 프로비저닝된 경우에는
모든 포드를 명시적으로 프로비저닝하려고 하면 google_firestore_database에서
Cloud Firestore 인스턴스.
프로젝트의 Cloud Firestore 인스턴스가 프로비저닝되면
"재프로비저닝" 그것의 위치를 변경할 수 있습니다. 오류가 발생하는 것을 막으려면
구성 파일에서 google_firestore_database 리소스 블록을 삭제합니다.
다만 Cloud Firestore
프로젝트의 기본 Cloud Storage 버킷 (이유는 아래 참조)