-
Notifications
You must be signed in to change notification settings - Fork 677
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added resource for ibm_pi_snapshot + cleaned up pi_instance #1867
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,18 +40,22 @@ func resourceIBMPINetworkPortAttach() *schema.Resource { | |
}, | ||
|
||
helpers.PIInstanceName: { | ||
Type: schema.TypeString, | ||
Required: true, | ||
Type: schema.TypeString, | ||
Required: true, | ||
Description: "Instance name to attach the network port to", | ||
}, | ||
|
||
helpers.PINetworkName: { | ||
Type: schema.TypeString, | ||
Required: true, | ||
Type: schema.TypeString, | ||
Required: true, | ||
Description: "Network Name - This is the subnet name in the Cloud instance", | ||
}, | ||
|
||
"description": { | ||
Type: schema.TypeString, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Description is optional field...can we add the helper string pi_description and in create don't set the default description if it's not set by user
|
||
Optional: true, | ||
helpers.PINetworkPortDescription: { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Description: "A human readable description for this network Port", | ||
Default: "Port Created via Terraform", | ||
}, | ||
}, | ||
} | ||
|
@@ -67,7 +71,7 @@ func resourceIBMPINetworkPortAttachCreate(d *schema.ResourceData, meta interface | |
networkname := d.Get(helpers.PINetworkName).(string) | ||
portid := d.Get("port_id").(string) | ||
instancename := d.Get(helpers.PIInstanceName).(string) | ||
description := d.Get("description").(string) | ||
description := d.Get(helpers.PINetworkPortDescription).(string) | ||
client := st.NewIBMPINetworkClient(sess, powerinstanceid) | ||
|
||
log.Printf("Printing the input to the resource powerinstance [%s] and network name [%s] and the portid [%s]", powerinstanceid, networkname, portid) | ||
|
@@ -86,7 +90,7 @@ func resourceIBMPINetworkPortAttachCreate(d *schema.ResourceData, meta interface | |
log.Printf("[DEBUG] err %s", err) | ||
return err | ||
} | ||
_, err = isWaitForIBMPINetworkPortAvailable(client, IBMPINetworkPortID, d.Timeout(schema.TimeoutCreate), powerinstanceid, networkname) | ||
_, err = isWaitForIBMPINetworkPortAttachAvailable(client, IBMPINetworkPortID, d.Timeout(schema.TimeoutCreate), powerinstanceid, networkname) | ||
if err != nil { | ||
return err | ||
} | ||
|
@@ -95,7 +99,28 @@ func resourceIBMPINetworkPortAttachCreate(d *schema.ResourceData, meta interface | |
} | ||
|
||
func resourceIBMPINetworkPortAttachRead(d *schema.ResourceData, meta interface{}) error { | ||
log.Printf("Calling ther NetworkAttach Read code") | ||
log.Printf("Calling ther Network Port Attach Read code") | ||
sess, err := meta.(ClientSession).IBMPISession() | ||
|
||
if err != nil { | ||
fmt.Printf("failed to get a session from the IBM Cloud Service %v", err) | ||
} | ||
|
||
parts, err := idParts(d.Id()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
powerinstanceid := parts[0] | ||
powernetworkname := d.Get(helpers.PINetworkName).(string) | ||
networkC := st.NewIBMPINetworkClient(sess, powerinstanceid) | ||
networkdata, err := networkC.GetPort(powernetworkname, powerinstanceid, parts[1], getTimeOut) | ||
|
||
d.Set("ipaddress", networkdata.IPAddress) | ||
d.Set("macaddress", networkdata.MacAddress) | ||
d.Set("status", networkdata.Status) | ||
d.Set("portid", networkdata.PortID) | ||
d.Set("pvminstance", networkdata.PvmInstance.Href) | ||
|
||
return nil | ||
} | ||
|
@@ -108,32 +133,44 @@ func resourceIBMPINetworkPortAttachUpdate(d *schema.ResourceData, meta interface | |
func resourceIBMPINetworkPortAttachDelete(d *schema.ResourceData, meta interface{}) error { | ||
log.Printf("Detaching the network port from the Instance ") | ||
|
||
/* log.Printf("Calling the network delete functions. ") | ||
sess, err := meta.(ClientSession).IBMPISession() | ||
if err != nil { | ||
return err | ||
} | ||
parts, err := idParts(d.Id()) | ||
powernetworkname := d.Get(helpers.PINetworkName).(string) | ||
if err != nil { | ||
return err | ||
} | ||
powerinstanceid := parts[0] | ||
portid := parts[1] | ||
client := st.NewIBMPINetworkClient(sess, powerinstanceid) | ||
sess, err := meta.(ClientSession).IBMPISession() | ||
|
||
if err != nil { | ||
fmt.Printf("failed to get a session from the IBM Cloud Service %v", err) | ||
|
||
} | ||
parts, err := idParts(d.Id()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
network, err := client.DetachPort(powerinstanceid, powernetworkname, portid, deleteTimeOut)*/ | ||
powerinstanceid := parts[0] | ||
powernetworkname := d.Get(helpers.PINetworkName).(string) | ||
portid := d.Get("port_id").(string) | ||
|
||
client := st.NewIBMPINetworkClient(sess, powerinstanceid) | ||
log.Printf("Calling the network delete functions. ") | ||
network, err := client.DetachPort(powerinstanceid, powernetworkname, portid, deleteTimeOut) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
log.Printf("Printing the networkresponse %+v", &network) | ||
|
||
//log.Printf("Printing the networkresponse %s", network.Status) | ||
|
||
d.SetId("") | ||
return nil | ||
|
||
} | ||
|
||
func isWaitForIBMPINetworkPortAvailable(client *st.IBMPINetworkClient, id string, timeout time.Duration, powerinstanceid, networkname string) (interface{}, error) { | ||
func isWaitForIBMPINetworkPortAttachAvailable(client *st.IBMPINetworkClient, id string, timeout time.Duration, powerinstanceid, networkname string) (interface{}, error) { | ||
log.Printf("Waiting for Power Network (%s) that was created for Network Zone (%s) to be available.", id, networkname) | ||
|
||
stateConf := &resource.StateChangeConf{ | ||
Pending: []string{"retry", helpers.PINetworkProvisioning}, | ||
Target: []string{"DOWN"}, | ||
Refresh: isIBMPINetworkPortRefreshFunc(client, id, powerinstanceid, networkname), | ||
Target: []string{"ACTIVE"}, | ||
Refresh: isIBMPINetworkPortAttachRefreshFunc(client, id, powerinstanceid, networkname), | ||
Timeout: timeout, | ||
Delay: 10 * time.Second, | ||
MinTimeout: 10 * time.Minute, | ||
|
@@ -142,7 +179,7 @@ func isWaitForIBMPINetworkPortAvailable(client *st.IBMPINetworkClient, id string | |
return stateConf.WaitForState() | ||
} | ||
|
||
func isIBMPINetworkPortRefreshFunc(client *st.IBMPINetworkClient, id, powerinstanceid, networkname string) resource.StateRefreshFunc { | ||
func isIBMPINetworkPortAttachRefreshFunc(client *st.IBMPINetworkClient, id, powerinstanceid, networkname string) resource.StateRefreshFunc { | ||
|
||
log.Printf("Calling the IsIBMPINetwork Refresh Function....with the following id (%s) for network port and following id (%s) for network name and waiting for network to be READY", id, networkname) | ||
return func() (interface{}, string, error) { | ||
|
@@ -151,10 +188,10 @@ func isIBMPINetworkPortRefreshFunc(client *st.IBMPINetworkClient, id, powerinsta | |
return nil, "", err | ||
} | ||
|
||
if &network.PortID != nil { | ||
if &network.PortID != nil && &network.PvmInstance.PvmInstanceID != nil { | ||
//if network.State == "available" { | ||
log.Printf(" The port has been created with the following ip address") | ||
return network, "DOWN", nil | ||
log.Printf(" The port has been created with the following ip address and attached to an instance ") | ||
return network, "ACTIVE", nil | ||
} | ||
|
||
return network, helpers.PINetworkProvisioning, nil | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add this storage_type attribute to the docs of both resource and datasources pi_image