sacloud / libsacloud

[Deprecated] Library for SAKURA Cloud API with Go
Apache License 2.0
18 stars 13 forks source link

v1 UpdateSettingsのv2での実装 #397

Closed yamamoto-febc closed 4 years ago

yamamoto-febc commented 4 years ago

from https://github.com/sacloud/terraform-provider-sakuracloud/issues/550

v2ではPatchが提供されているが、v1でのUpdateSetting相当の処理も必要。 SettingsSettingsHashのみを扱うようにして実装する。

yamamoto-febc commented 4 years ago

Note: 例えばLoadBalancerの場合、nakedパッケージ内ではTagsやDescriptionを空に更新する場合向けに以下のような実装となっている。

// LoadBalancer ロードバランサ
type LoadBalancer struct {
    ID           types.ID              `json:",omitempty" yaml:"id,omitempty" structs:",omitempty"`
    Name         string                `json:",omitempty" yaml:"name,omitempty" structs:",omitempty"`
    Description  string                `yaml:"description"`
    Tags         types.Tags            `yaml:"tags"`
    Icon         *Icon                 `json:",omitempty" yaml:"icon,omitempty" structs:",omitempty"`
    CreatedAt    *time.Time            `json:",omitempty" yaml:"created_at,omitempty" structs:",omitempty"`
    ModifiedAt   *time.Time            `json:",omitempty" yaml:"modified_at,omitempty" structs:",omitempty"`
    Availability types.EAvailability   `json:",omitempty" yaml:"availability,omitempty" structs:",omitempty"`
    Class        string                `json:",omitempty" yaml:"class,omitempty" structs:",omitempty"`
    ServiceClass string                `json:",omitempty" yaml:"service_class,omitempty" structs:",omitempty"`
    Plan         *AppliancePlan        `json:",omitempty" yaml:"plan,omitempty" structs:",omitempty"`
    Instance     *Instance             `json:",omitempty" yaml:"instance,omitempty" structs:",omitempty"`
    Interfaces   []*Interface          `json:",omitempty" yaml:"interfaces,omitempty" structs:",omitempty"`
    Switch       *Switch               `json:",omitempty" yaml:"switch,omitempty" structs:",omitempty"`
    Settings     *LoadBalancerSettings `json:",omitempty" yaml:"settings,omitempty" structs:",omitempty"`
    SettingsHash string                `json:",omitempty" yaml:"settings_hash,omitempty" structs:",omitempty"`
    Remark       *ApplianceRemark      `json:",omitempty" yaml:"remark,omitempty" structs:",omitempty"`
}

このため、internal/defineパッケージでのUpdatePatchの定義を流用するとTagsやDescriptionが意図せずクリアされてしまうことがある。

対応としてnakedパッケージ内にSettingsやSettingsHashのみを持つ専用の型を定義する。