From 47c7680d5fad1c2fad26289a0de737a614a25a91 Mon Sep 17 00:00:00 2001 From: stelcheck Date: Thu, 17 May 2018 21:19:13 +0900 Subject: [PATCH] user_data, manually check server list array length --- src/terraform-provider-ncloud/helpers.go | 2 +- src/terraform-provider-ncloud/resource_instance.go | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/terraform-provider-ncloud/helpers.go b/src/terraform-provider-ncloud/helpers.go index 1b142d1..b9d69be 100644 --- a/src/terraform-provider-ncloud/helpers.go +++ b/src/terraform-provider-ncloud/helpers.go @@ -21,7 +21,7 @@ func getServerInfo(client *sdk.Conn, serverID string) (*sdk.ServerInstance, erro return nil, fmt.Errorf("Received no servers in the API response") } - if response.TotalRows == 0 { + if response.TotalRows == 0 || len(response.ServerInstanceList) == 0 { return nil, nil } diff --git a/src/terraform-provider-ncloud/resource_instance.go b/src/terraform-provider-ncloud/resource_instance.go index 9e0c372..d21d551 100644 --- a/src/terraform-provider-ncloud/resource_instance.go +++ b/src/terraform-provider-ncloud/resource_instance.go @@ -53,6 +53,13 @@ func resourceInstance() *schema.Resource { Description: "login keyname", Default: false, }, + "user_data": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + ForceNew: true, + Description: "script to run at first boot", + Default: false, + }, "public_ip": &schema.Schema{ Type: schema.TypeString, Computed: true, @@ -76,6 +83,7 @@ func resourceInstanceCreate(data *schema.ResourceData, meta interface{}) error { createReqParams.ServerProductCode = data.Get("server_product_code").(string) createReqParams.LoginKeyName = data.Get("login_keyname").(string) createReqParams.IsProtectServerTermination = data.Get("termination_protection").(bool) + createReqParams.UserData = data.Get("user_data").(string) createReqParams.ServerCreateCount = 1 response, err := client.CreateServerInstances(createReqParams) @@ -103,6 +111,7 @@ func resourceInstanceCreate(data *schema.ResourceData, meta interface{}) error { data.SetPartial("server_product_code") data.SetPartial("login_keyname") data.SetPartial("termination_protection") + data.SetPartial("user_data") listReqParams := new(sdk.RequestGetServerInstanceList) listReqParams.ServerInstanceNoList = []string{