diff --git a/builder/oracle/oci/config.go b/builder/oracle/oci/config.go index 943bd32fa..50c442fe1 100644 --- a/builder/oracle/oci/config.go +++ b/builder/oracle/oci/config.go @@ -283,6 +283,18 @@ func (c *Config) Prepare(raws ...interface{}) error { errs, errors.New("'shape' must be specified")) } + if strings.HasSuffix(c.Shape, "Flex") { + if c.ShapeConfig.Ocpus == nil { + errs = packersdk.MultiErrorAppend( + errs, errors.New("'Ocpus' must be specified when using flexible shapes")) + } + } + + if c.ShapeConfig.MemoryInGBs != nil && c.ShapeConfig.Ocpus == nil { + errs = packersdk.MultiErrorAppend( + errs, errors.New("'Ocpus' must be specified if memory_in_gbs is specified")) + } + if (c.SubnetID == "") && (c.CreateVnicDetails.SubnetId == nil) { errs = packersdk.MultiErrorAppend( errs, errors.New("'subnet_ocid' must be specified")) diff --git a/builder/oracle/oci/driver_oci.go b/builder/oracle/oci/driver_oci.go index 2d8ea27e8..1b8f978d3 100644 --- a/builder/oracle/oci/driver_oci.go +++ b/builder/oracle/oci/driver_oci.go @@ -95,11 +95,6 @@ func (d *driverOCI) CreateInstance(ctx context.Context, publicKey string) (strin FreeformTags: d.cfg.CreateVnicDetails.FreeformTags, } - LaunchInstanceShapeConfigDetails := core.LaunchInstanceShapeConfigDetails{ - Ocpus: d.cfg.ShapeConfig.Ocpus, - MemoryInGBs: d.cfg.ShapeConfig.MemoryInGBs, - } - // Determine base image ID var imageId *string if d.cfg.BaseImageID != "" { @@ -159,11 +154,18 @@ func (d *driverOCI) CreateInstance(ctx context.Context, publicKey string) (strin DisplayName: d.cfg.InstanceName, FreeformTags: d.cfg.InstanceTags, Shape: &d.cfg.Shape, - ShapeConfig: &LaunchInstanceShapeConfigDetails, SourceDetails: InstanceSourceDetails, Metadata: metadata, } + if d.cfg.ShapeConfig.Ocpus != nil { + LaunchInstanceShapeConfigDetails := core.LaunchInstanceShapeConfigDetails{ + Ocpus: d.cfg.ShapeConfig.Ocpus, + MemoryInGBs: d.cfg.ShapeConfig.MemoryInGBs, + } + instanceDetails.ShapeConfig = &LaunchInstanceShapeConfigDetails + } + instance, err := d.computeClient.LaunchInstance(context.TODO(), core.LaunchInstanceRequest{ LaunchInstanceDetails: instanceDetails, RequestMetadata: requestMetadata, diff --git a/website/content/docs/builders/oracle/oci.mdx b/website/content/docs/builders/oracle/oci.mdx index d9d19f17c..e63d8fa0b 100644 --- a/website/content/docs/builders/oracle/oci.mdx +++ b/website/content/docs/builders/oracle/oci.mdx @@ -100,10 +100,7 @@ can also be supplied to override the typical auto-generated key: [ListShapes](https://docs.us-phoenix-1.oraclecloud.com/api/#/en/iaas/20160918/Shape/ListShapes) operation available in the Core Services API. -- `shape_config` (map of strings) - The shape configuration for an instance. The shape configuration determines the resources - allocated to an instance. Options: - - `ocpus` - The total number of OCPUs available to the instance. - - `memory_in_gbs` - The total amount of memory, in gigabytes, available to the instance. + When using flexible shapes, ocpus must be set. - `subnet_ocid` (string) - The name of the subnet within which a new instance is launched and provisioned. @@ -192,6 +189,11 @@ can also be supplied to override the typical auto-generated key: - `use_private_ip` (boolean) - Use private ip addresses to connect to the instance via ssh. +- `shape_config` (object) - The shape configuration for an instance. The shape configuration determines the resources + allocated to an instance. Options: + - `ocpus` (required when using flexible shapes or memory_in_gbs is set) (float32) - The total number of OCPUs available to the instance. + - `memory_in_gbs` (optional) (float32) - The total amount of memory, in gigabytes, available to the instance. + - `metadata` (map of strings) - Metadata optionally contains custom metadata key/value pairs provided in the configuration. While this can be used to