Skip to content

Commit 8315fe5

Browse files
committed
feat(bare-metal): Add CRN for BM resource creation and updation
1 parent 68d51e4 commit 8315fe5

File tree

4 files changed

+47
-29
lines changed

4 files changed

+47
-29
lines changed

ibm/service/vpc/resource_ibm_is_bare_metal_server.go

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,26 +1117,23 @@ func ResourceIBMIsBareMetalServer() *schema.Resource {
11171117
"auto_link": {
11181118
Type: schema.TypeBool,
11191119
Optional: true,
1120-
Computed: true,
11211120
Description: "If set to true, the system will create a link to the specified target trusted profile during server creation. Regardless of whether a link is created by the system or manually using the IAM Identity service, it will be automatically deleted when the server is deleted.",
11221121
},
11231122
"target": {
11241123
Type: schema.TypeList,
11251124
Optional: true,
1126-
Computed: true,
11271125
Description: "The default IAM trusted profile to use for this bare metal server",
11281126
Elem: &schema.Resource{
11291127
Schema: map[string]*schema.Schema{
11301128
"id": {
1131-
Type: schema.TypeString,
1132-
Optional: true,
1133-
Computed: true,
1134-
Description: "The unique identifier for this trusted profile",
1129+
Type: schema.TypeString,
1130+
Optional: true,
1131+
Description: "The unique identifier for this trusted profile",
11351132
},
11361133
"crn": {
1137-
Type: schema.TypeString,
1138-
Computed: true,
1139-
Description: "The CRN for this trusted profile",
1134+
Type: schema.TypeString,
1135+
Optional: true,
1136+
Description: "The CRN for this trusted profile",
11401137
},
11411138
},
11421139
},
@@ -1510,17 +1507,23 @@ func resourceIBMISBareMetalServerCreate(context context.Context, d *schema.Resou
15101507
defaultTrustedProfilePrototype.AutoLink = &autolink
15111508
}
15121509
}
1510+
15131511
if targetIntf, ok := defaultTrustedProfileMap["target"]; ok {
1514-
targetMap := targetIntf.([]interface{})[0].(map[string]interface{})
1515-
var id *string
1516-
if idIntf, ok := targetMap["id"]; ok {
1517-
if idStr, ok := idIntf.(string); ok && idStr != "" {
1518-
id = &idStr
1519-
}
1520-
}
1521-
if id != nil {
1522-
defaultTrustedProfilePrototype.Target = &vpcv1.TrustedProfileIdentity{
1523-
ID: id,
1512+
if targetList, ok := targetIntf.([]interface{}); ok && len(targetList) > 0 {
1513+
if targetMap, ok := targetList[0].(map[string]interface{}); ok {
1514+
var id, crn *string
1515+
if crnStr, ok := targetMap["crn"].(string); ok && crnStr != "" {
1516+
crn = &crnStr
1517+
} else if idStr, ok := targetMap["id"].(string); ok && idStr != "" {
1518+
id = &idStr
1519+
}
1520+
1521+
if crn != nil || id != nil {
1522+
defaultTrustedProfilePrototype.Target = &vpcv1.TrustedProfileIdentity{
1523+
CRN: crn,
1524+
ID: id,
1525+
}
1526+
}
15241527
}
15251528
}
15261529
}
@@ -2754,6 +2757,13 @@ func bareMetalServerUpdate(context context.Context, d *schema.ResourceData, meta
27542757
ID: &newTargetID,
27552758
}
27562759
}
2760+
2761+
if d.HasChange("default_trusted_profile.0.target.0.crn") {
2762+
newTargetCRN := d.Get("default_trusted_profile.0.target.0.crn").(string)
2763+
defaultTrustedProfile.Target = &vpcv1.TrustedProfileIdentity{
2764+
CRN: &newTargetCRN,
2765+
}
2766+
}
27572767

27582768
if defaultTrustedProfile.AutoLink != nil || defaultTrustedProfile.Target != nil {
27592769
initializationPatch.DefaultTrustedProfile = defaultTrustedProfile

ibm/service/vpc/resource_ibm_is_bare_metal_server_initialization.go

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ func ResourceIBMIsBareMetalServerInitialization() *schema.Resource {
6464
},
6565
"crn": {
6666
Type: schema.TypeString,
67+
Optional: true,
6768
Computed: true,
6869
Description: "The CRN for this trusted profile",
6970
},
@@ -156,16 +157,21 @@ func resourceIBMISBareMetalServerInitializationCreate(context context.Context, d
156157
}
157158

158159
if targetIntf, ok := defaultTrustedProfileMap["target"]; ok {
159-
targetMap := targetIntf.([]interface{})[0].(map[string]interface{})
160-
var id *string
161-
if idIntf, ok := targetMap["id"]; ok {
162-
if idStr, ok := idIntf.(string); ok && idStr != "" {
163-
id = &idStr
164-
}
165-
}
166-
if id != nil {
167-
defaultTrustedProfilePrototype.Target = &vpcv1.TrustedProfileIdentity{
168-
ID: id,
160+
if targetList, ok := targetIntf.([]interface{}); ok && len(targetList) > 0 {
161+
if targetMap, ok := targetList[0].(map[string]interface{}); ok {
162+
var id, crn *string
163+
if crnStr, ok := targetMap["crn"].(string); ok && crnStr != "" {
164+
crn = &crnStr
165+
} else if idStr, ok := targetMap["id"].(string); ok && idStr != "" {
166+
id = &idStr
167+
}
168+
169+
if crn != nil || id != nil {
170+
defaultTrustedProfilePrototype.Target = &vpcv1.TrustedProfileIdentity{
171+
CRN: crn,
172+
ID: id,
173+
}
174+
}
169175
}
170176
}
171177
}

website/docs/r/is_bare_metal_server.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ Review the argument references that you can specify for your resource.
240240
- `target` - (List) The default IAM trusted profile to use for this bare metal server.
241241
Nested scheme for `target`:
242242
- `id` - (String) The unique identifier for this trusted profile
243+
- `crn`- (String) The CRN for this trusted profile
243244
- `delete_type` - (Optional, String) Type of deletion on destroy. **soft** signals running operating system to quiesce and shutdown cleanly, **hard** immediately stop the server. By default its `hard`.
244245
- `enable_secure_boot` - (Optional, Boolean) Indicates whether secure boot is enabled. If enabled, the image must support secure boot or the server will fail to boot. Updating `enable_secure_boot` requires the server to be stopped and then it would be started.
245246
- `health_reasons` - (List) The reasons for the current health_state (if any).

website/docs/r/is_bare_metal_server_initialization.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ Review the argument references that you can specify for your resource.
6262
- `target` - (List) The default IAM trusted profile to use for this bare metal server.
6363
Nested scheme for `target`:
6464
- `id` - (String) The unique identifier for this trusted profile
65+
- `crn`- (String) The CRN for this trusted profile
6566
- `image` - (Required, String) Image id to use to reinitialize the bare metal server.
6667
- `keys` - (Required, Array) Keys ids to use to reinitialize the bare metal server.
6768
- `user_data` - (Optional, String) User data to transfer to the server bare metal server. If unspecified, no user data will be made available. (For reload/reinitialize provide the same user data as at the time of provisioning)

0 commit comments

Comments
 (0)