Skip to content

Commit c9d8d56

Browse files
authored
Merge pull request #112 from MustWin/master
Latest Updates
2 parents 790bdbd + f5a4210 commit c9d8d56

File tree

128 files changed

+2054
-7739
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

128 files changed

+2054
-7739
lines changed

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ clean:
1212
fmt:
1313
gofmt -w $(GOFMT_FILES)
1414

15-
test:
16-
TF_ORACLE_ENV=test go test -v
15+
test_acceptance_debug:
16+
TF_LOG=DEBUG DEBUG=true TF_ORACLE_ENV=test TF_ACC=1 go test -v -timeout 120m
1717

1818
test_acceptance:
19-
TF_ORACLE_ENV=test TF_ACC=1 go test -v
19+
TF_ORACLE_ENV=test TF_ACC=1 go test -v -timeout 120m
2020

21-
build: test
21+
build:
2222
go build -o terraform-provider-baremetal
2323

2424
cross: test_acceptance

client/bare_metal_client.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,11 @@ type BareMetalClient interface {
120120
ListCompartments(opts *baremetal.ListOptions) (resources *baremetal.ListCompartments, e error)
121121
ListConsoleHistories(compartmentID string, opts *baremetal.ListConsoleHistoriesOptions) (icHistories *baremetal.ListConsoleHistories, e error)
122122
ListCpes(compartmentID string, opts *baremetal.ListOptions) (cpes *baremetal.ListCpes, e error)
123-
ListDBHomes(compartmentID, dbSystemID string, limit uint64, opts *baremetal.PageListOptions) (res *baremetal.ListDBHomes, e error)
124-
ListDBNodes(compartmentID, dbSystemID string, limit uint64, opts *baremetal.PageListOptions) (resources *baremetal.ListDBNodes, e error)
125-
ListDBSystemShapes(availabilityDomain, compartmentID string, limit uint64, opts *baremetal.PageListOptions) (resources *baremetal.ListDBSystemShapes, e error)
126-
ListDBSystems(compartmentID string, limit uint64, opts *baremetal.PageListOptions) (res *baremetal.ListDBSystems, e error)
127-
ListDBVersions(compartmentID string, limit uint64, opts *baremetal.PageListOptions) (resources *baremetal.ListDBVersions, e error)
123+
ListDBHomes(compartmentID, dbSystemID string, opts *baremetal.ListOptions) (res *baremetal.ListDBHomes, e error)
124+
ListDBNodes(compartmentID, dbSystemID string, opts *baremetal.ListOptions) (resources *baremetal.ListDBNodes, e error)
125+
ListDBSystemShapes(availabilityDomain, compartmentID string, opts *baremetal.ListOptions) (resources *baremetal.ListDBSystemShapes, e error)
126+
ListDBSystems(compartmentID string, opts *baremetal.ListOptions) (res *baremetal.ListDBSystems, e error)
127+
ListDBVersions(compartmentID string, opts *baremetal.ListOptions) (resources *baremetal.ListDBVersions, e error)
128128
ListDHCPOptions(compartmentID, vcnID string, opts *baremetal.ListOptions) (res *baremetal.ListDHCPOptions, e error)
129129
ListDatabases(compartmentID, dbHomeID string, limit uint64, opts *baremetal.PageListOptions) (resources *baremetal.ListDatabases, e error)
130130
ListDrgAttachments(compartmentID string, opts *baremetal.ListDrgAttachmentsOptions) (res *baremetal.ListDrgAttachments, e error)

client/mocks/bare_metal_client.go

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package mocks
22

33
import baremetal "github.com/MustWin/baremetal-sdk-go"
4-
4+
import client "github.com/oracle/terraform-provider-baremetal/client"
55
import mock "github.com/stretchr/testify/mock"
66

77
// BareMetalClient is an autogenerated mock type for the BareMetalClient type
@@ -2215,114 +2215,114 @@ func (_m *BareMetalClient) ListCpes(compartmentID string, opts *baremetal.ListOp
22152215
return r0, r1
22162216
}
22172217

2218-
// ListDBHomes provides a mock function with given fields: compartmentID, dbSystemID, limit, opts
2219-
func (_m *BareMetalClient) ListDBHomes(compartmentID string, dbSystemID string, limit uint64, opts *baremetal.PageListOptions) (*baremetal.ListDBHomes, error) {
2220-
ret := _m.Called(compartmentID, dbSystemID, limit, opts)
2218+
// ListDBHomes provides a mock function with given fields: compartmentID, dbSystemID, opts
2219+
func (_m *BareMetalClient) ListDBHomes(compartmentID string, dbSystemID string, opts *baremetal.ListOptions) (*baremetal.ListDBHomes, error) {
2220+
ret := _m.Called(compartmentID, dbSystemID, opts)
22212221

22222222
var r0 *baremetal.ListDBHomes
2223-
if rf, ok := ret.Get(0).(func(string, string, uint64, *baremetal.PageListOptions) *baremetal.ListDBHomes); ok {
2224-
r0 = rf(compartmentID, dbSystemID, limit, opts)
2223+
if rf, ok := ret.Get(0).(func(string, string, *baremetal.ListOptions) *baremetal.ListDBHomes); ok {
2224+
r0 = rf(compartmentID, dbSystemID, opts)
22252225
} else {
22262226
if ret.Get(0) != nil {
22272227
r0 = ret.Get(0).(*baremetal.ListDBHomes)
22282228
}
22292229
}
22302230

22312231
var r1 error
2232-
if rf, ok := ret.Get(1).(func(string, string, uint64, *baremetal.PageListOptions) error); ok {
2233-
r1 = rf(compartmentID, dbSystemID, limit, opts)
2232+
if rf, ok := ret.Get(1).(func(string, string, *baremetal.ListOptions) error); ok {
2233+
r1 = rf(compartmentID, dbSystemID, opts)
22342234
} else {
22352235
r1 = ret.Error(1)
22362236
}
22372237

22382238
return r0, r1
22392239
}
22402240

2241-
// ListDBNodes provides a mock function with given fields: compartmentID, dbSystemID, limit, opts
2242-
func (_m *BareMetalClient) ListDBNodes(compartmentID string, dbSystemID string, limit uint64, opts *baremetal.PageListOptions) (*baremetal.ListDBNodes, error) {
2243-
ret := _m.Called(compartmentID, dbSystemID, limit, opts)
2241+
// ListDBNodes provides a mock function with given fields: compartmentID, dbSystemID, opts
2242+
func (_m *BareMetalClient) ListDBNodes(compartmentID string, dbSystemID string, opts *baremetal.ListOptions) (*baremetal.ListDBNodes, error) {
2243+
ret := _m.Called(compartmentID, dbSystemID, opts)
22442244

22452245
var r0 *baremetal.ListDBNodes
2246-
if rf, ok := ret.Get(0).(func(string, string, uint64, *baremetal.PageListOptions) *baremetal.ListDBNodes); ok {
2247-
r0 = rf(compartmentID, dbSystemID, limit, opts)
2246+
if rf, ok := ret.Get(0).(func(string, string, *baremetal.ListOptions) *baremetal.ListDBNodes); ok {
2247+
r0 = rf(compartmentID, dbSystemID, opts)
22482248
} else {
22492249
if ret.Get(0) != nil {
22502250
r0 = ret.Get(0).(*baremetal.ListDBNodes)
22512251
}
22522252
}
22532253

22542254
var r1 error
2255-
if rf, ok := ret.Get(1).(func(string, string, uint64, *baremetal.PageListOptions) error); ok {
2256-
r1 = rf(compartmentID, dbSystemID, limit, opts)
2255+
if rf, ok := ret.Get(1).(func(string, string, *baremetal.ListOptions) error); ok {
2256+
r1 = rf(compartmentID, dbSystemID, opts)
22572257
} else {
22582258
r1 = ret.Error(1)
22592259
}
22602260

22612261
return r0, r1
22622262
}
22632263

2264-
// ListDBSystemShapes provides a mock function with given fields: availabilityDomain, compartmentID, limit, opts
2265-
func (_m *BareMetalClient) ListDBSystemShapes(availabilityDomain string, compartmentID string, limit uint64, opts *baremetal.PageListOptions) (*baremetal.ListDBSystemShapes, error) {
2266-
ret := _m.Called(availabilityDomain, compartmentID, limit, opts)
2264+
// ListDBSystemShapes provides a mock function with given fields: availabilityDomain, compartmentID, opts
2265+
func (_m *BareMetalClient) ListDBSystemShapes(availabilityDomain string, compartmentID string, opts *baremetal.ListOptions) (*baremetal.ListDBSystemShapes, error) {
2266+
ret := _m.Called(availabilityDomain, compartmentID, opts)
22672267

22682268
var r0 *baremetal.ListDBSystemShapes
2269-
if rf, ok := ret.Get(0).(func(string, string, uint64, *baremetal.PageListOptions) *baremetal.ListDBSystemShapes); ok {
2270-
r0 = rf(availabilityDomain, compartmentID, limit, opts)
2269+
if rf, ok := ret.Get(0).(func(string, string, *baremetal.ListOptions) *baremetal.ListDBSystemShapes); ok {
2270+
r0 = rf(availabilityDomain, compartmentID, opts)
22712271
} else {
22722272
if ret.Get(0) != nil {
22732273
r0 = ret.Get(0).(*baremetal.ListDBSystemShapes)
22742274
}
22752275
}
22762276

22772277
var r1 error
2278-
if rf, ok := ret.Get(1).(func(string, string, uint64, *baremetal.PageListOptions) error); ok {
2279-
r1 = rf(availabilityDomain, compartmentID, limit, opts)
2278+
if rf, ok := ret.Get(1).(func(string, string, *baremetal.ListOptions) error); ok {
2279+
r1 = rf(availabilityDomain, compartmentID, opts)
22802280
} else {
22812281
r1 = ret.Error(1)
22822282
}
22832283

22842284
return r0, r1
22852285
}
22862286

2287-
// ListDBSystems provides a mock function with given fields: compartmentID, limit, opts
2288-
func (_m *BareMetalClient) ListDBSystems(compartmentID string, limit uint64, opts *baremetal.PageListOptions) (*baremetal.ListDBSystems, error) {
2289-
ret := _m.Called(compartmentID, limit, opts)
2287+
// ListDBSystems provides a mock function with given fields: compartmentID, opts
2288+
func (_m *BareMetalClient) ListDBSystems(compartmentID string, opts *baremetal.ListOptions) (*baremetal.ListDBSystems, error) {
2289+
ret := _m.Called(compartmentID, opts)
22902290

22912291
var r0 *baremetal.ListDBSystems
2292-
if rf, ok := ret.Get(0).(func(string, uint64, *baremetal.PageListOptions) *baremetal.ListDBSystems); ok {
2293-
r0 = rf(compartmentID, limit, opts)
2292+
if rf, ok := ret.Get(0).(func(string, *baremetal.ListOptions) *baremetal.ListDBSystems); ok {
2293+
r0 = rf(compartmentID, opts)
22942294
} else {
22952295
if ret.Get(0) != nil {
22962296
r0 = ret.Get(0).(*baremetal.ListDBSystems)
22972297
}
22982298
}
22992299

23002300
var r1 error
2301-
if rf, ok := ret.Get(1).(func(string, uint64, *baremetal.PageListOptions) error); ok {
2302-
r1 = rf(compartmentID, limit, opts)
2301+
if rf, ok := ret.Get(1).(func(string, *baremetal.ListOptions) error); ok {
2302+
r1 = rf(compartmentID, opts)
23032303
} else {
23042304
r1 = ret.Error(1)
23052305
}
23062306

23072307
return r0, r1
23082308
}
23092309

2310-
// ListDBVersions provides a mock function with given fields: compartmentID, limit, opts
2311-
func (_m *BareMetalClient) ListDBVersions(compartmentID string, limit uint64, opts *baremetal.PageListOptions) (*baremetal.ListDBVersions, error) {
2312-
ret := _m.Called(compartmentID, limit, opts)
2310+
// ListDBVersions provides a mock function with given fields: compartmentID, opts
2311+
func (_m *BareMetalClient) ListDBVersions(compartmentID string, opts *baremetal.ListOptions) (*baremetal.ListDBVersions, error) {
2312+
ret := _m.Called(compartmentID, opts)
23132313

23142314
var r0 *baremetal.ListDBVersions
2315-
if rf, ok := ret.Get(0).(func(string, uint64, *baremetal.PageListOptions) *baremetal.ListDBVersions); ok {
2316-
r0 = rf(compartmentID, limit, opts)
2315+
if rf, ok := ret.Get(0).(func(string, *baremetal.ListOptions) *baremetal.ListDBVersions); ok {
2316+
r0 = rf(compartmentID, opts)
23172317
} else {
23182318
if ret.Get(0) != nil {
23192319
r0 = ret.Get(0).(*baremetal.ListDBVersions)
23202320
}
23212321
}
23222322

23232323
var r1 error
2324-
if rf, ok := ret.Get(1).(func(string, uint64, *baremetal.PageListOptions) error); ok {
2325-
r1 = rf(compartmentID, limit, opts)
2324+
if rf, ok := ret.Get(1).(func(string, *baremetal.ListOptions) error); ok {
2325+
r1 = rf(compartmentID, opts)
23262326
} else {
23272327
r1 = ret.Error(1)
23282328
}
@@ -3658,3 +3658,5 @@ func (_m *BareMetalClient) UploadAPIKey(userID string, key string, opts *baremet
36583658

36593659
return r0, r1
36603660
}
3661+
3662+
var _ client.BareMetalClient = (*BareMetalClient)(nil)

crud/helpers.go

Lines changed: 73 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ package crud
44

55
import (
66
"log"
7-
"os"
87
"reflect"
98
"strings"
109
"time"
@@ -13,6 +12,9 @@ import (
1312
"github.com/hashicorp/terraform/helper/schema"
1413

1514
"github.com/oracle/terraform-provider-baremetal/client"
15+
"github.com/MustWin/baremetal-sdk-go"
16+
"errors"
17+
"strconv"
1618
)
1719

1820
var (
@@ -66,13 +68,73 @@ func (s *BaseCrud) State() string {
6668
}
6769

6870
func handleMissingResourceError(sync ResourceVoider, err *error) {
69-
if err != nil && strings.Contains((*err).Error(), "does not exist") {
71+
if err != nil && (
72+
strings.Contains((*err).Error(), "does not exist") ||
73+
strings.Contains((*err).Error(), " not present in ") ||
74+
strings.Contains((*err).Error(), "resource not found") ||
75+
(strings.Contains((*err).Error(), "Load balancer") && strings.Contains((*err).Error(), " has no "))) {
7076
log.Println("[DEBUG] Object does not exist, voiding resource and nullifying error")
7177
sync.VoidState()
7278
*err = nil
7379
}
7480
}
7581

82+
func LoadBalancerResourceID(res interface{}, workReq *baremetal.WorkRequest) (id *string, workReqSucceeded bool) {
83+
v := reflect.ValueOf(res).Elem()
84+
if v.IsValid() {
85+
// This is super fugly. It's this way because this API has no convention for ID formats.
86+
87+
// Load balancer
88+
id := v.FieldByName("ID")
89+
if id.IsValid() {
90+
s := id.String()
91+
return &s, false
92+
}
93+
// backendset, certificate, listener
94+
name := v.FieldByName("Name")
95+
if name.IsValid() {
96+
s := name.String()
97+
return &s, false
98+
}
99+
// backend
100+
ip := v.FieldByName("ip_address")
101+
port := v.FieldByName("port")
102+
if ip.IsValid() && port.IsValid() {
103+
s := ip.String() + ":" + strconv.Itoa(int(int(port.Int())))
104+
return &s, false
105+
}
106+
}
107+
if workReq != nil {
108+
if workReq.State == baremetal.WorkRequestSucceeded {
109+
return nil, true
110+
} else {
111+
return &workReq.ID, false
112+
}
113+
}
114+
return nil, false
115+
}
116+
117+
func LoadBalancerResourceGet(s BaseCrud, workReq *baremetal.WorkRequest) (id string, stillWorking bool, err error) {
118+
id = s.D.Id()
119+
log.Printf("================== ID in LoadbalancerResourceGet: %s\n", id)
120+
// NOTE: if the id is for a work request, refresh its state and loadBalancerID.
121+
if strings.HasPrefix(id, "ocid1.loadbalancerworkrequest.") {
122+
updatedWorkReq, err := s.Client.GetWorkRequest(id, nil)
123+
if err != nil {
124+
return "", false, err
125+
}
126+
if workReq != nil {
127+
*workReq = *updatedWorkReq
128+
s.D.Set("state", workReq.State)
129+
if workReq.State == baremetal.WorkRequestSucceeded {
130+
return "", false, nil
131+
}
132+
}
133+
return "", true, nil
134+
}
135+
return id, false, nil
136+
}
137+
76138
func CreateResource(d *schema.ResourceData, sync ResourceCreator) (e error) {
77139
if e = sync.Create(); e != nil {
78140
// Check for conflicts and retry
@@ -95,6 +157,10 @@ func CreateResource(d *schema.ResourceData, sync ResourceCreator) (e error) {
95157
d.SetId(sync.ID())
96158
sync.SetData()
97159

160+
if ew, waitOK := sync.(ExtraWaitPostCreateDelete); waitOK {
161+
time.Sleep(ew.ExtraWaitPostCreateDelete())
162+
}
163+
98164
return
99165
}
100166

@@ -133,10 +199,8 @@ func DeleteResource(d *schema.ResourceData, sync ResourceDeleter) (e error) {
133199

134200
}
135201

136-
if ew, waitOK := sync.(ExtraWaitPostDelete); waitOK {
137-
if os.Getenv("TF_ORACLE_ENV") != "test" {
138-
time.Sleep(ew.ExtraWaitPostDelete())
139-
}
202+
if ew, waitOK := sync.(ExtraWaitPostCreateDelete); waitOK {
203+
time.Sleep(ew.ExtraWaitPostCreateDelete())
140204
}
141205

142206
if e == nil {
@@ -179,6 +243,9 @@ func waitForStateRefresh(sync StatefulResource, timeout time.Duration, pending,
179243
handleMissingResourceError(sync, &e)
180244
return
181245
}
246+
if sync.State() == baremetal.ResourceFailed {
247+
return errors.New("Resource creation failed, state FAILED")
248+
}
182249

183250
return
184251
}

crud/interface.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ type ResourceDeleter interface {
6767
// of that fact. This facility allows us to add an artificial delay for
6868
// resources that need a little time to let the oracle API backend catch
6969
// up with reality.
70-
type ExtraWaitPostDelete interface {
71-
ExtraWaitPostDelete() time.Duration
70+
type ExtraWaitPostCreateDelete interface {
71+
ExtraWaitPostCreateDelete() time.Duration
7272
}
7373

7474
type StatefulResource interface {

0 commit comments

Comments
 (0)