柔軟性を高めるため、式を Cloud Assembly のクラウド テンプレート コードに追加できます。
式の仕組み
Cloud Assembly 式では、次の例に示すように、${expression} コンストラクトが使用されます。
次のコード サンプルは、重要な行のみを表示するために省略しています。未編集のクラウド テンプレート全体が最後に表示されます。
例
展開時に、リモート アクセスに必要な暗号化キーをユーザーが貼り付けられるようにします。
inputs:
sshKey:
type: string
maxLength: 500
resources:
frontend:
type: Cloud.Machine
properties:
remoteAccess:
authentication: publicPrivateKey
sshKey: '${input.sshKey}'
VMware Cloud on AWS への展開の場合、フォルダ名をワークロードの必要な名前に設定します。
inputs:
environment:
type: string
enum:
- AWS
- vSphere
- Azure
- VMC
- GCP
default: vSphere
resources:
frontend:
type: Cloud.Machine
properties:
folderName: '${input.environment == "VMC" ? "Workload" : ""}'
展開時に、選択した環境に一致する env タグ(すべて小文字)でマシンをタグ付けします。
inputs:
environment:
type: string
enum:
- AWS
- vSphere
- Azure
- VMC
- GCP
default: vSphere
resources:
frontend:
type: Cloud.Machine
properties:
constraints:
- tag: '${"env:" + to_lower(input.environment)}'
フロントエンド クラスタ内のマシンの数を 1(小規模)または 2(大規模)に設定します。大規模クラスタは以下の除外プロセスによって設定される点に注目してください。
inputs:
envsize:
type: string
enum:
- Small
- Large
resources:
frontend:
type: Cloud.Machine
properties:
count: '${input.envsize == "Small" ? 1 : 2}'
ネットワーク リソースで検出されたプロパティにバインドすることにより、マシンを同じデフォルトのネットワークに接続します。
resources:
frontend:
type: Cloud.Machine
properties:
networks:
- network: '${resource.Cloud_Network_1.name}'
apitier:
type: Cloud.Machine
properties:
networks:
- network: '${resource.Cloud_Network_1.name}'
Cloud_Network_1:
type: Cloud.Network
properties:
name: Default
networkType: existing
API に送信されたアクセス認証情報を暗号化します。
resources:
apitier:
type: Cloud.Machine
properties:
cloudConfig: |
#cloud-config
runcmd:
- export apikey=${base64_encode(input.username:input.password)}
- curl -i -H 'Accept:application/json' -H 'Authorization:Basic :$apikey' http://example.com
API マシンのアドレスを検出します。
resources:
frontend:
type: Cloud.Machine
properties:
cloudConfig: |
runcmd:
- echo ${resource.apitier.networks[0].address}
apitier:
type: Cloud.Machine
properties:
networks:
- network: '${resource.Cloud_Network_1.name}'
完全なクラウド テンプレート
inputs:
environment:
type: string
enum:
- AWS
- vSphere
- Azure
- VMC
- GCP
default: vSphere
sshKey:
type: string
maxLength: 500
envsize:
type: string
enum:
- Small
- Large
resources:
frontend:
type: Cloud.Machine
properties:
folderName: '${input.environment == "VMC" ? "Workload" : ""}'
image: ubuntu
flavor: medium
count: '${input.envsize == "Small" ? 1 : 2}'
remoteAccess:
authentication: publicPrivateKey
sshKey: '${input.sshKey}'
cloudConfig: |
packages:
- nginx
runcmd:
- echo ${resource.apitier.networks[0].address}
constraints:
- tag: '${"env:" + to_lower(input.environment)}'
networks:
- network: '${resource.Cloud_Network_1.name}'
apitier:
type: Cloud.Machine
properties:
folderName: '${input.environment == "VMC" ? "Workload" : ""}'
image: ubuntu
flavor: small
cloudConfig: |
#cloud-config
runcmd:
- export apikey=${base64_encode(input.username:input.password)}
- curl -i -H 'Accept:application/json' -H 'Authorization:Basic :$apikey' http://example.com
remoteAccess:
authentication: publicPrivateKey
sshKey: '${input.sshKey}'
constraints:
- tag: '${"env:" + to_lower(input.environment)}'
networks:
- network: '${resource.Cloud_Network_1.name}'
Cloud_Network_1:
type: Cloud.Network
properties:
name: Default
networkType: existing
constraints:
- tag: '${"env:" + to_lower(input.environment)}'