Skip to content

Commit 7e6c8c2

Browse files
committed
Replace bmcs-go-sdk with oci-go-sdk
1 parent 16da76a commit 7e6c8c2

File tree

1,032 files changed

+76263
-21026
lines changed

Some content is hidden

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

1,032 files changed

+76263
-21026
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ tf.plan
88
.DS_Store
99
.env
1010
.idea
11+
.vscode
1112
.wercker
1213
terraform-encrypted-des.sh
1314
terraform-encrypted.sh
@@ -16,4 +17,7 @@ bin/*
1617
obmc-container-clean
1718
terraform-provider-oci
1819
*.iml
20+
debug.test
21+
*.iws
22+
*.ipr
1923
docs/solutions/rhel74_image/ipxe.sh

CHANGELOG.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,30 @@ All notable changes to this project are documented in this file.
33

44
The format is based on [Keep a Changelog](http://keepachangelog.com/).
55

6+
## 2.1.0 - 2018-03-08
7+
More details for the changes introduced in 2.1.0 can be found [here](https://github.com/oracle/terraform-provider-oci/wiki/Details-for-v2.1.0-Release)
8+
9+
### Added
10+
- [Client side filtering](https://github.com/oracle/terraform-provider-oci/blob/master/docs/Filters.md) is now enabled for all data sources that return a list.
11+
- Some Core data sources now support server side filtering by `display_name` and `state`.
12+
- New optional parameters and fields have been added to existing resources and data sources to support new functionality added by the services.
13+
- Documentation files have been updated and improved. Documentation files for resources and data sources of the same entity have now been consolidated into one file.
14+
15+
### Deprecated
16+
- `limit` and `page` parameters in data sources have been deprecated. All list data sources loop through all the pages and return one aggregated list.
17+
- The `time_modified` field was deprecated from a few resources as it is no longer set by the service.
18+
19+
### Fixed
20+
- Updates to fields in `oci_objectstorage_preauthrequest` resource will force the destruction and recreation of the resource. Updates to fields in this resource had no effect earlier.
21+
- Updating some fields resulted in nothing happening. This has been fixed.
22+
- Unexpected destruction and recreation of `oci_objectstorage_object` was fixed by constraining all keys in the `metadata` map to be lower case.
23+
24+
### Notes
25+
- With this release we started using the new official [OCI Go SDK](https://github.com/oracle/oci-go-sdk). Widespread changes to the source code were needed to make this happen.
26+
- Removing optional parameters from a created resource will not result in a difference and the value for that field will remain as it was. If you want to reset the field to the default value returned by the service for that field you will have to taint the resource to destroy it and recreate it.
27+
- If upgrading the OCI provider from v1.x.x, see [this wiki](https://github.com/oracle/terraform-provider-oci/wiki/Oracle-Terraform-Provider-Name-Change) for migration steps.
28+
- See docs for this version [here](https://github.com/oracle/terraform-provider-oci/tree/v2.1.0).
29+
630
## 2.0.7 - 2018-02-08
731

832
### Added
@@ -16,7 +40,6 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/).
1640
- If upgrading from v1, see [this wiki](https://github.com/oracle/terraform-provider-oci/wiki/Oracle-Terraform-Provider-Name-Change) for migration steps.
1741
- See docs for this version [here](https://github.com/oracle/terraform-provider-oci/tree/v2.0.7).
1842

19-
2043
## 2.0.6 - 2018-01-08
2144

2245
### Added

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
GOFMT_FILES?=$$(find . -name '*.go' | grep -v vendor)
22

3-
default: build
3+
default: fmt build
44
build: ;go build -o terraform-provider-oci
55
clean: ;@rm -rf terraform-provider-oci rm -rf bin/* rm bin
66
fmt: ;goimports -w -local github.com/oracle/terraform-provider-oci $(GOFMT_FILES)
@@ -28,12 +28,12 @@ ifdef run
2828
cmd := $(cmd) -run $(run)
2929
endif
3030
ifdef debug
31-
cmd := DEBUG=true TF_LOG=DEBUG $(cmd)
31+
cmd := DEBUG=true TF_LOG=DEBUG OCI_GO_SDK_DEBUG=1 $(cmd)
3232
endif
3333
test: ;$(cmd)
3434

3535
test_print:
36-
@grep -ohi "Test.*$(test).*TestSuite" *.go
37-
@grep -oh "TestAcc.*\*testing.T" *.go | cut -d \( -f 1
36+
@grep -ohi "Test.*$(test).*TestSuite" provider/*.go
37+
@grep -oh "TestAcc.*\*testing.T" provider/*.go | cut -d \( -f 1
3838

3939
.PHONY: build clean fmt release zip test test_print

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,5 +142,3 @@ https://community.oracle.com/community/cloud_computing/bare-metal
142142

143143
[Github issues](https://github.com/oracle/terraform-provider-oci/issues)
144144

145-
## About the provider
146-
This provider was written on behalf of Oracle by [MustWin.](http://mustwin.com/)

crud/helpers.go

Lines changed: 84 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
package crud
44

55
import (
6+
"context"
67
"errors"
8+
"fmt"
79
"log"
810
"reflect"
911
"strconv"
@@ -12,7 +14,8 @@ import (
1214

1315
"github.com/hashicorp/terraform/helper/resource"
1416
"github.com/hashicorp/terraform/helper/schema"
15-
"github.com/oracle/bmcs-go-sdk"
17+
oci_common "github.com/oracle/oci-go-sdk/common"
18+
oci_load_balancer "github.com/oracle/oci-go-sdk/loadbalancer"
1619
)
1720

1821
var (
@@ -27,9 +30,12 @@ var (
2730
}
2831
)
2932

33+
const (
34+
FAILED = "FAILED"
35+
)
36+
3037
type BaseCrud struct {
31-
D *schema.ResourceData
32-
Client *baremetal.Client
38+
D *schema.ResourceData
3339
}
3440

3541
func (s *BaseCrud) VoidState() {
@@ -46,7 +52,18 @@ func (s *BaseCrud) setState(sync StatefulResource) error {
4652
// Yes, this "valid"ation is terrible
4753
if resourceReferenceValue := v.FieldByName(key); resourceReferenceValue.IsValid() {
4854
if resourceValue := resourceReferenceValue.Elem(); resourceValue.IsValid() {
49-
if stateValue := resourceValue.FieldByName("State"); stateValue.IsValid() {
55+
// In rare cases, the kind for "Res" is an interface (e.g. if the resource itself is
56+
// a polymorphic type, opposed to a field on the resource). Use Elem() to get the value
57+
// the interface contains, otherwise the ".FieldByName()" method will throw.
58+
if resourceValue.Kind() == reflect.Interface {
59+
resourceValue = resourceValue.Elem()
60+
}
61+
62+
if stateValue := resourceValue.FieldByName("LifecycleState"); stateValue.IsValid() {
63+
currentState := stateValue.String()
64+
log.Printf("[DEBUG] crud.BaseCrud.setState: state: %#v", currentState)
65+
return s.D.Set("state", currentState)
66+
} else if stateValue := resourceValue.FieldByName("State"); stateValue.IsValid() {
5067
currentState := stateValue.String()
5168
log.Printf("[DEBUG] crud.BaseCrud.setState: state: %#v", currentState)
5269
return s.D.Set("state", currentState)
@@ -82,59 +99,61 @@ func handleMissingResourceError(sync ResourceVoider, err *error) {
8299
}
83100
}
84101

85-
func LoadBalancerResourceID(res interface{}, workReq *baremetal.WorkRequest) (id *string, workReqSucceeded bool) {
102+
func LoadBalancerResourceID(res interface{}, workReq *oci_load_balancer.WorkRequest) (id *string, workReqSucceeded bool) {
86103
v := reflect.ValueOf(res).Elem()
87104
if v.IsValid() {
88105
// This is super fugly. It's this way because the LB API has no convention for ID formats.
89106

90107
// Load balancer
91-
id := v.FieldByName("ID")
92-
if id.IsValid() {
93-
s := id.String()
108+
id := v.FieldByName("Id")
109+
if id.IsValid() && !id.IsNil() {
110+
s := id.Elem().String()
94111
return &s, false
95112
}
96113
// backendset, listener
97114
name := v.FieldByName("Name")
98-
if name.IsValid() {
99-
s := name.String()
115+
if name.IsValid() && !name.IsNil() {
116+
s := name.Elem().String()
100117
return &s, false
101118
}
102119
// certificate
103120
certName := v.FieldByName("CertificateName")
104-
if certName.IsValid() {
105-
s := certName.String()
121+
if certName.IsValid() && !certName.IsNil() {
122+
s := certName.Elem().String()
106123
return &s, false
107124
}
108-
// backend
109-
ip := v.FieldByName("ip_address")
110-
port := v.FieldByName("port")
111-
if ip.IsValid() && port.IsValid() {
112-
s := ip.String() + ":" + strconv.Itoa(int(int(port.Int())))
125+
// backend TODO The following can probably be removed because the Backend object has a Name parameter)
126+
ip := v.FieldByName("IpAddress")
127+
port := v.FieldByName("Port")
128+
if ip.IsValid() && !ip.IsNil() && port.IsValid() && !port.IsNil() {
129+
s := ip.Elem().String() + ":" + strconv.Itoa(int(int(port.Elem().Int())))
113130
return &s, false
114131
}
115132
}
116133
if workReq != nil {
117-
if workReq.State == baremetal.WorkRequestSucceeded {
134+
if workReq.LifecycleState == oci_load_balancer.WorkRequestLifecycleStateSucceeded {
118135
return nil, true
119136
} else {
120-
return &workReq.ID, false
137+
return workReq.Id, false
121138
}
122139
}
123140
return nil, false
124141
}
125142

126-
func LoadBalancerResourceGet(s BaseCrud, workReq *baremetal.WorkRequest) (id string, stillWorking bool, err error) {
127-
id = s.D.Id()
143+
func LoadBalancerResourceGet(client *oci_load_balancer.LoadBalancerClient, d *schema.ResourceData, wr *oci_load_balancer.WorkRequest, retryOptions ...oci_common.RetryPolicyOption) (id string, stillWorking bool, err error) {
144+
id = d.Id()
128145
// NOTE: if the id is for a work request, refresh its state and loadBalancerID.
129146
if strings.HasPrefix(id, "ocid1.loadbalancerworkrequest.") {
130-
updatedWorkReq, err := s.Client.GetWorkRequest(id, nil)
147+
getWorkRequestRequest := oci_load_balancer.GetWorkRequestRequest{}
148+
getWorkRequestRequest.WorkRequestId = &id
149+
updatedWorkRes, err := client.GetWorkRequest(context.Background(), getWorkRequestRequest, retryOptions...)
131150
if err != nil {
132151
return "", false, err
133152
}
134-
if workReq != nil {
135-
*workReq = *updatedWorkReq
136-
s.D.Set("state", workReq.State)
137-
if workReq.State == baremetal.WorkRequestSucceeded {
153+
if wr != nil {
154+
*wr = updatedWorkRes.WorkRequest
155+
d.Set("state", wr.LifecycleState)
156+
if wr.LifecycleState == oci_load_balancer.WorkRequestLifecycleStateSucceeded {
138157
return "", false, nil
139158
}
140159
}
@@ -143,30 +162,31 @@ func LoadBalancerResourceGet(s BaseCrud, workReq *baremetal.WorkRequest) (id str
143162
return id, false, nil
144163
}
145164

146-
func LoadBalancerWaitForWorkRequest(client *baremetal.Client, d *schema.ResourceData, wr *baremetal.WorkRequest) error {
165+
func LoadBalancerWaitForWorkRequest(client *oci_load_balancer.LoadBalancerClient, d *schema.ResourceData, wr *oci_load_balancer.WorkRequest, retryOptions ...oci_common.RetryPolicyOption) error {
147166
var e error
148167
stateConf := &resource.StateChangeConf{
149168
Pending: []string{
150-
baremetal.ResourceWaitingForWorkRequest,
151-
baremetal.WorkRequestInProgress,
152-
baremetal.WorkRequestAccepted,
169+
string(oci_load_balancer.WorkRequestLifecycleStateInProgress),
170+
string(oci_load_balancer.WorkRequestLifecycleStateAccepted),
153171
},
154172
Target: []string{
155-
baremetal.ResourceSucceededWorkRequest,
156-
baremetal.WorkRequestSucceeded,
157-
baremetal.ResourceFailed,
173+
string(oci_load_balancer.WorkRequestLifecycleStateSucceeded),
174+
string(oci_load_balancer.WorkRequestLifecycleStateFailed),
158175
},
159176
Refresh: func() (interface{}, string, error) {
160-
wr, e = client.GetWorkRequest(wr.ID, nil)
161-
return wr, wr.State, e
177+
getWorkRequestRequest := oci_load_balancer.GetWorkRequestRequest{}
178+
getWorkRequestRequest.WorkRequestId = wr.Id
179+
workRequestResponse, err := client.GetWorkRequest(context.Background(), getWorkRequestRequest, retryOptions...)
180+
wr = &workRequestResponse.WorkRequest
181+
return wr, string(wr.LifecycleState), err
162182
},
163183
Timeout: d.Timeout(schema.TimeoutCreate),
164184
}
165185

166186
if _, e = stateConf.WaitForState(); e != nil {
167187
return e
168188
}
169-
if wr.State == baremetal.ResourceFailed {
189+
if wr.LifecycleState == oci_load_balancer.WorkRequestLifecycleStateFailed {
170190
return errors.New("Resource creation failed, state FAILED")
171191
}
172192
return nil
@@ -214,8 +234,7 @@ func CreateResource(d *schema.ResourceData, sync ResourceCreator) (e error) {
214234

215235
if stateful, ok := sync.(StatefullyCreatedResource); ok {
216236
e = waitForStateRefresh(stateful, d.Timeout(schema.TimeoutCreate), stateful.CreatedPending(), stateful.CreatedTarget())
217-
218-
if stateful.State() == baremetal.WorkRequestFailed {
237+
if stateful.State() == string(oci_load_balancer.WorkRequestLifecycleStateFailed) {
219238
// Remove resource from state if asynchronous work request has failed so that it is recreated on next apply
220239
// TODO: automatic retry on WorkRequestFailed
221240
sync.VoidState()
@@ -245,7 +264,7 @@ func ReadResource(sync ResourceReader) (e error) {
245264
// Remove resource from state if it has been terminated so that it is recreated on next apply
246265
if dr, ok := sync.(StatefullyDeletedResource); ok {
247266
for _, target := range dr.DeletedTarget() {
248-
if dr.State() == target && dr.State() != baremetal.ResourceSucceededWorkRequest && dr.State() != baremetal.WorkRequestSucceeded {
267+
if dr.State() == target && dr.State() != string(oci_load_balancer.WorkRequestLifecycleStateSucceeded) {
249268
dr.VoidState()
250269
return
251270
}
@@ -327,7 +346,7 @@ func waitForStateRefresh(sync StatefulResource, timeout time.Duration, pending,
327346
handleMissingResourceError(sync, &e)
328347
return
329348
}
330-
if sync.State() == baremetal.ResourceFailed || sync.State() == baremetal.WorkRequestFailed {
349+
if sync.State() == FAILED {
331350
return errors.New("Resource creation failed, state FAILED")
332351
}
333352

@@ -346,7 +365,29 @@ func EqualIgnoreCaseSuppressDiff(key string, old string, new string, d *schema.R
346365
return strings.EqualFold(old, new)
347366
}
348367

349-
func ImportDefaultResource(d *schema.ResourceData, value interface{}) ([]*schema.ResourceData, error) {
350-
err := d.Set("manage_default_resource_id", d.Id())
351-
return []*schema.ResourceData{d}, err
368+
func FieldDeprecated(deprecatedFieldName string) string {
369+
return fmt.Sprintf("The '%s' field has been deprecated. It is no longer supported.", deprecatedFieldName)
370+
}
371+
372+
func FieldDeprecatedForAnother(deprecatedFieldName string, newFieldName string) string {
373+
return fmt.Sprintf("The '%s' field has been deprecated. Please use '%s' instead.", deprecatedFieldName, newFieldName)
374+
}
375+
376+
// GenerateDataSourceID generates an ID for the data source based on the current time stamp.
377+
func GenerateDataSourceID() string {
378+
// Important, if you don't have an ID, make one up for your datasource
379+
// or things will end in tears.
380+
381+
// Consider prefixing with resource name or useful identifier beyond just a timestamp.
382+
return time.Now().UTC().String()
383+
}
384+
385+
// stringsToSet encodes an []string into a
386+
// *schema.Set in the appropriate structure for the schema
387+
func StringsToSet(ss []string) *schema.Set {
388+
st := &schema.Set{F: schema.HashString}
389+
for _, s := range ss {
390+
st.Add(s)
391+
}
392+
return st
352393
}

crud/interface.go

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

55
import (
66
"time"
7-
8-
"github.com/oracle/bmcs-go-sdk"
97
)
108

119
// Common interfaces
@@ -96,13 +94,3 @@ type StatefullyDeletedResource interface {
9694
DeletedPending() []string
9795
DeletedTarget() []string
9896
}
99-
100-
type IdentitySync struct{}
101-
102-
func (s *IdentitySync) CreatedPending() []string {
103-
return []string{baremetal.ResourceCreating}
104-
}
105-
106-
func (s *IdentitySync) CreatedTarget() []string {
107-
return []string{baremetal.ResourceCreated}
108-
}

docs/Managing Default Resources.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
## Managing Default Virtual Cloud Network Resources
22

3-
When you create an [oci_core_virtual_network](https://github.com/oracle/terraform-provider-oci/blob/master/docs/resources/core/virtual_networks.md)
3+
When you create an [oci_core_vcn](https://github.com/oracle/terraform-provider-oci/blob/master/docs/core/vcns.md)
44
resource, it will also create the following associated resources by default.
55

6-
- [oci_core_security_list](https://github.com/oracle/terraform-provider-oci/blob/master/docs/resources/core/security_list.md)
7-
- [oci_core_dhcp_options](https://github.com/oracle/terraform-provider-oci/blob/master/docs/resources/core/dhcp_option.md)
8-
- [oci_core_route_table](https://github.com/oracle/terraform-provider-oci/blob/master/docs/resources/core/route_table.md)
6+
- [oci_core_security_list](https://github.com/oracle/terraform-provider-oci/blob/master/docs/core/security_lists.md)
7+
- [oci_core_dhcp_options](https://github.com/oracle/terraform-provider-oci/blob/master/docs/core/dhcp_options.md)
8+
- [oci_core_route_table](https://github.com/oracle/terraform-provider-oci/blob/master/docs/core/route_tables.md)
99

1010
These default resources will be implicitly created even if they are not specified in the Terraform configuration.
11-
Their OCIDs are returned by the following attributes under the `oci_core_virtual_network` resource:
11+
Their OCIDs are returned by the following attributes under the `oci_core_vcn` resource:
1212

1313
- `default_security_list_id`
1414
- `default_dhcp_options_id`
@@ -32,15 +32,15 @@ Consequently, the `compartment_id` and `vcn_id` are no longer necessary for defa
3232
#### Modifying a VCN's default DHCP options
3333

3434
```
35-
resource "oci_core_virtual_network" "vcn1" {
35+
resource "oci_core_vcn" "vcn1" {
3636
cidr_block = "10.0.0.0/16"
3737
dns_label = "vcn1"
3838
compartment_id = "${var.compartment_ocid}"
3939
display_name = "vcn1"
4040
}
4141
4242
resource "oci_core_default_dhcp_options" "default-dhcp-options" {
43-
manage_default_resource_id = "${oci_core_virtual_network.vcn1.default_dhcp_options_id}"
43+
manage_default_resource_id = "${oci_core_vcn.vcn1.default_dhcp_options_id}"
4444
4545
// required
4646
options {
@@ -60,7 +60,7 @@ For more detailed examples, refer to [docs/examples/networking/vcn_default](http
6060

6161
### Limitations
6262

63-
Default resources can only be removed when the associated `oci_core_virtual_network resource` is removed. When attempting
63+
Default resources can only be removed when the associated `oci_core_vcn resource` is removed. When attempting
6464
a targeted removal of a default resource, the resource will be removed from the Terraform state file but the resource may
6565
still exist in OCI with empty settings.
6666

0 commit comments

Comments
 (0)