LoginSignup
15
6

More than 5 years have passed since last update.

Cloud Deployment Managerのリソースプロパティの調べ方

Last updated at Posted at 2018-04-02

概要

通常、Cloud Deployment Manager(以後CDM)のリソースプロパティを調べるにはドキュメント(英語版)を参照します。

ただしドキュメントのリンク先はAPIの仕様書になっており、CDMのリソースプロパティとは一致しないことがあります。
例えばlogging.v2.metricsで必要となるnameプロパティは、CDMではmetricsというリソースプロパティに変わります!

ほとんどのリソースはAPI仕様書と同じプロパティ名であるため、そこまで困っていませんでした。
ただし一致しないはリソースにぶち当たるとサポートへ問い合わせが必要だったので不便です。

ところが最近の仕様変更に伴い、コマンドラインからリソースプロパティを確認する方法を発見したので共有です!

前提知識のtypeの変更について

本題の前にresources[].typeの指定方法が変更されていることについて説明します。
CDMのサンプルをみるとresources[].typeの指定方法が変更されているサンプルが確認できます。

#- type: storage.v1.bucket
- type: gcp-types/storage-v1:buckets

コメントアウトされているフォーマットが現在のドキュメントに記載されているフォーマットで、その下が新しいフォーマットです。
これは独自のリソースを定義する、タイプ プロバイダの追加と同じフォーマットです。

今後はフォーマットを統一するために、新しいフォーマットに移行すると思われます。

実はリソースプロパティの調べ方はこの新しいフォーマットがヒントになっています。

確認方法

ではリソースプロパティの確認方法をさらっと。

# リソースプロパティを調べるためには、以下のコマンドからタイププロバイダーとタイプを確認します。
# 一部抜粋
$ `gcloud beta deployment-manager types list`
...
provider: gcp-types/logging-v2
types:
- exclusions
- monitoredResourceDescriptors
- organizations.logs
- organizations.sinks
- organizations.exclusions
- entries
- logs
- sinks
- projects.logs
- projects.sinks
- projects.exclusions
- projects.metrics
- billingAccounts.logs
- billingAccounts.sinks
- billingAccounts.exclusions
- folders.logs
- folders.sinks
- folders.exclusions
...

# 次に以下の引数でコマンドを実行すると、CDMのリソーススキーマが確認できる
# logging-v2の例)
$ gcloud beta deployment-manager types describe --provider logging-v2 projects.exclusions --project gcp-types
type_info:
  documentationLink: https://cloud.google.com/logging/docs/
  kind: deploymentmanager#typeInfo
  name: projects.exclusions
  schema:
    input:
      $schema: http://json-schema.org/draft-03/schema#
      create:
        properties:
          description:
            description: Optional. A description of this exclusion.
            type: string
          disabled:
            description: Optional. If set to True, then this exclusion is disabled
              and it does not exclude any log entries. You can use exclusions.patch
              to change the value of this boolean
          filter:
            description: |
              Required. An advanced logs filter that matches the log entries to be excluded. By using the sample function, you can exclude less than 100% of the matching log entries. For example, the following filter matches 99% of low-severity log entries from load balancers:
              "resource.type=http_load_balancer severity<ERROR sample(insertId, 0.99)"
            type: string
          name:
            description: Required. A client-assigned identifier, such as "load-balancer-exclusion".
              Identifiers are limited to 100 characters and can include only letters,
              digits, underscores, hyphens, and periods.
            type: string
          parent:
            description: |-
              Required. The parent resource in which to create the exclusion:
              "projects/[PROJECT_ID]"
              "organizations/[ORGANIZATION_ID]"
              "billingAccounts/[BILLING_ACCOUNT_ID]"
              "folders/[FOLDER_ID]"
              Examples: "projects/my-logging-project", "organizations/123456789".
            location: path
            pattern: ^projects/[^/]+$
            required: true
            type: string
        type: object
      methodName: create
      schemas:
        LogExclusion:
          description: Specifies a set of log entries that are not to be stored in
            Stackdriver Logging. If your project receives a large volume of logs,
            you might be able to use exclusions to reduce your chargeable logs. Exclusions
            are processed after log sinks, so you can export log entries before they
            are excluded. Audit log entries and log entries from Amazon Web Services
            are never excluded.
          id: LogExclusion
          properties:
            description:
              description: Optional. A description of this exclusion.
              type: string
            disabled:
              description: Optional. If set to True, then this exclusion is disabled
                and it does not exclude any log entries. You can use exclusions.patch
                to change the value of this field.
              type: boolean
            filter:
              description: |
                Required. An advanced logs filter that matches the log entries to be excluded. By using the sample function, you can exclude less than 100% of the matching log entries. For example, the following filter matches 99% of low-severity log entries from load balancers:
                "resource.type=http_load_balancer severity<ERROR sample(insertId, 0.99)"
              type: string
            name:
              description: Required. A client-assigned identifier, such as "load-balancer-exclusion".
                Identifiers are limited to 100 characters and can include only letters,
                digits, underscores, hyphens, and periods.
              type: string
          type: object
    output:
      $schema: http://json-schema.org/draft-03/schema#
      mainSchema:
        $ref: '#/schemas/LogExclusion'
      methodName: get
      schemas:
        LogExclusion:
          description: Specifies a set of log entries that are not to be stored in
            Stackdriver Logging. If your project receives a large volume of logs,
            you might be able to use exclusions to reduce your chargeable logs. Exclusions
            are processed after log sinks, so you can export log entries before they
            are excluded. Audit log entries and log entries from Amazon Web Services
            are never excluded.
          id: LogExclusion
          properties:
            description:
              description: Optional. A description of this exclusion.
              type: string
            disabled:
              description: Optional. If set to True, then this exclusion is disabled
                and it does not exclude any log entries. You can use exclusions.patch
                to change the value of this field.
              type: boolean
            filter:
              description: |
                Required. An advanced logs filter that matches the log entries to be excluded. By using the sample function, you can exclude less than 100% of the matching log entries. For example, the following filter matches 99% of low-severity log entries from load balancers:
                "resource.type=http_load_balancer severity<ERROR sample(insertId, 0.99)"
              type: string
            name:
              description: Required. A client-assigned identifier, such as "load-balancer-exclusion".
                Identifiers are limited to 100 characters and can include only letters,
                digits, underscores, hyphens, and periods.
              type: string
          type: object
  title: Stackdriver Logging API

ポイントは--projectgcp-typesになる点です。

通常は自分が所属しているGCPのプロジェクトを指定しますが、gcp-typesプロジェクトにはCDMの公式リソースのスキーマが定義されているらしく指定が可能となっています。

例の場合だと、新規作成時に使用できるプロパティが以下であることがわかります。

  • description(string)
  • disabled(boolean)
  • filter(string)
  • name(string)
  • parent(regex:^projects/[^/]+$)

最後に

例にあげたリソースは、今多くの運用者が悩んでいるであろう、Stackdriver loggingの課金問題で使用する除外フィルターです。
また変更があるかもしれませんが、2018/06/30より課金が始まるので、ぜひCDMで除外フィルターを作成してみてください!

15
6
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
15
6