PROGRESS! Now it only fails on the snapshot step
This commit is contained in:
parent
f208a071a4
commit
69ba710c2a
|
@ -3,7 +3,6 @@ package classic
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/hashicorp/go-cleanhttp"
|
"github.com/hashicorp/go-cleanhttp"
|
||||||
"github.com/hashicorp/go-oracle-terraform/compute"
|
"github.com/hashicorp/go-oracle-terraform/compute"
|
||||||
|
@ -64,7 +63,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
||||||
&ocommon.StepKeyPair{
|
&ocommon.StepKeyPair{
|
||||||
Debug: b.config.PackerDebug,
|
Debug: b.config.PackerDebug,
|
||||||
DebugKeyPath: fmt.Sprintf("oci_classic_%s.pem", b.config.PackerBuildName),
|
DebugKeyPath: fmt.Sprintf("oci_classic_%s.pem", b.config.PackerBuildName),
|
||||||
PrivateKeyFile: strings.TrimSpace(b.config.Comm.SSHPrivateKey),
|
PrivateKeyFile: b.config.Comm.SSHPrivateKey,
|
||||||
},
|
},
|
||||||
&stepCreateIPReservation{},
|
&stepCreateIPReservation{},
|
||||||
&stepCreateInstance{},
|
&stepCreateInstance{},
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package classic
|
package classic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"github.com/hashicorp/go-oracle-terraform/compute"
|
"github.com/hashicorp/go-oracle-terraform/compute"
|
||||||
|
@ -13,12 +14,14 @@ type stepCreateIPReservation struct{}
|
||||||
func (s *stepCreateIPReservation) Run(state multistep.StateBag) multistep.StepAction {
|
func (s *stepCreateIPReservation) Run(state multistep.StateBag) multistep.StepAction {
|
||||||
ui := state.Get("ui").(packer.Ui)
|
ui := state.Get("ui").(packer.Ui)
|
||||||
ui.Say("Creating IP reservation...")
|
ui.Say("Creating IP reservation...")
|
||||||
|
config := state.Get("config").(*Config)
|
||||||
client := state.Get("client").(*compute.ComputeClient)
|
client := state.Get("client").(*compute.ComputeClient)
|
||||||
iprClient := client.IPReservations()
|
iprClient := client.IPReservations()
|
||||||
// TODO: add optional Name and Tags
|
// TODO: add optional Name and Tags
|
||||||
IPInput := &compute.CreateIPReservationInput{
|
IPInput := &compute.CreateIPReservationInput{
|
||||||
ParentPool: compute.PublicReservationPool,
|
ParentPool: compute.PublicReservationPool,
|
||||||
Permanent: true,
|
Permanent: true,
|
||||||
|
Name: fmt.Sprintf("ipres_%s", config.ImageName),
|
||||||
}
|
}
|
||||||
ipRes, err := iprClient.CreateIPReservation(IPInput)
|
ipRes, err := iprClient.CreateIPReservation(IPInput)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -2,6 +2,7 @@ package classic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/hashicorp/go-oracle-terraform/compute"
|
"github.com/hashicorp/go-oracle-terraform/compute"
|
||||||
|
@ -17,9 +18,13 @@ func (s *stepCreateInstance) Run(state multistep.StateBag) multistep.StepAction
|
||||||
ui.Say("Creating Instance...")
|
ui.Say("Creating Instance...")
|
||||||
config := state.Get("config").(*Config)
|
config := state.Get("config").(*Config)
|
||||||
client := state.Get("client").(*compute.ComputeClient)
|
client := state.Get("client").(*compute.ComputeClient)
|
||||||
|
|
||||||
|
// SSH KEY CONFIGURATION
|
||||||
|
|
||||||
|
// grab packer-generated key from statebag context.
|
||||||
sshPublicKey := strings.TrimSpace(state.Get("publicKey").(string))
|
sshPublicKey := strings.TrimSpace(state.Get("publicKey").(string))
|
||||||
|
|
||||||
// Load the dynamically-generated SSH key into the Oracle Compute cloud.
|
// form API call to add key to compute cloud
|
||||||
sshKeyName := fmt.Sprintf("/Compute-%s/%s/packer_generated_key", config.IdentityDomain, config.Username)
|
sshKeyName := fmt.Sprintf("/Compute-%s/%s/packer_generated_key", config.IdentityDomain, config.Username)
|
||||||
|
|
||||||
sshKeysClient := client.SSHKeys()
|
sshKeysClient := client.SSHKeys()
|
||||||
|
@ -28,9 +33,11 @@ func (s *stepCreateInstance) Run(state multistep.StateBag) multistep.StepAction
|
||||||
Key: sshPublicKey,
|
Key: sshPublicKey,
|
||||||
Enabled: true,
|
Enabled: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Load the packer-generated SSH key into the Oracle Compute cloud.
|
||||||
keyInfo, err := sshKeysClient.CreateSSHKey(&sshKeysInput)
|
keyInfo, err := sshKeysClient.CreateSSHKey(&sshKeysInput)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Key already exists; update key instead
|
// Key already exists; update key instead of creating it
|
||||||
if strings.Contains(err.Error(), "packer_generated_key already exists") {
|
if strings.Contains(err.Error(), "packer_generated_key already exists") {
|
||||||
updateKeysInput := compute.UpdateSSHKeyInput{
|
updateKeysInput := compute.UpdateSSHKeyInput{
|
||||||
Name: sshKeyName,
|
Name: sshKeyName,
|
||||||
|
@ -46,15 +53,29 @@ func (s *stepCreateInstance) Run(state multistep.StateBag) multistep.StepAction
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NETWORKING INFO CONFIGURATION
|
||||||
|
ipAddName := fmt.Sprintf("ipres_%s", config.ImageName)
|
||||||
|
log.Printf("MEGAN ipADDName is %s", ipAddName)
|
||||||
|
secListName := "Megan_packer_test"
|
||||||
|
|
||||||
|
netInfo := compute.NetworkingInfo{
|
||||||
|
Nat: []string{ipAddName},
|
||||||
|
SecLists: []string{secListName},
|
||||||
|
}
|
||||||
|
fmt.Sprintf("Megan netInfo is %#v", netInfo)
|
||||||
|
|
||||||
|
// INSTANCE LAUNCH
|
||||||
|
|
||||||
// get instances client
|
// get instances client
|
||||||
instanceClient := client.Instances()
|
instanceClient := client.Instances()
|
||||||
|
|
||||||
// Instances Input
|
// Instances Input
|
||||||
input := &compute.CreateInstanceInput{
|
input := &compute.CreateInstanceInput{
|
||||||
Name: config.ImageName,
|
Name: config.ImageName,
|
||||||
Shape: config.Shape,
|
Shape: config.Shape,
|
||||||
ImageList: config.ImageList,
|
ImageList: config.ImageList,
|
||||||
SSHKeys: []string{keyInfo.Name},
|
SSHKeys: []string{keyInfo.Name},
|
||||||
|
Networking: map[string]compute.NetworkingInfo{"eth0": netInfo},
|
||||||
}
|
}
|
||||||
|
|
||||||
instanceInfo, err := instanceClient.CreateInstance(input)
|
instanceInfo, err := instanceClient.CreateInstance(input)
|
||||||
|
|
Loading…
Reference in New Issue