From 69ba710c2a1661eab9f26239d445b2666864dfb0 Mon Sep 17 00:00:00 2001 From: Megan Marsh Date: Fri, 19 Jan 2018 15:37:06 -0800 Subject: [PATCH] PROGRESS! Now it only fails on the snapshot step --- builder/oracle/classic/builder.go | 3 +- .../classic/step_create_IP_reservation.go | 3 ++ .../oracle/classic/step_create_instance.go | 33 +++++++++++++++---- 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/builder/oracle/classic/builder.go b/builder/oracle/classic/builder.go index b7773ee19..4501456d2 100644 --- a/builder/oracle/classic/builder.go +++ b/builder/oracle/classic/builder.go @@ -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{}, diff --git a/builder/oracle/classic/step_create_IP_reservation.go b/builder/oracle/classic/step_create_IP_reservation.go index f3f898eaa..f74dd6bb1 100644 --- a/builder/oracle/classic/step_create_IP_reservation.go +++ b/builder/oracle/classic/step_create_IP_reservation.go @@ -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 { diff --git a/builder/oracle/classic/step_create_instance.go b/builder/oracle/classic/step_create_instance.go index 1456da99e..1cbfcbcc6 100644 --- a/builder/oracle/classic/step_create_instance.go +++ b/builder/oracle/classic/step_create_instance.go @@ -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)