Skip to content

Commit

Permalink
user_data, manually check server list array length
Browse files Browse the repository at this point in the history
  • Loading branch information
stelcheck committed May 17, 2018
1 parent 0f1418f commit 47c7680
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/terraform-provider-ncloud/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
9 changes: 9 additions & 0 deletions src/terraform-provider-ncloud/resource_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand Down Expand Up @@ -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{
Expand Down

0 comments on commit 47c7680

Please sign in to comment.