Skip to content

Commit 86679ef

Browse files
authored
Merge pull request #4 from MustWin/iscsi-vol-attach
baremetal_core_volume_attachment: add chap_secret, chap_username, ipv4, iqn, port
2 parents 061515d + 51e6071 commit 86679ef

File tree

5 files changed

+73
-22
lines changed

5 files changed

+73
-22
lines changed

core/volume_attachment_resource.go

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
package core
44

55
import (
6+
"github.com/hashicorp/terraform/helper/schema"
7+
"github.com/hashicorp/terraform/helper/validation"
8+
69
"github.com/oracle/terraform-provider-baremetal/client"
710
"github.com/oracle/terraform-provider-baremetal/crud"
8-
"github.com/hashicorp/terraform/helper/schema"
911
)
1012

1113
func VolumeAttachmentResource() *schema.Resource {
@@ -14,33 +16,42 @@ func VolumeAttachmentResource() *schema.Resource {
1416
Read: readVolumeAttachment,
1517
Delete: deleteVolumeAttachment,
1618
Schema: map[string]*schema.Schema{
19+
//// Required ////
1720
"attachment_type": {
21+
Type: schema.TypeString,
22+
Required: true,
23+
ForceNew: true,
24+
ValidateFunc: validation.StringInSlice([]string{"iscsi"}, false),
25+
},
26+
"compartment_id": {
1827
Type: schema.TypeString,
1928
Required: true,
2029
ForceNew: true,
2130
},
22-
"availability_domain": {
31+
"instance_id": {
2332
Type: schema.TypeString,
24-
Computed: true,
33+
Required: true,
34+
ForceNew: true,
2535
},
26-
"compartment_id": {
36+
"volume_id": {
2737
Type: schema.TypeString,
2838
Required: true,
2939
ForceNew: true,
3040
},
31-
"display_name": {
41+
//// Computed ////
42+
"id": {
3243
Type: schema.TypeString,
3344
Computed: true,
3445
},
35-
"id": {
46+
"availability_domain": {
3647
Type: schema.TypeString,
3748
Computed: true,
3849
},
39-
"instance_id": {
50+
"display_name": {
4051
Type: schema.TypeString,
41-
Required: true,
42-
ForceNew: true,
52+
Computed: true,
4353
},
54+
// aka lifecycleState
4455
"state": {
4556
Type: schema.TypeString,
4657
Computed: true,
@@ -49,10 +60,27 @@ func VolumeAttachmentResource() *schema.Resource {
4960
Type: schema.TypeString,
5061
Computed: true,
5162
},
52-
"volume_id": {
63+
// The following are only computed if type == "iscsi"
64+
"chap_secret": {
5365
Type: schema.TypeString,
54-
Required: true,
55-
ForceNew: true,
66+
Computed: true,
67+
},
68+
"chap_username": {
69+
Type: schema.TypeString,
70+
Computed: true,
71+
},
72+
"ipv4": {
73+
Type: schema.TypeString,
74+
Computed: true,
75+
},
76+
"iqn": {
77+
// iSCSI Qualified Name per RFC 3720
78+
Type: schema.TypeString,
79+
Computed: true,
80+
},
81+
"port": {
82+
Type: schema.TypeInt,
83+
Computed: true,
5684
},
5785
},
5886
}

core/volume_attachment_resource_crud.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ func (s *VolumeAttachmentResourceCrud) SetData() {
6161
s.D.Set("state", s.Res.State)
6262
s.D.Set("time_created", s.Res.TimeCreated.String())
6363
s.D.Set("volume_id", s.Res.VolumeID)
64+
s.D.Set("chap_secret", s.Res.CHAPSecret)
65+
s.D.Set("chap_username", s.Res.CHAPUsername)
66+
s.D.Set("ipv4", s.Res.IPv4)
67+
s.D.Set("iqn", s.Res.IQN)
68+
s.D.Set("port", s.Res.Port)
6469
}
6570

6671
func (s *VolumeAttachmentResourceCrud) Delete() (e error) {

core_volume_attachment_test.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
package main
44

55
import (
6+
"strconv"
67
"testing"
78
"time"
89

910
"github.com/MustWin/baremetal-sdk-go"
10-
"github.com/oracle/terraform-provider-baremetal/client/mocks"
1111
"github.com/hashicorp/terraform/helper/resource"
1212
"github.com/hashicorp/terraform/helper/schema"
1313
"github.com/hashicorp/terraform/terraform"
14+
"github.com/oracle/terraform-provider-baremetal/client/mocks"
1415

1516
"github.com/stretchr/testify/suite"
1617
)
@@ -44,7 +45,7 @@ func (s *ResourceCoreVolumeAttachmentTestSuite) SetupTest() {
4445

4546
s.Config = `
4647
resource "baremetal_core_volume_attachment" "t" {
47-
attachment_type = "attachment_type"
48+
attachment_type = "iscsi"
4849
compartment_id = "compartment_id"
4950
instance_id = "instance_id"
5051
volume_id = "volume_id"
@@ -54,7 +55,7 @@ func (s *ResourceCoreVolumeAttachmentTestSuite) SetupTest() {
5455

5556
s.ResourceName = "baremetal_core_volume_attachment.t"
5657
s.Res = &baremetal.VolumeAttachment{
57-
AttachmentType: "attachment_type",
58+
AttachmentType: "iscsi",
5859
AvailabilityDomain: "availability_domain",
5960
CompartmentID: "compartment_id",
6061
DisplayName: "display_name",
@@ -63,12 +64,17 @@ func (s *ResourceCoreVolumeAttachmentTestSuite) SetupTest() {
6364
State: baremetal.ResourceAttached,
6465
TimeCreated: s.TimeCreated,
6566
VolumeID: "volume_id",
67+
CHAPSecret: "chap_secret",
68+
CHAPUsername: "chap_username",
69+
IPv4: "ipv4",
70+
IQN: "iqn",
71+
Port: 12345,
6672
}
6773
s.Res.ETag = "etag"
6874
s.Res.RequestID = "opcrequestid"
6975

7076
s.DetachedRes = &baremetal.VolumeAttachment{
71-
AttachmentType: "attachment_type",
77+
AttachmentType: "iscsi",
7278
AvailabilityDomain: "availability_domain",
7379
CompartmentID: "compartment_id",
7480
DisplayName: "display_name",
@@ -83,7 +89,7 @@ func (s *ResourceCoreVolumeAttachmentTestSuite) SetupTest() {
8389

8490
s.Client.On(
8591
"AttachVolume",
86-
"attachment_type",
92+
"iscsi",
8793
"instance_id",
8894
"volume_id",
8995
(*baremetal.CreateOptions)(nil)).Return(s.Res, nil)
@@ -109,6 +115,11 @@ func (s *ResourceCoreVolumeAttachmentTestSuite) TestCreateResourceCoreVolumeAtta
109115
resource.TestCheckResourceAttr(s.ResourceName, "state", s.Res.State),
110116
resource.TestCheckResourceAttr(s.ResourceName, "time_created", s.Res.TimeCreated.String()),
111117
resource.TestCheckResourceAttr(s.ResourceName, "volume_id", s.Res.VolumeID),
118+
resource.TestCheckResourceAttr(s.ResourceName, "chap_secret", s.Res.CHAPSecret),
119+
resource.TestCheckResourceAttr(s.ResourceName, "chap_username", s.Res.CHAPUsername),
120+
resource.TestCheckResourceAttr(s.ResourceName, "ipv4", s.Res.IPv4),
121+
resource.TestCheckResourceAttr(s.ResourceName, "iqn", s.Res.IQN),
122+
resource.TestCheckResourceAttr(s.ResourceName, "port", strconv.Itoa(s.Res.Port)),
112123
),
113124
},
114125
},

vendor/github.com/MustWin/baremetal-sdk-go/core_volume_attachment.go

Lines changed: 9 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/vendor.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -315,10 +315,10 @@
315315
"revisionTime": "2017-02-01T00:43:30Z"
316316
},
317317
{
318-
"checksumSHA1": "Z5k3FbEQycqfu0Y/WtuV1zE/yqE=",
318+
"checksumSHA1": "OTS+U4v/fjA7wtYQVG3pn2FZDE8=",
319319
"path": "github.com/MustWin/baremetal-sdk-go",
320-
"revision": "496d0fe63ba8342535e639d9116e8dc243780b1e",
321-
"revisionTime": "2017-03-20T18:17:09Z"
320+
"revision": "8aafd2e65eb09843e9bd2233f4619069d2a8d630",
321+
"revisionTime": "2017-03-16T21:54:35Z"
322322
},
323323
{
324324
"checksumSHA1": "Aqy8/FoAIidY/DeQ5oTYSZ4YFVc=",

0 commit comments

Comments
 (0)