Closed yamamoto-febc closed 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
パッケージでのUpdate
やPatch
の定義を流用するとTagsやDescriptionが意図せずクリアされてしまうことがある。
対応としてnakedパッケージ内にSettingsやSettingsHashのみを持つ専用の型を定義する。
from https://github.com/sacloud/terraform-provider-sakuracloud/issues/550
v2では
Patch
が提供されているが、v1でのUpdateSetting相当の処理も必要。Settings
とSettingsHash
のみを扱うようにして実装する。