From 72166febee89db489655938a047500a4569c6b3e Mon Sep 17 00:00:00 2001 From: Kostas Date: Wed, 30 Sep 2020 13:31:37 +0300 Subject: [PATCH] allow to specify boot volume size --- builder/oracle/oci/config.go | 10 ++++++++++ builder/oracle/oci/config.hcl2spec.go | 2 ++ builder/oracle/oci/config_test.go | 3 ++- builder/oracle/oci/driver_oci.go | 7 ++++++- 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/builder/oracle/oci/config.go b/builder/oracle/oci/config.go index 0277518a5..c63608c6b 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:"boot_volume_size_in_gbs"` // 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("'boot_volume_size_in_gbs' 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..83e5c0785 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:"boot_volume_size_in_gbs" cty:"boot_volume_size_in_gbs" hcl:"boot_volume_size_in_gbs"` 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}, + "boot_volume_size_in_gbs": &hcldec.AttrSpec{Name: "boot_volume_size_in_gbs", 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..eeeb189af 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", + "boot_volume_size_in_gbs": 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 {