Skip to content

Commit

Permalink
Fixes #3, fixes #5, fixes #6, fixes #9
Browse files Browse the repository at this point in the history
  • Loading branch information
craigcarl-oracle committed Feb 24, 2017
1 parent 874c652 commit 6fcf666
Show file tree
Hide file tree
Showing 26 changed files with 512 additions and 55 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ fmt:
gofmt -w $(GOFMT_FILES)

test:
go test -v
TF_ORACLE_ENV=test go test -v

test_acceptance:
TF_ACC=1 go test -v
Expand Down
17 changes: 4 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ Find the appropriate binary for [your platform here](https://github.com/oracle/t
Create `~/.terraformrc` that specifies the path to the `baremetal` provider.
```
providers {
baremetal = "<path_to_provider_binary>"
baremetal = "<path_to_provider_binary/terraform-provider-baremetal>"
}
```

#### Windows
Create `%APPDATA%/terraform.rc` that specifies the path to the `baremetal` provider.
```
providers {
baremetal = "<path_to_provider_binary>"
baremetal = "<path_to_provider_binary/terraform-provider-baremetal>"
}
```
### Export credentials
Expand Down Expand Up @@ -81,17 +81,8 @@ https://github.com/oracle/terraform-provider-baremetal/issues
or meet us in the OBMCS forums
https://community.oracle.com/community/cloud_computing/bare-metal

## Known bugs
### Key passphrase
The private key you use for API access must have a passphrase to work with Terraform. You can add a passphrase to your existing key with `ssh-keygen -p -f <private key>`.

If you don't want to apply a passphrase to the version of the key you don't use with Terraform you can copy the key first -
```
cp <private key> <private key>.pass
ssh-keygen -p -f <private key>.pass
```
### DB Systems timeout
DB Systems can take up to an hour to provision. Terraform times out after 5 minutes. Ensure the DB System is the last resource you provision in a configuration.
## Known serious bugs
None

#### About the provider
This provider was written on behalf of Oracle by [MustWin.](http://mustwin.com/)
4 changes: 2 additions & 2 deletions circle.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
machine:
pre:
- sudo curl -O https://storage.googleapis.com/golang/go1.6.3.linux-amd64.tar.gz
- sudo tar -xvf go1.6.3.linux-amd64.tar.gz
- sudo curl -O https://storage.googleapis.com/golang/go1.7.5.linux-amd64.tar.gz
- sudo tar -xvf go1.7.5.linux-amd64.tar.gz
- sudo rm -fr /usr/local/go
- sudo mv go /usr/local/go
environment:
Expand Down
2 changes: 1 addition & 1 deletion core/instance_datasource_crud.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (s *InstanceDatasourceCrud) SetData() {
"compartment_id": v.CompartmentID,
"display_name": v.DisplayName,
"id": v.ID,
"image": v.Image,
"image": v.ImageID,
"metadata": v.Metadata,
"region": v.Region,
"shape": v.Shape,
Expand Down
2 changes: 1 addition & 1 deletion core/instance_resource_crud.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (s *InstanceResourceCrud) SetData() {
s.D.Set("availability_domain", s.Resource.AvailabilityDomain)
s.D.Set("compartment_id", s.Resource.CompartmentID)
s.D.Set("display_name", s.Resource.DisplayName)
s.D.Set("image", s.Resource.Image)
s.D.Set("image", s.Resource.ImageID)
s.D.Set("metadata", s.Resource.Metadata)
s.D.Set("region", s.Resource.Region)
s.D.Set("shape", s.Resource.Shape)
Expand Down
9 changes: 8 additions & 1 deletion core/security_list_resource_crud.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
package core

import (
"github.com/MustWin/baremetal-sdk-go"
"time"
"fmt"

"github.com/MustWin/baremetal-sdk-go"
"github.com/MustWin/terraform-Oracle-BareMetal-Provider/crud"
)

Expand Down Expand Up @@ -33,6 +35,11 @@ func (s *SecurityListResourceCrud) DeletedTarget() []string {
return []string{baremetal.ResourceTerminated}
}

func (s *SecurityListResourceCrud) ExtraWaitPostDelete() time.Duration {
fmt.Println("=====================================")
return time.Duration(0 * time.Second)
}

func (s *SecurityListResourceCrud) State() string {
return s.Res.State
}
Expand Down
9 changes: 8 additions & 1 deletion core/subnet_resource_crud.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
package core

import (
"github.com/MustWin/baremetal-sdk-go"
"time"
"fmt"

"github.com/MustWin/baremetal-sdk-go"
"github.com/MustWin/terraform-Oracle-BareMetal-Provider/crud"
)

Expand Down Expand Up @@ -33,6 +35,11 @@ func (s *SubnetResourceCrud) DeletedTarget() []string {
return []string{baremetal.ResourceTerminated}
}

func (s *SubnetResourceCrud) ExtraWaitPostDelete() time.Duration {
fmt.Println("=====================================")
return time.Duration(10 * time.Second)
}

func (s *SubnetResourceCrud) Create() (e error) {
availabilityDomain := s.D.Get("availability_domain").(string)
cidrBlock := s.D.Get("cidr_block").(string)
Expand Down
14 changes: 7 additions & 7 deletions core_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (s *ResourceCoreInstanceTestSuite) SetupTest() {
CompartmentID: "compartment_id",
DisplayName: "display_name",
ID: "id",
Image: "imageid",
ImageID: "imageid",
Metadata: map[string]string{
"ssh_authorized_keys": "mypublickey",
},
Expand All @@ -86,7 +86,7 @@ func (s *ResourceCoreInstanceTestSuite) SetupTest() {
"LaunchInstance",
s.Res.AvailabilityDomain,
s.Res.CompartmentID,
s.Res.Image,
s.Res.ImageID,
s.Res.Shape,
"subnetid",
opts).Return(s.Res, nil)
Expand All @@ -106,7 +106,7 @@ func (s *ResourceCoreInstanceTestSuite) TestCreateResourceCoreInstance() {
resource.TestCheckResourceAttr(s.ResourceName, "compartment_id", s.Res.CompartmentID),
resource.TestCheckResourceAttr(s.ResourceName, "display_name", s.Res.DisplayName),
resource.TestCheckResourceAttr(s.ResourceName, "id", s.Res.ID),
resource.TestCheckResourceAttr(s.ResourceName, "image", s.Res.Image),
resource.TestCheckResourceAttr(s.ResourceName, "image", s.Res.ImageID),
resource.TestCheckResourceAttr(s.ResourceName, "state", s.Res.State),
resource.TestCheckResourceAttr(s.ResourceName, "time_created", s.Res.TimeCreated.String()),
),
Expand Down Expand Up @@ -139,7 +139,7 @@ func (s *ResourceCoreInstanceTestSuite) TestCreateResourceCoreInstanceWithoutDis
"LaunchInstance",
s.Res.AvailabilityDomain,
s.Res.CompartmentID,
s.Res.Image,
s.Res.ImageID,
s.Res.Shape,
"subnetid",
opts).Return(s.Res, nil)
Expand Down Expand Up @@ -180,7 +180,7 @@ func (s ResourceCoreInstanceTestSuite) TestUpdateInstanceDisplayName() {
CompartmentID: "compartment_id",
DisplayName: "new_display_name",
ID: "id",
Image: "imageid",
ImageID: "imageid",
Metadata: map[string]string{
"ssh_authorized_keys": "mypublickey",
},
Expand Down Expand Up @@ -237,7 +237,7 @@ func (s ResourceCoreInstanceTestSuite) TestUpdateAvailabilityDomainForcesNewInst
CompartmentID: "compartment_id",
DisplayName: "display_name",
ID: "new_id",
Image: "imageid",
ImageID: "imageid",
Metadata: map[string]string{
"ssh_authorized_keys": "mypublickey",
},
Expand All @@ -256,7 +256,7 @@ func (s ResourceCoreInstanceTestSuite) TestUpdateAvailabilityDomainForcesNewInst
"LaunchInstance",
res.AvailabilityDomain,
res.CompartmentID,
res.Image,
res.ImageID,
res.Shape,
"subnetid",
opts).Return(res, nil)
Expand Down
12 changes: 12 additions & 0 deletions core_security_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/hashicorp/terraform/terraform"

"github.com/stretchr/testify/suite"
"github.com/MustWin/terraform-Oracle-BareMetal-Provider/crud"
)

type ResourceCoreSecurityListTestSuite struct {
Expand All @@ -24,9 +25,14 @@ type ResourceCoreSecurityListTestSuite struct {
Config string
ResourceName string
Res *baremetal.SecurityList
DeletingRes *baremetal.SecurityList
DeletedRes *baremetal.SecurityList
}

func extraWait(ew crud.ExtraWaitPostDelete) {
return
}

func (s *ResourceCoreSecurityListTestSuite) SetupTest() {
s.Client = &mocks.BareMetalClient{}

Expand Down Expand Up @@ -98,6 +104,11 @@ func (s *ResourceCoreSecurityListTestSuite) SetupTest() {
s.Res.ETag = "etag"
s.Res.RequestID = "opcrequestid"


deletingRes := *s.Res
s.DeletingRes = &deletingRes
s.DeletingRes.State = baremetal.ResourceTerminating

deletedRes := *s.Res
s.DeletedRes = &deletedRes
s.DeletedRes.State = baremetal.ResourceTerminated
Expand Down Expand Up @@ -216,6 +227,7 @@ func (s ResourceCoreSecurityListTestSuite) TestUpdateSecurityList() {

func (s *ResourceCoreSecurityListTestSuite) TestDeleteSecurityList() {
s.Client.On("GetSecurityList", "id").Return(s.Res, nil).Times(2)
s.Client.On("GetSecurityList", "id").Return(s.DeletingRes, nil).Times(2)
s.Client.On("GetSecurityList", "id").Return(s.DeletedRes, nil)

resource.UnitTest(s.T(), resource.TestCase{
Expand Down
21 changes: 16 additions & 5 deletions crud/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ package crud

import (
"time"

"log"
"strings"

"github.com/MustWin/terraform-Oracle-BareMetal-Provider/client"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema"

// "fmt"
"fmt"
"os"
)

const FiveMinutes time.Duration = 5 * time.Minute
Expand All @@ -28,7 +27,7 @@ func (s *BaseCrud) VoidState() {

func handleMissingResourceError(sync ResourceVoider, err *error) {
if err != nil && strings.Contains((*err).Error(), "does not exist") {
fmt.Println("Object does not exist, voiding and nullifying error")
log.Println("Object does not exist, voiding and nullifying error")
sync.VoidState()
*err = nil
}
Expand Down Expand Up @@ -77,13 +76,21 @@ func DeleteResource(sync ResourceDeleter) (e error) {
return
}

ew, waitOK := sync.(ExtraWaitPostDelete)

stateful, ok := sync.(StatefullyDeletedResource)
if ok {
pending := stateful.DeletedPending()
target := stateful.DeletedTarget()
e = waitForStateRefresh(stateful, pending, target)
}

if waitOK {
if os.Getenv("TF_ORACLE_ENV") != "test" {
time.Sleep(ew.ExtraWaitPostDelete())
}
}

if e == nil {
sync.VoidState()
} else {
Expand All @@ -103,11 +110,15 @@ func stateRefreshFunc(sync StatefulResource) resource.StateRefreshFunc {
}

func waitForStateRefresh(sync StatefulResource, pending, target []string) (e error) {
timeout := FiveMinutes
if customTimeouter, ok := sync.(CustomTimeouter); ok {
timeout = customTimeouter.CustomTimeout()
}
stateConf := &resource.StateChangeConf{
Pending: pending,
Target: target,
Refresh: stateRefreshFunc(sync),
Timeout: FiveMinutes,
Timeout: timeout,
}

if _, e = stateConf.WaitForState(); e != nil {
Expand Down
13 changes: 12 additions & 1 deletion crud/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

package crud

import "github.com/MustWin/baremetal-sdk-go"
import (
"github.com/MustWin/baremetal-sdk-go"
"time"
)

// Gets the current BareMetal Resource
type ResourceFetcher interface {
Expand Down Expand Up @@ -44,6 +47,14 @@ type ResourceDeleter interface {
Delete() error
}

type CustomTimeouter interface {
CustomTimeout() time.Duration
}

type ExtraWaitPostDelete interface {
ExtraWaitPostDelete() time.Duration
}

type StatefulResource interface {
ResourceReader
State() string
Expand Down
5 changes: 5 additions & 0 deletions database/db_system_resource_crud.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/MustWin/baremetal-sdk-go"

"github.com/MustWin/terraform-Oracle-BareMetal-Provider/crud"
"time"
)

type DBSystemResourceCrud struct {
Expand Down Expand Up @@ -33,6 +34,10 @@ func (s *DBSystemResourceCrud) DeletedTarget() []string {
return []string{baremetal.ResourceTerminated}
}

func (s *DBSystemResourceCrud) CustomTimeout() time.Duration {
return 120 * time.Minute
}

func (s *DBSystemResourceCrud) State() string {
return s.Res.State
}
Expand Down
43 changes: 43 additions & 0 deletions docs/datasources/core/vnic_attachments.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# baremetal\_core\_vnic_attachments

Gets information about a specific vnic.

## Example Usage

```
data "baremetal_core_vnic_attachments" "s" {
compartment_id = "compartmentid"
availability_domain = "availabilityid"
vnic_id = "vnicid"
instance_id = "instanceid"
}
```

## Argument Reference

The following arguments are supported:

* `compartment_id` - (Required) The OCID of the compartment.
* `vnic_id` - (Optional) The OCID of the VNIC.
* `instance_id` - (Optional) The OCID of the instance.
* `availability_domain` - (Optional) The name of the Availability Domain.
* `limit` - (Optional) The maximum number of items to return in a paginated "List" call.
* `page` - (Optional) The value of the opc-next-page response header from the previous "List" call.


## Attributes Reference

The following attributes are exported:

* `vnic_attachments` - A list of vnic attachments.

## Vnic Attachment Reference
* `availability_domain` - The VNIC Attachment's Availability Domain.
* `compartment_id` - The OCID of the compartment.
* `display_name` - A user-friendly name. Does not have to be unique.
* `id` - The OCID of the VNIC Attachment.
* `instance_id` - The OCID of the instance.
* `state` - The current state of the VNIC. [ATTACHING, ATTACHED, DETACHING, DETACHED].
* `vnic_id` - The OCID of the VNIC.
* `subnet_id` - The OCID of the subnet the VNIC Attachment is in.
* `time_created` - The date and time the VNIC was created.
Loading

0 comments on commit 6fcf666

Please sign in to comment.