기본 구성 만들기

이 페이지에서는 배포를 만드는 데 사용할 수 있는 구성을 만드는 방법을 설명합니다. 배포에 대한 자세한 내용은 배포 만들기를 참조하세요.

구성 파일은 배포를 구성하는 모든 Google Cloud 리소스를 정의합니다. 배포를 만들려면 구성 파일이 있어야 합니다. 구성 파일은 YAML 구문으로 작성해야 합니다.

시작하기 전에

구성 파일 구조

구성 파일은 YAML 형식으로 작성되며, 다음 구조를 갖습니다.

#  imported templates, if applicable
imports:
  #  path relative to the configuration file
- path: path/to/template.jinja
  name: my-template
- path: path/to/another/template.py
  name: another-template

resources:
  - name: NAME_OF_RESOURCE
    type: TYPE_OF_RESOURCE
    properties:
      property-a: value
      property-b: value
      ...
      property-z: value
  - name: NAME_OF_RESOURCE
    type: TYPE_OF_RESOURCE
    properties:
      property-a: value
      property-b: value
      ...
      property-z: value

각 섹션은 배포의 각기 다른 부분을 정의합니다.

  • imports 섹션은 구성에서 사용되는 템플릿 파일 목록입니다. Deployment Manager는 가져온 모든 템플릿을 재귀적으로 확장하여 최종 구성을 형성합니다.

  • resources 섹션은 이 배포를 구성하는 리소스 목록입니다. 가능한 리소스는 다음과 같습니다.

또한 outputs 섹션 및 metadata 섹션과 같은 다른 선택적인 섹션이 포함될 수 있습니다. outputs 섹션에서는 최종 사용자의 출력으로 또는 같은 배포에 있는 다른 템플릿의 출력으로 템플릿 및 구성의 데이터를 노출할 수 있습니다. 반면에 metadata 섹션에서는 리소스 간 명시적 종속 항목 설정과 같은 다른 기능을 사용할 수 있습니다.

최소한 구성은 resources 섹션과 그 다음의 리소스 목록을 항상 선언해야 합니다. 다른 섹션은 선택 사항입니다.

리소스 유형 선언

구성의 각 리소스는 유형으로 지정해야 합니다. 유형은 Google 관리형 기본 유형, 복합 유형, 유형 공급자 또는 가져온 템플릿일 수 있습니다.

Google 관리 기본 유형은 Google Cloud 리소스로 확인되는 유형입니다. 예를 들어 Cloud SQL 인스턴스 또는 Cloud Storage 버킷은 Google 관리형 기본 유형입니다. 이러한 유형은 다음 구문을 사용하여 선언할 수 있습니다.

type: <api>.<api-version>.<resource-type>

예를 들어 Compute Engine 인스턴스는 다음 유형을 포함합니다.

type: compute.v1.instance

BigQuery 데이터베이스의 경우에는 다음 유형일 수 있습니다.

type: bigquery.v2.dataset

지원되는 모든 유형 목록을 보려면 다음 명령어를 사용하세요.

gcloud deployment-manager types list

지원되는 Google에서 관리되는 기본 유형의 전체 목록은 지원되는 리소스 유형을 참조하세요.

복합 또는 유형 공급자를 사용하는 경우 유형을 다음과 같이 선언합니다.

# Composite type

resources:
- name: my-composite-type
  type: [PROJECT]/composite:[TYPE_NAME]

유형 공급자에 대해서는 다음과 같이 선언합니다.

# Base type

resources:
- name: my-base-type
  type: [PROJECT_ID]/[TYPE_PROVIDER_NAME]:[TYPE_NAME]

또한 Google 관리형 유형 공급자(베타)를 사용하여 리소스를 만들 수도 있습니다. Google Cloud 유형 공급자 목록은 지원되는 유형 공급자를 참조하세요.

템플릿을 사용하려는 경우 템플릿을 유형으로 선언하고, 템플릿 이름 또는 경로를 type의 값으로 지정합니다. 예를 들어 다음 구성은 my_vm_template.jinja라는 템플릿을 가져오고 유형으로 제공합니다.

imports:
- path: path/to/template/my_vm_template.jinja
  name: my-template.jinja

resources:
- name: my-first-virtual-machine
  type: my-template.jinja

템플릿에 대한 자세한 내용은 기본 템플릿 만들기를 참조하세요.

리소스 속성 선언

리소스 유형을 선언한 후에는 리소스에 name을 지정하고 리소스에 필요한 속성을 지정해야 합니다. 예를 들어 다음 구성 파일에서는 vm-created-by-deployment-manager라는 가상 머신 인스턴스와 여기에서 사용할 속성을 정의합니다. Deployment Manager는 이 정보를 사용하여 이러한 속성이 포함된 VM 인스턴스를 만듭니다.

# Copyright 2016 Google Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

resources:
- name: vm-created-by-deployment-manager
  type: compute.v1.instance
  properties:
    zone: us-central1-a
    machineType: zones/us-central1-a/machineTypes/n1-standard-1
    disks:
    - deviceName: boot
      type: PERSISTENT
      boot: true
      autoDelete: true
      initializeParams:
        sourceImage: projects/debian-cloud/global/images/family/debian-11
    networkInterfaces:
    - network: global/networks/default

리소스의 properties를 확인하려면 리소스의 API 참고 리소스를 사용합니다.

  • 리소스의 insert 또는 create 메서드에서 요청 형식을 확인합니다.
  • 요청 URI에 영역이 포함된 경우 영역을 속성에 추가합니다.
  • 배열의 경우 YAML 목록 구문을 사용해서 배열 요소를 나열합니다. 예를 들어 API를 사용해서 Compute Engine 인스턴스를 만드는 경우, 인스턴스에 연결하려는 디스크 배열을 다음 형식으로 제공해야 합니다.

    "disks": [
      {
        "type": "PERSISTENT",
        "deviceName": "disk1",
        ...
      },
      {
        "type": "PERSISTENT",
        "deviceName": "disk2",
        ...
      }
    ]
    

    Deployment Manager 구성에서 다음 구문을 사용하여 이러한 디스크를 추가합니다.

    disks:
    - deviceName: disk1
      type: PERSISTENT
      ...
    - deviceName: disk2
      type: PERSISTENT
    

또한 해당 리소스의 쓰기 가능 속성을 제공할 수 있습니다. 속성이 쓰기 가능한지 확인하려면 리소스 유형에 대한 API 참고 문서를 사용합니다. 예를 들어 Compute Engine 참조는 특정 속성을 출력 전용으로 표시합니다. 이러한 속성은 변경할 수 없으므로, 개발자가 자신의 구성에 정의할 수 없습니다.

일부 API는 리소스를 만들기 위한 최소 속성 집합이 필요합니다. 예를 들어 Compute Engine 영구 디스크는 새 디스크를 만들 때 디스크 이름, 이미지 소스, 디스크 크기 등이 필요합니다. 특정 리소스에 대한 자세한 내용은 해당 리소스에 대한 API 참조를 검토하세요.

템플릿 속성 정의

구성에서 사용할 템플릿을 가져올 경우 properties 섹션을 사용하여 리소스 속성 대신 템플릿 속성 값을 정의합니다. 또는 템플릿에 템플릿 속성이 없으면 properties 섹션을 함께 생략할 수 있습니다.

다른 Google Cloud 서비스에서 리소스 만들기

마지막으로 구성 파일은 다른 Google Cloud 서비스에서 리소스를 만들 수 있습니다. 예를 들어 다음 구성 파일은 Compute Engine 및 BigQuery에서 리소스를 만듭니다.

# Copyright 2016 Google Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

resources:
- name: vm-created-by-deployment-manager
  type: compute.v1.instance
  properties:
    zone: us-central1-a
    machineType: zones/us-central1-a/machineTypes/n1-standard-1
    disks:
    - deviceName: boot
      type: PERSISTENT
      boot: true
      autoDelete: true
      initializeParams:
        sourceImage: projects/debian-cloud/global/images/family/debian-11
    networkInterfaces:
    - network: global/networks/default

- name: big-query-dataset
  type: bigquery.v2.dataset
  properties:
    datasetReference:
      datasetId: example_id

지원되는 리소스 유형 및 속성

지원되는 리소스 유형 문서에서 지원되는 Google에서 관리되는 리소스 전체 목록을 참조하세요.

다음 단계