diff --git a/builder/oracle/oci/config.go b/builder/oracle/oci/config.go index 0277518a5..79666620f 100644 --- a/builder/oracle/oci/config.go +++ b/builder/oracle/oci/config.go @@ -77,6 +77,7 @@ type Config struct { InstanceTags map[string]string `mapstructure:"instance_tags"` InstanceDefinedTags map[string]map[string]interface{} `mapstructure:"instance_defined_tags"` Shape string `mapstructure:"shape"` + BootVolumeSizeInGBs int64 `mapstructure:"disk_size"` // Metadata optionally contains custom metadata key/value pairs provided in the // configuration. While this can be used to set metadata["user_data"] the explicit @@ -326,6 +327,15 @@ func (c *Config) Prepare(raws ...interface{}) error { } } + // Set default boot volume size to 50 if not set + // Check if size set is allowed by OCI + if c.BootVolumeSizeInGBs == 0 { + c.BootVolumeSizeInGBs = 50 + } else if c.BootVolumeSizeInGBs < 50 || c.BootVolumeSizeInGBs > 16384 { + errs = packer.MultiErrorAppend( + errs, errors.New("'disk_size' must be between 50 and 16384 GBs")) + } + if errs != nil && len(errs.Errors) > 0 { return errs } diff --git a/builder/oracle/oci/config.hcl2spec.go b/builder/oracle/oci/config.hcl2spec.go index 21afb0d92..0dc4af8a4 100644 --- a/builder/oracle/oci/config.hcl2spec.go +++ b/builder/oracle/oci/config.hcl2spec.go @@ -81,6 +81,7 @@ type FlatConfig struct { 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"` Shape *string `mapstructure:"shape" cty:"shape" hcl:"shape"` + BootVolumeSizeInGBs *int64 `mapstructure:"disk_size" cty:"disk_size" hcl:"disk_size"` Metadata map[string]string `mapstructure:"metadata" cty:"metadata" hcl:"metadata"` UserData *string `mapstructure:"user_data" cty:"user_data" hcl:"user_data"` UserDataFile *string `mapstructure:"user_data_file" cty:"user_data_file" hcl:"user_data_file"` @@ -174,6 +175,7 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec { "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}, "shape": &hcldec.AttrSpec{Name: "shape", Type: cty.String, Required: false}, + "disk_size": &hcldec.AttrSpec{Name: "disk_size", Type: cty.Number, Required: false}, "metadata": &hcldec.AttrSpec{Name: "metadata", Type: cty.Map(cty.String), Required: false}, "user_data": &hcldec.AttrSpec{Name: "user_data", Type: cty.String, Required: false}, "user_data_file": &hcldec.AttrSpec{Name: "user_data_file", Type: cty.String, Required: false}, diff --git a/builder/oracle/oci/config_test.go b/builder/oracle/oci/config_test.go index 2f85b7a8d..1026d8aed 100644 --- a/builder/oracle/oci/config_test.go +++ b/builder/oracle/oci/config_test.go @@ -44,7 +44,8 @@ func testConfig(accessConfFile *os.File) map[string]interface{} { "create_vnic_details": map[string]interface{}{ "nsg_ids": []string{"ocd1..."}, }, - "shape": "VM.Standard1.1", + "shape": "VM.Standard1.1", + "disk_size": 60, } } diff --git a/builder/oracle/oci/driver_oci.go b/builder/oracle/oci/driver_oci.go index a441de7dd..011908232 100644 --- a/builder/oracle/oci/driver_oci.go +++ b/builder/oracle/oci/driver_oci.go @@ -56,7 +56,6 @@ func (d *driverOCI) CreateInstance(ctx context.Context, publicKey string) (strin CompartmentId: &d.cfg.CompartmentID, DefinedTags: d.cfg.InstanceDefinedTags, FreeformTags: d.cfg.InstanceTags, - ImageId: &d.cfg.BaseImageID, Shape: &d.cfg.Shape, SubnetId: &d.cfg.SubnetID, Metadata: metadata, @@ -82,6 +81,12 @@ func (d *driverOCI) CreateInstance(ctx context.Context, publicKey string) (strin instanceDetails.CreateVnicDetails = &CreateVnicDetails + // Create Source details which will be used to Launch Instance + instanceDetails.SourceDetails = core.InstanceSourceViaImageDetails{ + ImageId: &d.cfg.BaseImageID, + BootVolumeSizeInGBs: &d.cfg.BootVolumeSizeInGBs, + } + instance, err := d.computeClient.LaunchInstance(context.TODO(), core.LaunchInstanceRequest{LaunchInstanceDetails: instanceDetails}) if err != nil { diff --git a/website/pages/docs/builders/oracle/oci.mdx b/website/pages/docs/builders/oracle/oci.mdx index ab95924a8..956d9fdaf 100644 --- a/website/pages/docs/builders/oracle/oci.mdx +++ b/website/pages/docs/builders/oracle/oci.mdx @@ -139,7 +139,7 @@ can also be supplied to override the typical auto-generated key: - `instance_name` (string) - The name to assign to the instance used for the image creation process. If not set a name of the form `instanceYYYYMMDDhhmmss` will be used. -- `instance_tags` (map of strings) - Add one or more freeform tags to the instance used for the +- `instance_tags` (map of strings) - Add one or more freeform tags to the instance used for the image creation process. - `instance_defined_tags` (map of maps of strings) - Add one or more defined tags for a given namespace @@ -153,6 +153,10 @@ can also be supplied to override the typical auto-generated key: [the Oracle docs](https://docs.cloud.oracle.com/en-us/iaas/Content/Network/Tasks/managingVNICs.htm) for more information about VNICs. +- `disk_size` (int64) - The size of the boot volume in GBs. Minimum value is 50 and maximum value is 16384 (16TB). + Sets the [BootVolumeSizeInGBs](https://godoc.org/github.com/oracle/oci-go-sdk/core#InstanceConfigurationInstanceSourceViaImageDetails) + when launching the instance. Defaults to `50`. + - `use_private_ip` (boolean) - Use private ip addresses to connect to the instance via ssh.