Merge pull request #6498 from neumayer/ocimetadata

Allow instance metadata to be specified in config
This commit is contained in:
Andrew Pryde 2018-07-18 18:27:27 +01:00 committed by GitHub
commit 67f039509a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 0 deletions

View File

@ -48,6 +48,13 @@ type Config struct {
// Instance // Instance
InstanceName string `mapstructure:"instance_name"` InstanceName string `mapstructure:"instance_name"`
// Metadata optionally contains custom metadata key/value pairs provided in the
// configuration. While this can be used to set metadata["user_data"] the explicit
// "user_data" and "user_data_file" values will have precedence.
// An instance's metadata can be obtained from at http://169.254.169.254 on the
// launched instance.
Metadata map[string]string `mapstructure:"metadata"`
// UserData and UserDataFile file are both optional and mutually exclusive. // UserData and UserDataFile file are both optional and mutually exclusive.
UserData string `mapstructure:"user_data"` UserData string `mapstructure:"user_data"`
UserDataFile string `mapstructure:"user_data_file"` UserDataFile string `mapstructure:"user_data_file"`

View File

@ -29,6 +29,9 @@ func testConfig(accessConfFile *os.File) map[string]interface{} {
// Comm // Comm
"ssh_username": "opc", "ssh_username": "opc",
"use_private_ip": false, "use_private_ip": false,
"metadata": map[string]string{
"key": "value",
},
} }
} }

View File

@ -42,6 +42,11 @@ func (d *driverOCI) CreateInstance(ctx context.Context, publicKey string) (strin
metadata := map[string]string{ metadata := map[string]string{
"ssh_authorized_keys": publicKey, "ssh_authorized_keys": publicKey,
} }
if d.cfg.Metadata != nil {
for key, value := range d.cfg.Metadata {
metadata[key] = value
}
}
if d.cfg.UserData != "" { if d.cfg.UserData != "" {
metadata["user_data"] = d.cfg.UserData metadata["user_data"] = d.cfg.UserData
} }

View File

@ -125,6 +125,10 @@ builder.
- `use_private_ip` (boolean) - Use private ip addresses to connect to the instance via ssh. - `use_private_ip` (boolean) - Use private ip addresses to connect to the instance via ssh.
- `metadata` (map of strings) - Metadata optionally contains custom metadata key/value pairs provided in the
configuration. While this can be used to set metadata["user_data"] the explicit "user_data" and "user_data_file" values will have precedence. An instance's metadata can be obtained from at http://169.254.169.254 on the
launched instance.
- `user_data` (string) - user_data to be used by cloud - `user_data` (string) - user_data to be used by cloud
init. See [the Oracle docs](https://docs.us-phoenix-1.oraclecloud.com/api/#/en/iaas/20160918/LaunchInstanceDetails) for more details. Generally speaking, it is easier to use the `user_data_file`, init. See [the Oracle docs](https://docs.us-phoenix-1.oraclecloud.com/api/#/en/iaas/20160918/LaunchInstanceDetails) for more details. Generally speaking, it is easier to use the `user_data_file`,
but you can use this option to put either the plaintext data or the base64 but you can use this option to put either the plaintext data or the base64