fix (builder/oracle-oci): add freeform and defined tags to create_vnic_details

This commit is contained in:
js-g 2020-09-08 14:33:50 -04:00
parent 254716a02a
commit dd54651125
4 changed files with 31 additions and 22 deletions

View File

@ -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 {

View File

@ -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},

View File

@ -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

View File

@ -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\"}}"
}
}
```