sacloud / terraform-provider-sakuracloud

Terraform provider for SakuraCloud
https://docs.usacloud.jp/terraform
Apache License 2.0
71 stars 23 forks source link

シンプル監視をterraform apply しても、terraform planで差分が出る #144

Closed hitsumabushi closed 7 years ago

hitsumabushi commented 7 years ago

バージョン

事象

シンプル監視について、 terraform apply したにもかかわらず、 terraform plan で差分が見える。 期待としては、 terraform apply した後は、 terraform plan で差分がなくなっていることです。

再現方法

以下のtfファイルを使って、 terraform apply, terraform plan を行うと再現します。

$ cat sakuracloud-alerting.tf 
resource "sakuracloud_simple_monitor" "website" {
  target = "github.com"
  description = "検証: ウェブサイト"
  health_check = {
    protocol = "https"
    delay_loop = 60
    path = "/"
    host_header = "github.com"
    status = "200"
    port = 443
  }
  notify_email_enabled = "false"
  notify_email_html = "false"
  notify_slack_enabled = "true"
  notify_slack_webhook = "https://hooks.slack.com/services/x/x/x"
  enabled = "true"
}

実行時のログ

`terraform apply` 後 `terraform plan` したときの様子 ``` $ SAKURACLOUD_ACCESS_TOKEN="..." SAKURACLOUD_ACCESS_TOKEN_SECRET="..." SAKURACLOUD_ZONE="tk1v" terraform apply sakuracloud_simple_monitor.website: Creating... description: "" => "検証: ウェブサイト" enabled: "" => "true" health_check.#: "" => "1" health_check.1061010695.community: "" => "" health_check.1061010695.delay_loop: "" => "60" health_check.1061010695.excepcted_data: "" => "" health_check.1061010695.host_header: "" => "github.com" health_check.1061010695.oid: "" => "" health_check.1061010695.path: "" => "/" health_check.1061010695.port: "" => "443" health_check.1061010695.protocol: "" => "https" health_check.1061010695.qname: "" => "" health_check.1061010695.snmp_version: "" => "" health_check.1061010695.status: "" => "200" notify_email_enabled: "" => "false" notify_email_html: "" => "false" notify_slack_enabled: "" => "true" notify_slack_webhook: "" => "https://hooks.slack.com/services/x/x/x" target: "" => "github.com" sakuracloud_simple_monitor.website: Creation complete (ID: 112900749994) Apply complete! Resources: 1 added, 0 changed, 0 destroyed. The state of your infrastructure has been saved to the path below. This state is required to modify and destroy your infrastructure, so keep it safe. To inspect the complete state use the `terraform show` command. State path: $ $ SAKURACLOUD_ACCESS_TOKEN="..." SAKURACLOUD_ACCESS_TOKEN_SECRET="..." SAKURACLOUD_ZONE="tk1v" terraform plan Refreshing Terraform state in-memory prior to plan... The refreshed state will be used to calculate this plan, but will not be persisted to local or remote state storage. sakuracloud_simple_monitor.website: Refreshing state... (ID: 112900749994) The Terraform execution plan has been generated and is shown below. Resources are shown in alphabetical order for quick scanning. Green resources will be created (or destroyed and then created if an existing resource exists), yellow resources are being changed in-place, and red resources will be destroyed. Cyan entries are data sources to be read. Note: You didn't specify an "-out" parameter to save this plan, so when "apply" is called, Terraform can't guarantee this is what will execute. ~ sakuracloud_simple_monitor.website health_check.1061010695.community: "" => "" health_check.1061010695.delay_loop: "" => "60" health_check.1061010695.excepcted_data: "" => "" health_check.1061010695.host_header: "" => "github.com" health_check.1061010695.oid: "" => "" health_check.1061010695.path: "" => "/" health_check.1061010695.port: "" => "443" health_check.1061010695.protocol: "" => "https" health_check.1061010695.qname: "" => "" health_check.1061010695.snmp_version: "" => "" health_check.1061010695.status: "" => "200" health_check.3455907603.community: "" => "" health_check.3455907603.delay_loop: "60" => "0" health_check.3455907603.excepcted_data: "" => "" health_check.3455907603.host_header: "github.com" => "" health_check.3455907603.oid: "" => "" health_check.3455907603.path: "/" => "" health_check.3455907603.port: "0" => "0" health_check.3455907603.protocol: "https" => "" health_check.3455907603.qname: "" => "" health_check.3455907603.snmp_version: "" => "" health_check.3455907603.status: "200" => "" Plan: 0 to add, 1 to change, 0 to destroy. ```
yamamoto-febc commented 7 years ago

portの設定が、protocolごとのデフォルトである場合にhealth_check.portをtfstateに反映できてないようです。 (httpの場合だと80、httpsの場合だと443の場合はtfstateに反映されない)

修正PRを作成し対応します。

yamamoto-febc commented 7 years ago

修正されるまでのワークアラウンド

方法1) portがデフォルト値(各protocolにより異なる)の場合、portの記述を行わない 方法2) portにデフォルト値以外を設定する

今回の例の場合単純にportの記述を削除することで回避できます。

hitsumabushi commented 7 years ago

port の設定を削除して、期待通りの挙動になることが確認できました

yamamoto-febc commented 7 years ago

@hitsumabushi ,

145 にて対応しました。

ありがとうございました!!!!!