Merge pull request #6338 from harveylowndes/support-freeform-tagging-oci-images

Support freeform tagging of OCI images
This commit is contained in:
Megan Marsh 2018-08-29 15:39:13 -07:00 committed by GitHub
commit 7f0c540ef2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 0 deletions

View File

@ -8,6 +8,7 @@ import (
"log"
"os"
"path/filepath"
"strings"
"github.com/hashicorp/packer/common"
"github.com/hashicorp/packer/helper/communicator"
@ -62,6 +63,9 @@ type Config struct {
// Networking
SubnetID string `mapstructure:"subnet_ocid"`
// Tagging
Tags map[string]string `mapstructure:"tags"`
ctx interpolate.Context
}
@ -180,6 +184,30 @@ func NewConfig(raws ...interface{}) (*Config, error) {
errs, errors.New("'base_image_ocid' must be specified"))
}
// Validate tag lengths. TODO (hlowndes) maximum number of tags allowed.
if c.Tags != nil {
for k, v := range c.Tags {
k = strings.TrimSpace(k)
v = strings.TrimSpace(v)
if len(k) > 100 {
errs = packer.MultiErrorAppend(
errs, fmt.Errorf("Tag key length too long. Maximum 100 but found %d. Key: %s", len(k), k))
}
if len(k) == 0 {
errs = packer.MultiErrorAppend(
errs, errors.New("Tag key empty in config"))
}
if len(v) > 100 {
errs = packer.MultiErrorAppend(
errs, fmt.Errorf("Tag value length too long. Maximum 100 but found %d. Key: %s", len(v), k))
}
if len(v) == 0 {
errs = packer.MultiErrorAppend(
errs, errors.New("Tag value empty in config"))
}
}
}
if c.ImageName == "" {
name, err := interpolate.Render("packer-{{timestamp}}", nil)
if err != nil {

View File

@ -80,6 +80,7 @@ func (d *driverOCI) CreateImage(ctx context.Context, id string) (core.Image, err
CompartmentId: &d.cfg.CompartmentID,
InstanceId: &id,
DisplayName: &d.cfg.ImageName,
FreeformTags: d.cfg.Tags,
}})
if err != nil {

View File

@ -138,6 +138,13 @@ launched instance.
init. See [the Oracle docs](https://docs.us-phoenix-1.oraclecloud.com/api/#/en/iaas/20160918/LaunchInstanceDetails) for more details. Example:
`"user_data_file": "./boot_config/myscript.sh"`
- `tags` (map of strings) - Add one or more freeform tags to the resulting custom image. See [the Oracle docs](https://docs.cloud.oracle.com/iaas/Content/Identity/Concepts/taggingoverview.htm) for more details. Example:
``` {.yaml}
"tags":
"tag1": "value1"
"tag2": "value2"
```
## Basic Example