여러 템플릿 사용

이 단계에서는 다른 템플릿을 가져오는 템플릿을 살펴봅니다.

이러한 템플릿을 통합한 후에는 구성에서 템플릿 한 개만 호출하여 리소스가 모두 포함된 배포를 만들어야 합니다.

네트워크용 템플릿 열기

compute-engine-template.py 템플릿을 엽니다.

cd deploymentmanager-samples/examples/v2/step_by_step_guide/step6_use_multiple_templates/python

nano compute-engine-template.py  # use your preferred text editor

이 템플릿은 배포에 있는 모든 리소스를 위한 vm-template.py, 가상 머신(VM)용 vm-template-2.py, 네트워크용 network-template.py, 방화벽 규칙용 firewall-template.py 등의 다른 템플릿을 가져옵니다.

# 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.

"""Creates the Compute Engine."""

def GenerateConfig(context):
  """Creates the Compute Engine with network and firewall."""

  resources = [{
      'name': 'vm-1',
      'type': 'vm-template.py'
  }, {
      'name': 'vm-2',
      'type': 'vm-template-2.py'
  }, {
      'name': 'network-1',
      'type': 'network-template.py'
  }, {
      'name': 'firewall-1',
      'type': 'firewall-template.py'
  }]
  return {'resources': resources}

구성 확인

배포용 구성 파일을 엽니다.

cd deploymentmanager-samples/examples/v2/step_by_step_guide/step6_use_multiple_templates/python

nano config-with-many-templates.yaml  # use your preferred text editor

구성에서 다른 템플릿을 직접 호출하지 않았습니다. 하지만 compute-engine-template.py가 다른 템플릿에 의존하므로 다른 템플릿을 가져옵니다.

# 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.

imports:
- path: vm-template.py
- path: vm-template-2.py
- path: network-template.py
- path: firewall-template.py
- path: compute-engine-template.py

resources:
- name: compute-engine-setup
  type: compute-engine-template.py

구성 저장 및 배포

다음 명령어를 실행하여 구성을 배포합니다.

gcloud deployment-manager deployments create deployment-with-many-templates \
  --config config-with-many-templates.yaml

배포를 보려면 다음을 실행합니다.

gcloud deployment-manager deployments describe deployment-with-many-templates

미리보기: 템플릿 속성 및 환경 변수

그런 다음 템플릿의 하드 코딩된 부분을 커스텀 템플릿 및 환경 변수와 같은 재사용 가능한 패턴으로 바꿉니다.

배포 삭제

요금이 청구되지 않도록 배포를 삭제하는 것이 좋습니다. 다음 단계에는 이 배포가 필요하지 않습니다. 다음 명령어를 실행하여 배포를 삭제합니다.

gcloud deployment-manager deployments delete deployment-with-many-templates