From c892f0582b155b7d741a22b6edd770ddc8e677c5 Mon Sep 17 00:00:00 2001 From: js-g Date: Fri, 2 Oct 2020 22:27:34 -0400 Subject: [PATCH] GH#6844: allow image compartment to be specified --- builder/oracle/oci/config.go | 9 +++++++-- builder/oracle/oci/config.hcl2spec.go | 2 ++ builder/oracle/oci/driver_oci.go | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/builder/oracle/oci/config.go b/builder/oracle/oci/config.go index 79666620f..0b3eb9bff 100644 --- a/builder/oracle/oci/config.go +++ b/builder/oracle/oci/config.go @@ -69,8 +69,9 @@ type Config struct { CompartmentID string `mapstructure:"compartment_ocid"` // Image - BaseImageID string `mapstructure:"base_image_ocid"` - ImageName string `mapstructure:"image_name"` + BaseImageID string `mapstructure:"base_image_ocid"` + ImageName string `mapstructure:"image_name"` + ImageCompartmentID string `mapstructure:"image_compartment_ocid"` // Instance InstanceName string `mapstructure:"instance_name"` @@ -254,6 +255,10 @@ func (c *Config) Prepare(raws ...interface{}) error { c.CompartmentID = tenancyOCID } + if c.ImageCompartmentID == "" { + c.ImageCompartmentID = c.CompartmentID + } + if c.Shape == "" { errs = packer.MultiErrorAppend( errs, errors.New("'shape' must be specified")) diff --git a/builder/oracle/oci/config.hcl2spec.go b/builder/oracle/oci/config.hcl2spec.go index 0dc4af8a4..647244f12 100644 --- a/builder/oracle/oci/config.hcl2spec.go +++ b/builder/oracle/oci/config.hcl2spec.go @@ -77,6 +77,7 @@ type FlatConfig struct { CompartmentID *string `mapstructure:"compartment_ocid" cty:"compartment_ocid" hcl:"compartment_ocid"` BaseImageID *string `mapstructure:"base_image_ocid" cty:"base_image_ocid" hcl:"base_image_ocid"` ImageName *string `mapstructure:"image_name" cty:"image_name" hcl:"image_name"` + ImageCompartmentID *string `mapstructure:"image_compartment_ocid" cty:"image_compartment_ocid" hcl:"image_compartment_ocid"` InstanceName *string `mapstructure:"instance_name" cty:"instance_name" hcl:"instance_name"` InstanceTags map[string]string `mapstructure:"instance_tags" cty:"instance_tags" hcl:"instance_tags"` InstanceDefinedTags map[string]map[string]interface{} `mapstructure:"instance_defined_tags" cty:"instance_defined_tags" hcl:"instance_defined_tags"` @@ -171,6 +172,7 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec { "compartment_ocid": &hcldec.AttrSpec{Name: "compartment_ocid", Type: cty.String, Required: false}, "base_image_ocid": &hcldec.AttrSpec{Name: "base_image_ocid", Type: cty.String, Required: false}, "image_name": &hcldec.AttrSpec{Name: "image_name", Type: cty.String, Required: false}, + "image_compartment_ocid": &hcldec.AttrSpec{Name: "image_compartment_ocid", Type: cty.String, Required: false}, "instance_name": &hcldec.AttrSpec{Name: "instance_name", Type: cty.String, Required: false}, "instance_tags": &hcldec.AttrSpec{Name: "instance_tags", Type: cty.Map(cty.String), Required: false}, "instance_defined_tags": &hcldec.AttrSpec{Name: "instance_defined_tags", Type: cty.Map(cty.String), Required: false}, diff --git a/builder/oracle/oci/driver_oci.go b/builder/oracle/oci/driver_oci.go index 011908232..3901a0bac 100644 --- a/builder/oracle/oci/driver_oci.go +++ b/builder/oracle/oci/driver_oci.go @@ -99,7 +99,7 @@ func (d *driverOCI) CreateInstance(ctx context.Context, publicKey string) (strin // CreateImage creates a new custom image. func (d *driverOCI) CreateImage(ctx context.Context, id string) (core.Image, error) { res, err := d.computeClient.CreateImage(ctx, core.CreateImageRequest{CreateImageDetails: core.CreateImageDetails{ - CompartmentId: &d.cfg.CompartmentID, + CompartmentId: &d.cfg.ImageCompartmentID, InstanceId: &id, DisplayName: &d.cfg.ImageName, FreeformTags: d.cfg.Tags,