diff --git a/Gopkg.lock b/Gopkg.lock index 2125a89..f869e1a 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -10,7 +10,7 @@ "request", "sdk" ] - revision = "f0bad5cda5e5c9bfb9cca1f78f551486b8f30afb" + revision = "5fd6750b50f03d491b794e178fe5fce311a721b7" source = "github.com/stelcheck/ncloud-sdk-go" [[projects]] @@ -68,8 +68,8 @@ "service/s3", "service/sts" ] - revision = "c7cd1ebe87257cde9b65112fc876b0339ea0ac30" - version = "v1.13.49" + revision = "ee7b4b1162937cba700de23bd90acb742982e626" + version = "v1.13.50" [[projects]] branch = "master" diff --git a/src/terraform-provider-ncloud/resource_instance.go b/src/terraform-provider-ncloud/resource_instance.go index d21d551..948c950 100644 --- a/src/terraform-provider-ncloud/resource_instance.go +++ b/src/terraform-provider-ncloud/resource_instance.go @@ -60,6 +60,13 @@ func resourceInstance() *schema.Resource { Description: "script to run at first boot", Default: false, }, + "public_ip_instance": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + ForceNew: true, + Description: "Public IP ID", + Default: "", + }, "public_ip": &schema.Schema{ Type: schema.TypeString, Computed: true, @@ -120,6 +127,19 @@ func resourceInstanceCreate(data *schema.ResourceData, meta interface{}) error { waitForServerStatus(client, data.Id(), "RUN") + publicIP := data.Get("public_ip_instance").(string) + if publicIP != "" { + associateReqParams := new(sdk.RequestAssociatePublicIP) + associateReqParams.PublicIPInstanceNo = publicIP + associateReqParams.ServerInstanceNo = data.Id() + + _, err = client.AssociatePublicIP(associateReqParams) + if err != nil { + return fmt.Errorf("Failed to associate public IP %s", err) + } + } + data.SetPartial("public_ip_instance") + return resourceInstanceRead(data, meta) } @@ -160,6 +180,8 @@ func resourceInstanceDelete(data *schema.ResourceData, meta interface{}) error { return fmt.Errorf("Failed to disassociate IP with ID %s from server %s: %s", publicIP, data.Id(), err) } + waitForPublicIPDetach(client, publicIPInstance.PublicIPInstanceNo) + break } } diff --git a/src/terraform-provider-ncloud/resource_public_ip.go b/src/terraform-provider-ncloud/resource_public_ip.go index 4340759..88c4b5a 100644 --- a/src/terraform-provider-ncloud/resource_public_ip.go +++ b/src/terraform-provider-ncloud/resource_public_ip.go @@ -15,12 +15,6 @@ func resourcePublicIP() *schema.Resource { Read: resourcePublicIPRead, Delete: resourcePublicIPDelete, Schema: map[string]*schema.Schema{ - "server_id": &schema.Schema{ - Type: schema.TypeString, - ForceNew: true, - Required: true, - Description: "Product code (see https://github.com/Wizcorp/terraform-provider-ncloud/blob/master/Services.md#servers-server_product_code)", - }, "public_ip": &schema.Schema{ Type: schema.TypeString, Computed: true, @@ -33,8 +27,6 @@ func resourcePublicIPCreate(data *schema.ResourceData, meta interface{}) error { client := meta.(*sdk.Conn) data.Partial(true) - serverID := data.Get("server_id").(string) - readReqParams := new(sdk.RequestGetServerInstanceList) readResponse, err := client.GetServerInstanceList(readReqParams) @@ -49,7 +41,6 @@ func resourcePublicIPCreate(data *schema.ResourceData, meta interface{}) error { serverInfo := readResponse.ServerInstanceList[0] reqParams := new(sdk.RequestCreatePublicIPInstance) - reqParams.ServerInstanceNo = serverID reqParams.RegionNo = serverInfo.Region.RegionNo // API doc says we should be allowed to specify th zone // reqParams.ZoneNo = serverInfo.Zone.ZoneNo @@ -65,7 +56,6 @@ func resourcePublicIPCreate(data *schema.ResourceData, meta interface{}) error { ipInfo := response.PublicIPInstanceList[0] data.SetId(ipInfo.PublicIPInstanceNo) - data.SetPartial("server_id") return resourcePublicIPRead(data, meta) }