From dd54651125fe4daf6aa90d7e8da44fece0ad7bf3 Mon Sep 17 00:00:00 2001 From: js-g Date: Tue, 8 Sep 2020 14:33:50 -0400 Subject: [PATCH] fix (builder/oracle-oci): add freeform and defined tags to create_vnic_details --- builder/oracle/oci/config.go | 16 +++++++++------- builder/oracle/oci/config.hcl2spec.go | 18 +++++++++++------- builder/oracle/oci/driver_oci.go | 2 ++ website/pages/docs/builders/oracle/oci.mdx | 17 +++++++++-------- 4 files changed, 31 insertions(+), 22 deletions(-) diff --git a/builder/oracle/oci/config.go b/builder/oracle/oci/config.go index 417174a54..d56cb7375 100644 --- a/builder/oracle/oci/config.go +++ b/builder/oracle/oci/config.go @@ -24,13 +24,15 @@ import ( type CreateVnicDetailsRaw struct { // fields that can be specified under "create_vnic_details" - AssignPublicIp *bool `mapstructure:"assign_public_ip" required:"false"` - DisplayName *string `mapstructure:"display_name" required:"false"` - HostnameLabel *string `mapstructure:"hostname_label" required:"false"` - NsgIds []string `mapstructure:"nsg_ids" required:"false"` - PrivateIp *string `mapstructure:"private_ip" required:"false"` - SkipSourceDestCheck *bool `mapstructure:"skip_source_dest_check" required:"false"` - SubnetId *string `mapstructure:"subnet_id" required:"false"` + AssignPublicIp *bool `mapstructure:"assign_public_ip" required:"false"` + DefinedTags map[string]map[string]interface{} `mapstructure:"defined_tags" required:"false"` + DisplayName *string `mapstructure:"display_name" required:"false"` + FreeformTags map[string]string `mapstructure:"tags" required:"false"` + HostnameLabel *string `mapstructure:"hostname_label" required:"false"` + NsgIds []string `mapstructure:"nsg_ids" required:"false"` + PrivateIp *string `mapstructure:"private_ip" required:"false"` + SkipSourceDestCheck *bool `mapstructure:"skip_source_dest_check" required:"false"` + SubnetId *string `mapstructure:"subnet_id" required:"false"` } type Config struct { diff --git a/builder/oracle/oci/config.hcl2spec.go b/builder/oracle/oci/config.hcl2spec.go index 45a9b12dc..39570d46b 100644 --- a/builder/oracle/oci/config.hcl2spec.go +++ b/builder/oracle/oci/config.hcl2spec.go @@ -188,13 +188,15 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec { // FlatCreateVnicDetailsRaw is an auto-generated flat version of CreateVnicDetailsRaw. // Where the contents of a field with a `mapstructure:,squash` tag are bubbled up. type FlatCreateVnicDetailsRaw struct { - AssignPublicIp *bool `mapstructure:"assign_public_ip" required:"false" cty:"assign_public_ip" hcl:"assign_public_ip"` - DisplayName *string `mapstructure:"display_name" required:"false" cty:"display_name" hcl:"display_name"` - HostnameLabel *string `mapstructure:"hostname_label" required:"false" cty:"hostname_label" hcl:"hostname_label"` - NsgIds []string `mapstructure:"nsg_ids" required:"false" cty:"nsg_ids" hcl:"nsg_ids"` - PrivateIp *string `mapstructure:"private_ip" required:"false" cty:"private_ip" hcl:"private_ip"` - SkipSourceDestCheck *bool `mapstructure:"skip_source_dest_check" required:"false" cty:"skip_source_dest_check" hcl:"skip_source_dest_check"` - SubnetId *string `mapstructure:"subnet_id" required:"false" cty:"subnet_id" hcl:"subnet_id"` + AssignPublicIp *bool `mapstructure:"assign_public_ip" required:"false" cty:"assign_public_ip" hcl:"assign_public_ip"` + DefinedTags map[string]map[string]interface{} `mapstructure:"defined_tags" required:"false" cty:"defined_tags" hcl:"defined_tags"` + DisplayName *string `mapstructure:"display_name" required:"false" cty:"display_name" hcl:"display_name"` + FreeformTags map[string]string `mapstructure:"tags" required:"false" cty:"tags" hcl:"tags"` + HostnameLabel *string `mapstructure:"hostname_label" required:"false" cty:"hostname_label" hcl:"hostname_label"` + NsgIds []string `mapstructure:"nsg_ids" required:"false" cty:"nsg_ids" hcl:"nsg_ids"` + PrivateIp *string `mapstructure:"private_ip" required:"false" cty:"private_ip" hcl:"private_ip"` + SkipSourceDestCheck *bool `mapstructure:"skip_source_dest_check" required:"false" cty:"skip_source_dest_check" hcl:"skip_source_dest_check"` + SubnetId *string `mapstructure:"subnet_id" required:"false" cty:"subnet_id" hcl:"subnet_id"` } // FlatMapstructure returns a new FlatCreateVnicDetailsRaw. @@ -210,7 +212,9 @@ func (*CreateVnicDetailsRaw) FlatMapstructure() interface{ HCL2Spec() map[string func (*FlatCreateVnicDetailsRaw) HCL2Spec() map[string]hcldec.Spec { s := map[string]hcldec.Spec{ "assign_public_ip": &hcldec.AttrSpec{Name: "assign_public_ip", Type: cty.Bool, Required: false}, + "defined_tags": &hcldec.AttrSpec{Name: "defined_tags", Type: cty.Map(cty.String), Required: false}, "display_name": &hcldec.AttrSpec{Name: "display_name", Type: cty.String, Required: false}, + "tags": &hcldec.AttrSpec{Name: "tags", Type: cty.Map(cty.String), Required: false}, "hostname_label": &hcldec.AttrSpec{Name: "hostname_label", Type: cty.String, Required: false}, "nsg_ids": &hcldec.AttrSpec{Name: "nsg_ids", Type: cty.List(cty.String), Required: false}, "private_ip": &hcldec.AttrSpec{Name: "private_ip", Type: cty.String, Required: false}, diff --git a/builder/oracle/oci/driver_oci.go b/builder/oracle/oci/driver_oci.go index f698ae7da..a441de7dd 100644 --- a/builder/oracle/oci/driver_oci.go +++ b/builder/oracle/oci/driver_oci.go @@ -76,6 +76,8 @@ func (d *driverOCI) CreateInstance(ctx context.Context, publicKey string) (strin PrivateIp: d.cfg.CreateVnicDetails.PrivateIp, SkipSourceDestCheck: d.cfg.CreateVnicDetails.SkipSourceDestCheck, SubnetId: d.cfg.CreateVnicDetails.SubnetId, + DefinedTags: d.cfg.CreateVnicDetails.DefinedTags, + FreeformTags: d.cfg.CreateVnicDetails.FreeformTags, } instanceDetails.CreateVnicDetails = &CreateVnicDetails diff --git a/website/pages/docs/builders/oracle/oci.mdx b/website/pages/docs/builders/oracle/oci.mdx index d77d424a7..f4e7e8c88 100644 --- a/website/pages/docs/builders/oracle/oci.mdx +++ b/website/pages/docs/builders/oracle/oci.mdx @@ -141,9 +141,10 @@ builder. to the instance used for the image creation process. - `create_vnic_details` (map of strings) - Specify details for the virtual network interface card (VNIC) - that get attached to the instance. Possible keys (all optional) are: `assign_public_ip` (bool), + that is attached to the instance. Possible keys (all optional) are: `assign_public_ip` (bool), `display_name` (string), `hostname_lable` (string), `nsg_ids` (list), `private_ip` (string), - `skip_source_dest_check` (bool), and `subnet_id` (string). See + `skip_source_dest_check` (bool), `subnet_id` (string), `tags` (map of string), and `defined_tags` + (map of maps of strings). See [the Oracle docs](https://docs.cloud.oracle.com/en-us/iaas/Content/Network/Tasks/managingVNICs.htm) for more information about VNICs. @@ -252,7 +253,7 @@ Build 'oracle-oci' finished. [opc@packerhost ~]$ ``` -## Auto-assign Tags and Network Security Groups to Instance +## Assigning Tags and Network Security Groups to the Instance Tags are useful for breaking down costs and usage. The keys `instance_tags` and `instance_defined_tags` are assigned to the temporary instance, whereas `tags` and `defined_tags` are assigned to the resulting image. @@ -261,19 +262,19 @@ Network Security Groups (NSGs) are used for granting networking permissions to the instance. Depending on network (VCN and subnet) setup, this may be required for Packer to successfully SSH into the instance. NSGs are a property of the virtual network interface card (VNIC) attached to the instance, and -are listed in `nsg_ids` under `create_vnic_details`. +are listed in `nsg_ids` under `create_vnic_details`. ``` { - "name": "base-image-{{isotime \"20000102030405\"}}", + "name": "base-image-{{isotime \"20060102030405\"}}", "type": "oracle-oci", "availability_domain": "aaaa:PHX-AD-1", "base_image_ocid": "ocid1.image.oc1.iad.aaa", "compartment_ocid": "ocid1.compartment.oc1..aaa", - "image_name": "my-image-{{isotime \"20000102030405\"}}", + "image_name": "my-image-{{isotime \"20060102030405\"}}", "shape": "VM.Standard.E2.1", "subnet_ocid": "ocid1.subnet.oc1.iad.aaa", "use_private_ip": "true", - "instance_name": "packer-build-{{isotime \"20000102030405\"}}", + "instance_name": "packer-build-{{isotime \"20060102030405\"}}", "instance_tags": { "testing": "yes" }, "instance_defined_tags": { "Operations": { @@ -287,7 +288,7 @@ are listed in `nsg_ids` under `create_vnic_details`. "nsg_ids": ["ocid1.networksecuritygroup.oc1.iad.aaa"] }, "tags": { - "CreationDate": "{{isotime \"20000102 15:04:05 MST\"}}" + "CreationDate": "{{isotime \"20060102 03:04:05 MST\"}}" } } ```