diff --git a/docs/Writing Terraform configurations for OBMCS.md b/docs/Writing Terraform configurations for OBMCS.md index c91e508da0b..31ab66e7217 100644 --- a/docs/Writing Terraform configurations for OBMCS.md +++ b/docs/Writing Terraform configurations for OBMCS.md @@ -41,6 +41,15 @@ provider "baremetal" { private_key_path = "${var.private_key_path}" } ``` + +To specify a different region, include the region parameter in your provider definition. Not specifying a value will use the default `us-phoenix-1` region. +``` +provider "baremetal" { + ... + region = "us-ashburn-1" +} +``` + ## CamelCase The OBMCS API uses CamelCase in multiple places. Terraform doesn't support CamelCase in configuration files so we've replaced it with underscores. For example - diff --git a/docs/resources/core/instance.md b/docs/resources/core/instance.md index 2977394b749..aba706a1096 100644 --- a/docs/resources/core/instance.md +++ b/docs/resources/core/instance.md @@ -48,3 +48,6 @@ The following attributes are exported: * `region` - The region that contains the Availability Domain the instance is running in. * `shape` - The shape of the instance. The shape determines the number of CPUs and the amount of memory allocated to the instance. * `time_created` - The date and time the instance was created. + +* `public_ip` - The public ip of instance vnic (if enabled). +* `private_ip` - The private ip of instance vnic (if enabled). diff --git a/provider.go b/provider.go index 38b5eae969b..cada9f927a5 100644 --- a/provider.go +++ b/provider.go @@ -24,6 +24,7 @@ func init() { "private_key_path": "(Optional) The path to the user's PEM formatted private key.\n" + "A private_key or a private_key_path must be provided.", "private_key_password": "(Optional) The password used to secure the private key.", + "region": "(Optional) The region for API connections.", } } @@ -80,6 +81,13 @@ func schemaMap() map[string]*schema.Schema { Description: descriptions["private_key_password"], DefaultFunc: schema.EnvDefaultFunc("OBMCS_PRIVATE_KEY_PASSWORD", nil), }, + "region": { + Type: schema.TypeString, + Optional: true, + Default: "us-phoenix-1", + Description: descriptions["region"], + DefaultFunc: schema.EnvDefaultFunc("OBMCS_REGION", nil), + }, } } @@ -183,6 +191,7 @@ func providerConfig(d *schema.ResourceData) (client interface{}, err error) { privateKeyBuffer, hasKey := d.Get("private_key").(string) privateKeyPath, hasKeyPath := d.Get("private_key_path").(string) privateKeyPassword, hasKeyPass := d.Get("private_key_password").(string) + region, hasRegion := d.Get("region").(string) clientOpts := []baremetal.NewClientOptionsFunc{ func(o *baremetal.NewClientOptions) { @@ -206,6 +215,10 @@ func providerConfig(d *schema.ResourceData) (client interface{}, err error) { clientOpts = append(clientOpts, baremetal.PrivateKeyPassword(privateKeyPassword)) } + if hasRegion && region != "" { + clientOpts = append(clientOpts, baremetal.Region(region)) + } + client, err = baremetal.NewClient(userOCID, tenancyOCID, fingerprint, clientOpts...) return } diff --git a/vendor/github.com/MustWin/baremetal-sdk-go/README.md b/vendor/github.com/MustWin/baremetal-sdk-go/README.md index 68e74a615da..8fc6a6108c6 100644 --- a/vendor/github.com/MustWin/baremetal-sdk-go/README.md +++ b/vendor/github.com/MustWin/baremetal-sdk-go/README.md @@ -4,36 +4,42 @@ Package baremetal provides access to the Oracle BareMetal Cloud APIs. ## Usage -To use the Go BareMetal SDK instantiate a baremetal.Client, supplying +To use the Go BareMetal SDK instantiate a baremetal.Client, supplying your tenancy OCID, user OCID, RSA public key fingerprint, and RSA private key. -Then call functions as the example below illustrates. Note that error -handling has been omitted to add clarity. See [API Docs](https://docs.us-phoenix-1.oraclecloud.com/) for more information. - +Then call functions as the example below illustrates. ``` import ( - "fmt" - "crypto/rsa" + "fmt" "github.com/MustWin/baremetal-sdk-go" ) func main() { - privateKey, _ := baremetal.PrivateKeyFromFile("/path/to/key.pem", "keyPassword") - - client := baremetal.New( - "ocid1.tenancy.oc1..aaaaaaaaq3hulfjvrouw3e6qx2ncxtp256aq7etiabqqtzunnhxjslzkfyxq", - "ocid1.user.oc1..aaaaaaaaflxvsdpjs5ztahmsf7vjxy5kdqnuzyqpvwnncbkfhavexwd4w5ra", - "b4:8a:7d:54:e6:81:04:b2:99:8e:b3:ed:10:e2:12:2b", - privateKey, + client, err := baremetal.NewClient( + , + , + , + baremetal.PrivateKeyFilePath(), ) - availabilityDomains, _ := client.ListAvailablityDomains() + if err != nil { + fmt.Println("Error setting up bmc client\n", err) + } + + compartmentList, err := Client.ListCompartments(nil) - for _, ad := range availabilityDomains { - fmt.Println(ad.Name) + if err != nil { + fmt.Println("Error listing Compartments\n", err) + } + + for _, c := range compartments.Compartments { + fmt.Println(c.Name) } } ``` + +For more details, see the [API Docs](https://docs.us-phoenix-1.oraclecloud.com/) + ## Unit Testing Some of the tests rely on GOPATH to build a path where a test private key is located. If for some reason you have a composite GOPATH i.e /home/foo/go-projects:/usr/stuff diff --git a/vendor/github.com/MustWin/baremetal-sdk-go/client.go b/vendor/github.com/MustWin/baremetal-sdk-go/client.go index f6e1dcab123..8bd1e4dd2e3 100644 --- a/vendor/github.com/MustWin/baremetal-sdk-go/client.go +++ b/vendor/github.com/MustWin/baremetal-sdk-go/client.go @@ -1,42 +1,9 @@ // Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. /* - Package baremetal provides access to the Oracle Bare Metal Cloud API's - - Usage: - - To use the Go BareMetal SDK instantiate a baremetal.Client, supplying - your tenancy OCID, user OCID, RSA public key fingerprint, and RSA private key. - Then call functions as the example below illustrates. Note that error - handling has been omitted to add clarity. - - import ( - "fmt" - "crypto/rsa" - "github.com/MustWin/baremetal-sdk-go" - ) - - func main() { - privateKey, _ := baremetal.PrivateKeyFromFile("/path/to/key.pem", "keyPassword") - - client := baremetal.New( - "ocid1.tenancy.oc1..aaaaaaaaq3hulfjvrouw3e6qx2ncxtp256aq7etiabqqtzunnhxjslzkfyxq", - "ocid1.user.oc1..aaaaaaaaflxvsdpjs5ztahmsf7vjxy5kdqnuzyqpvwnncbkfhavexwd4w5ra", - "b4:8a:7d:54:e6:81:04:b2:99:8e:b3:ed:10:e2:12:2b", - privateKey, - ) - - availabilityDomains, _ := client.ListAvailablityDomains() - - for _, ad := range availabilityDomains { - fmt.Println(ad.Name) - } - - } - - For more details, see the API docs located here: - https://docs.us-phoenix-1.oraclecloud.com/Content/API/Concepts/usingapi.htm + Package baremetal provides access to the Oracle Bare Metal Cloud API's. See Readme for usage example. */ + package baremetal import ( @@ -64,6 +31,7 @@ type Client struct { type NewClientOptions struct { Transport http.RoundTripper UserAgent string + Region string keyPassword *string keyPath *string keyBytes []byte @@ -109,6 +77,13 @@ func UserAgent(userAgent string) NewClientOptionsFunc { } } +// Region assigns a region override for API connections +func Region(region string) NewClientOptionsFunc { + return func(o *NewClientOptions) { + o.Region = region + } +} + // NewClient creates and authenticates a BareMetal API client func NewClient(userOCID, tenancyOCID, keyFingerprint string, opts ...NewClientOptionsFunc) (*Client, error) { var err error @@ -119,6 +94,7 @@ func NewClient(userOCID, tenancyOCID, keyFingerprint string, opts ...NewClientOp } nco := &NewClientOptions{ Transport: &http.Transport{}, + Region: us_phoenix_1, } for _, opt := range opts { opt(nco) diff --git a/vendor/github.com/MustWin/baremetal-sdk-go/constants.go b/vendor/github.com/MustWin/baremetal-sdk-go/constants.go index 9d25617dc13..8b6f48012d0 100644 --- a/vendor/github.com/MustWin/baremetal-sdk-go/constants.go +++ b/vendor/github.com/MustWin/baremetal-sdk-go/constants.go @@ -60,19 +60,22 @@ const ( SDKVersion = "20160918" SDKVersion2 = "20170115" - identityServiceAPI = "https://identity.us-phoenix-1.oraclecloud.com" + us_ashburn_1 string = "us-ashburn-1" + us_phoenix_1 string = "us-phoenix-1" + + identityServiceAPI = "https://identity.%s.oraclecloud.com" identityServiceAPIVersion = SDKVersion - coreServiceAPI = "https://iaas.us-phoenix-1.oraclecloud.com" + coreServiceAPI = "https://iaas.%s.oraclecloud.com" coreServiceAPIVersion = SDKVersion - databaseServiceAPI = "https://database.us-phoenix-1.oraclecloud.com" + databaseServiceAPI = "https://database.%s.oraclecloud.com" databaseServiceAPIVersion = SDKVersion - objectStorageServiceAPI = "https://objectstorage.us-phoenix-1.oraclecloud.com" + objectStorageServiceAPI = "https://objectstorage.%s.oraclecloud.com" objectStorageServiceAPIVersion = SDKVersion - loadBalancerServiceAPI = "https://iaas.us-phoenix-1.oraclecloud.com" + loadBalancerServiceAPI = "https://iaas.%s.oraclecloud.com" loadBalancerServiceAPIVersion = SDKVersion2 // Header Keys diff --git a/vendor/github.com/MustWin/baremetal-sdk-go/object_storage_objects.go b/vendor/github.com/MustWin/baremetal-sdk-go/object_storage_objects.go index 5719967361d..b577d52feed 100644 --- a/vendor/github.com/MustWin/baremetal-sdk-go/object_storage_objects.go +++ b/vendor/github.com/MustWin/baremetal-sdk-go/object_storage_objects.go @@ -179,6 +179,9 @@ func (c *Client) HeadObject( headObject = &HeadObject{} e = resp.unmarshal(headObject) + headObject.Namespace = namespace + headObject.Bucket = bucketName + headObject.ID = objectName return } @@ -220,5 +223,9 @@ func (c *Client) PutObject( object = &Object{} e = resp.unmarshal(object) + object.Namespace = namespace + object.Bucket = bucketName + object.ID = objectName + object.Body = content return } diff --git a/vendor/github.com/MustWin/baremetal-sdk-go/request.go b/vendor/github.com/MustWin/baremetal-sdk-go/request.go index bb39ad3e56d..04359b70bb3 100644 --- a/vendor/github.com/MustWin/baremetal-sdk-go/request.go +++ b/vendor/github.com/MustWin/baremetal-sdk-go/request.go @@ -21,7 +21,7 @@ type urlParts []interface{} type request interface { marshalBody() ([]byte, error) marshalHeader() http.Header - marshalURL(urlBuilderFn) (val string, e error) + marshalURL(string, urlBuilderFn) (val string, e error) } // requestDetails is the concrete implementation of request. @@ -30,6 +30,7 @@ type request interface { // optionally, have one of the unexported structs from // request_requirements.go embedded. type requestDetails struct { + region string ids urlParts name resourceName optional interface{} @@ -93,6 +94,13 @@ func (r *requestDetails) marshalHeader() http.Header { oHeader[k] = v } + if md, ok := r.optional.(MetadataUnmarshallable); ok { + prefix := "opc-meta-" + for name, val := range md.GetMetadata() { + oHeader[prefix+name] = []string{val} + } + } + return oHeader } @@ -110,11 +118,11 @@ func (r *requestDetails) marshalQueryString() (vals url.Values, e error) { return } -func (r *requestDetails) marshalURL(urlFn urlBuilderFn) (val string, e error) { +func (r *requestDetails) marshalURL(region string, urlFn urlBuilderFn) (val string, e error) { var q url.Values if q, e = r.marshalQueryString(); e != nil { return } - val = urlFn(r.name, q, r.ids...) + val = urlFn(region, r.name, q, r.ids...) return } diff --git a/vendor/github.com/MustWin/baremetal-sdk-go/request_options.go b/vendor/github.com/MustWin/baremetal-sdk-go/request_options.go index ae10837780c..706fe7a6922 100644 --- a/vendor/github.com/MustWin/baremetal-sdk-go/request_options.go +++ b/vendor/github.com/MustWin/baremetal-sdk-go/request_options.go @@ -220,14 +220,12 @@ type PutObjectOptions struct { IfMatchOptions IfNoneMatchOptions ClientRequestOptions + MetadataUnmarshaller Expect string `header:"Expect,omitempty" json:"-" url:"-"` ContentMD5 string `header:"Content-MD5,omitempty" json:"-" url:"-"` ContentType string `header:"Content-Type,omitempty" json:"-" url:"-"` ContentLanguage string `header:"Content-Language,omitempty" json:"-" url:"-"` ContentEncoding string `header:"Content-Encoding,omitempty" json:"-" url:"-"` - - // TODO: Metadata is handled explicitly during marshal. - Metadata map[string]string `header:"-" json:"-" url:"-"` } // Delete Options diff --git a/vendor/github.com/MustWin/baremetal-sdk-go/requestor.go b/vendor/github.com/MustWin/baremetal-sdk-go/requestor.go index d40392c231e..150816956b0 100644 --- a/vendor/github.com/MustWin/baremetal-sdk-go/requestor.go +++ b/vendor/github.com/MustWin/baremetal-sdk-go/requestor.go @@ -21,6 +21,7 @@ type apiRequestor struct { authInfo *authenticationInfo urlBuilder urlBuilderFn userAgent string + region string } func newCoreAPIRequestor(authInfo *authenticationInfo, nco *NewClientOptions) (r *apiRequestor) { @@ -31,6 +32,7 @@ func newCoreAPIRequestor(authInfo *authenticationInfo, nco *NewClientOptions) (r authInfo: authInfo, urlBuilder: buildCoreURL, userAgent: nco.UserAgent, + region: nco.Region, } } @@ -42,6 +44,7 @@ func newObjectStorageAPIRequestor(authInfo *authenticationInfo, nco *NewClientOp authInfo: authInfo, urlBuilder: buildObjectStorageURL, userAgent: nco.UserAgent, + region: nco.Region, } } @@ -53,6 +56,7 @@ func newDatabaseAPIRequestor(authInfo *authenticationInfo, nco *NewClientOptions authInfo: authInfo, urlBuilder: buildDatabaseURL, userAgent: nco.UserAgent, + region: nco.Region, } } @@ -64,6 +68,7 @@ func newIdentityAPIRequestor(authInfo *authenticationInfo, nco *NewClientOptions authInfo: authInfo, urlBuilder: buildIdentityURL, userAgent: nco.UserAgent, + region: nco.Region, } } @@ -75,6 +80,7 @@ func newLoadBalancerAPIRequestor(authInfo *authenticationInfo, nco *NewClientOpt authInfo: authInfo, urlBuilder: buildLoadBalancerURL, userAgent: nco.UserAgent, + region: nco.Region, } } @@ -103,7 +109,7 @@ func (api *apiRequestor) request(method string, reqOpts request) (r *response, e } var url string - if url, e = reqOpts.marshalURL(api.urlBuilder); e != nil { + if url, e = reqOpts.marshalURL(api.region, api.urlBuilder); e != nil { return } diff --git a/vendor/github.com/MustWin/baremetal-sdk-go/response.go b/vendor/github.com/MustWin/baremetal-sdk-go/response.go index a708a1a1e59..8265ca7701d 100644 --- a/vendor/github.com/MustWin/baremetal-sdk-go/response.go +++ b/vendor/github.com/MustWin/baremetal-sdk-go/response.go @@ -75,6 +75,7 @@ func (r *response) unmarshal(resource interface{}) (e error) { prefix := "opc-meta-" meta := make(map[string]string) for name, headers := range r.header { + name = strings.ToLower(name) if strings.HasPrefix(name, prefix) { for _, h := range headers { meta[strings.Replace(name, prefix, "", 1)] = h diff --git a/vendor/github.com/MustWin/baremetal-sdk-go/response_unmarshallers.go b/vendor/github.com/MustWin/baremetal-sdk-go/response_unmarshallers.go index 9c3516eeb35..ef770bb293a 100644 --- a/vendor/github.com/MustWin/baremetal-sdk-go/response_unmarshallers.go +++ b/vendor/github.com/MustWin/baremetal-sdk-go/response_unmarshallers.go @@ -82,11 +82,16 @@ func (r *LastModifiedUnmarshaller) SetLastModified(time time.Time) { } type MetadataUnmarshallable interface { + GetMetadata() map[string]string SetMetadata(map[string]string) } type MetadataUnmarshaller struct { - Metadata map[string]string + Metadata map[string]string `json:"-" url:"-" header:"-"` +} + +func (mr *MetadataUnmarshaller) GetMetadata() map[string]string { + return mr.Metadata } func (mr *MetadataUnmarshaller) SetMetadata(md map[string]string) { diff --git a/vendor/github.com/MustWin/baremetal-sdk-go/time.go b/vendor/github.com/MustWin/baremetal-sdk-go/time.go index fc59741a125..0467e1ca597 100644 --- a/vendor/github.com/MustWin/baremetal-sdk-go/time.go +++ b/vendor/github.com/MustWin/baremetal-sdk-go/time.go @@ -12,7 +12,12 @@ type Time struct { const baremetalTimeFormat = time.RFC3339 func (t *Time) UnmarshalJSON(data []byte) (e error) { - t.Time, e = time.Parse(`"`+baremetalTimeFormat+`"`, string(data)) + s := string(data) + if s == "null" { + t.Time = time.Time{} + } else { + t.Time, e = time.Parse(`"`+baremetalTimeFormat+`"`, string(data)) + } return } diff --git a/vendor/github.com/MustWin/baremetal-sdk-go/url_builder.go b/vendor/github.com/MustWin/baremetal-sdk-go/url_builder.go index a52c009ce1d..6c18b9a4d7f 100644 --- a/vendor/github.com/MustWin/baremetal-sdk-go/url_builder.go +++ b/vendor/github.com/MustWin/baremetal-sdk-go/url_builder.go @@ -8,30 +8,35 @@ import ( "strconv" ) -type urlBuilderFn func(resourceName, url.Values, ...interface{}) string +type urlBuilderFn func(string, resourceName, url.Values, ...interface{}) string -func buildCoreURL(resource resourceName, query url.Values, ids ...interface{}) string { - urlStr := fmt.Sprintf("%s/%s/%s", coreServiceAPI, coreServiceAPIVersion, resource) +func buildCoreURL(region string, resource resourceName, query url.Values, ids ...interface{}) string { + baseUrl := fmt.Sprintf(coreServiceAPI, region) + urlStr := fmt.Sprintf("%s/%s/%s", baseUrl, coreServiceAPIVersion, resource) return buildURL(urlStr, query, ids...) } -func buildIdentityURL(resource resourceName, query url.Values, ids ...interface{}) string { - urlStr := fmt.Sprintf("%s/%s/%s", identityServiceAPI, identityServiceAPIVersion, resource) +func buildIdentityURL(region string, resource resourceName, query url.Values, ids ...interface{}) string { + baseUrl := fmt.Sprintf(identityServiceAPI, region) + urlStr := fmt.Sprintf("%s/%s/%s", baseUrl, identityServiceAPIVersion, resource) return buildURL(urlStr, query, ids...) } -func buildDatabaseURL(resource resourceName, query url.Values, ids ...interface{}) string { - urlStr := fmt.Sprintf("%s/%s/%s", databaseServiceAPI, databaseServiceAPIVersion, resource) +func buildDatabaseURL(region string, resource resourceName, query url.Values, ids ...interface{}) string { + baseUrl := fmt.Sprintf(databaseServiceAPI, region) + urlStr := fmt.Sprintf("%s/%s/%s", baseUrl, databaseServiceAPIVersion, resource) return buildURL(urlStr, query, ids...) } -func buildObjectStorageURL(resource resourceName, query url.Values, ids ...interface{}) string { - urlStr := fmt.Sprintf("%s/%s", objectStorageServiceAPI, resourceNamespaces) +func buildObjectStorageURL(region string, resource resourceName, query url.Values, ids ...interface{}) string { + baseUrl := fmt.Sprintf(objectStorageServiceAPI, region) + urlStr := fmt.Sprintf("%s/%s", baseUrl, resourceNamespaces) return buildURL(urlStr, query, ids...) } -func buildLoadBalancerURL(resource resourceName, query url.Values, ids ...interface{}) string { - urlStr := fmt.Sprintf("%s/%s/%s", loadBalancerServiceAPI, loadBalancerServiceAPIVersion, resource) +func buildLoadBalancerURL(region string, resource resourceName, query url.Values, ids ...interface{}) string { + baseUrl := fmt.Sprintf(loadBalancerServiceAPI, region) + urlStr := fmt.Sprintf("%s/%s/%s", baseUrl, loadBalancerServiceAPIVersion, resource) return buildURL(urlStr, query, ids...) } diff --git a/vendor/vendor.json b/vendor/vendor.json index f64014a74aa..49b1f874f19 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -327,10 +327,10 @@ "revisionTime": "2017-02-01T00:43:30Z" }, { - "checksumSHA1": "JErNEBM+ctlSXh2weGLEX4+UIDQ=", + "checksumSHA1": "63iOaHAGKAR1w1u0XW+QjJ48NIw=", "path": "github.com/MustWin/baremetal-sdk-go", - "revision": "a9c2e1925c9df15d85eb537c037791dfe2ae266a", - "revisionTime": "2017-05-14T21:51:15Z" + "revision": "2429be22703b6f6b994ee9eaa2ef5ca27f1eaa32", + "revisionTime": "2017-05-16T00:52:04Z" }, { "checksumSHA1": "Aqy8/FoAIidY/DeQ5oTYSZ4YFVc=",