PROGRESS! Now it only fails on the snapshot step

This commit is contained in:
Megan Marsh 2018-01-19 15:37:06 -08:00 committed by Matthew Hooker
parent f208a071a4
commit 69ba710c2a
No known key found for this signature in database
GPG Key ID: 7B5F933D9CE8C6A1
3 changed files with 31 additions and 8 deletions

View File

@ -3,7 +3,6 @@ package classic
import (
"fmt"
"log"
"strings"
"github.com/hashicorp/go-cleanhttp"
"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{
Debug: b.config.PackerDebug,
DebugKeyPath: fmt.Sprintf("oci_classic_%s.pem", b.config.PackerBuildName),
PrivateKeyFile: strings.TrimSpace(b.config.Comm.SSHPrivateKey),
PrivateKeyFile: b.config.Comm.SSHPrivateKey,
},
&stepCreateIPReservation{},
&stepCreateInstance{},

View File

@ -1,6 +1,7 @@
package classic
import (
"fmt"
"log"
"github.com/hashicorp/go-oracle-terraform/compute"
@ -13,12 +14,14 @@ type stepCreateIPReservation struct{}
func (s *stepCreateIPReservation) Run(state multistep.StateBag) multistep.StepAction {
ui := state.Get("ui").(packer.Ui)
ui.Say("Creating IP reservation...")
config := state.Get("config").(*Config)
client := state.Get("client").(*compute.ComputeClient)
iprClient := client.IPReservations()
// TODO: add optional Name and Tags
IPInput := &compute.CreateIPReservationInput{
ParentPool: compute.PublicReservationPool,
Permanent: true,
Name: fmt.Sprintf("ipres_%s", config.ImageName),
}
ipRes, err := iprClient.CreateIPReservation(IPInput)
if err != nil {

View File

@ -2,6 +2,7 @@ package classic
import (
"fmt"
"log"
"strings"
"github.com/hashicorp/go-oracle-terraform/compute"
@ -17,9 +18,13 @@ func (s *stepCreateInstance) Run(state multistep.StateBag) multistep.StepAction
ui.Say("Creating Instance...")
config := state.Get("config").(*Config)
client := state.Get("client").(*compute.ComputeClient)
// SSH KEY CONFIGURATION
// grab packer-generated key from statebag context.
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)
sshKeysClient := client.SSHKeys()
@ -28,9 +33,11 @@ func (s *stepCreateInstance) Run(state multistep.StateBag) multistep.StepAction
Key: sshPublicKey,
Enabled: true,
}
// Load the packer-generated SSH key into the Oracle Compute cloud.
keyInfo, err := sshKeysClient.CreateSSHKey(&sshKeysInput)
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") {
updateKeysInput := compute.UpdateSSHKeyInput{
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
instanceClient := client.Instances()
// Instances Input
input := &compute.CreateInstanceInput{
Name: config.ImageName,
Shape: config.Shape,
ImageList: config.ImageList,
SSHKeys: []string{keyInfo.Name},
Name: config.ImageName,
Shape: config.Shape,
ImageList: config.ImageList,
SSHKeys: []string{keyInfo.Name},
Networking: map[string]compute.NetworkingInfo{"eth0": netInfo},
}
instanceInfo, err := instanceClient.CreateInstance(input)