Skip to content

Commit db591ef

Browse files
authored
feat(bare-metal): Support for metadata service configuration (IBM-Cloud#6461)
* feat(bare-metal): Support for metadata service configuration * feat(bare-metal): Add max items in the schema for BM * feat(bare-metal): Add force new to bare metal server initialization
1 parent c0e53bc commit db591ef

17 files changed

+807
-15
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ require (
3838
github.com/IBM/secrets-manager-go-sdk/v2 v2.0.15
3939
github.com/IBM/vmware-go-sdk v0.1.5
4040
github.com/IBM/vpc-beta-go-sdk v0.8.0
41-
github.com/IBM/vpc-go-sdk v0.70.1
41+
github.com/IBM/vpc-go-sdk v0.71.1
4242
github.com/ScaleFT/sshkeys v0.0.0-20200327173127-6142f742bca5
4343
github.com/akamai/AkamaiOPEN-edgegrid-golang v1.2.2
4444
github.com/akamai/AkamaiOPEN-edgegrid-golang/v5 v5.0.0

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@ github.com/IBM/vpc-beta-go-sdk v0.8.0 h1:cEPpv4iw3Ba5W2d0AWg3TIbKeJ8y1nPuUuibR5J
171171
github.com/IBM/vpc-beta-go-sdk v0.8.0/go.mod h1:hORgIyTFRzXrZIK9IohaWmCRBBlYiDRagsufi7M6akE=
172172
github.com/IBM/vpc-go-sdk v0.70.1 h1:6NsbRkiA5gDNxe7cjNx8Pi1j9s0PlhwNQj29wsKZxAo=
173173
github.com/IBM/vpc-go-sdk v0.70.1/go.mod h1:K3vVlje72PYE3ZRt1iouE+jSIq+vCyYzT1HiFC06hUA=
174+
github.com/IBM/vpc-go-sdk v0.71.1 h1:SP5/uQs5JDb1QRvSJ1QC2BzE+BHEMq4jd2+JEcRuieE=
175+
github.com/IBM/vpc-go-sdk v0.71.1/go.mod h1:K3vVlje72PYE3ZRt1iouE+jSIq+vCyYzT1HiFC06hUA=
174176
github.com/Logicalis/asn1 v0.0.0-20190312173541-d60463189a56 h1:vuquMR410psHNax14XKNWa0Ae/kYgWJcXi0IFuX60N0=
175177
github.com/Logicalis/asn1 v0.0.0-20190312173541-d60463189a56/go.mod h1:Zb3OT4l0mf7P/GOs2w2Ilj5sdm5Whoq3pa24dAEBHFc=
176178
github.com/Masterminds/semver/v3 v3.2.1 h1:RN9w6+7QoMeJVGyfmbcgs28Br8cvmnucEXnY0rYXWg0=

ibm/service/vpc/data_source_ibm_is_bare_metal_server.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,27 @@ func DataSourceIBMIsBareMetalServer() *schema.Resource {
7676
},
7777
},
7878

79+
isBareMetalServerMetadataService: {
80+
Type: schema.TypeList,
81+
Computed: true,
82+
Description: "The metadata service configuration",
83+
Elem: &schema.Resource{
84+
Schema: map[string]*schema.Schema{
85+
isBareMetalServerMetadataServiceEnabled: {
86+
Type: schema.TypeBool,
87+
Computed: true,
88+
Description: "Indicates whether the metadata service endpoint will be available to the bare metal server",
89+
},
90+
91+
isBareMetalServerMetadataServiceProtocol: {
92+
Type: schema.TypeString,
93+
Computed: true,
94+
Description: "The communication protocol to use for the metadata service endpoint. Applies only when the metadata service is enabled.",
95+
},
96+
},
97+
},
98+
},
99+
79100
isBareMetalServerBootTarget: {
80101
Type: schema.TypeString,
81102
Computed: true,
@@ -1432,6 +1453,20 @@ func dataSourceIBMISBareMetalServerRead(context context.Context, d *schema.Resou
14321453
}
14331454
}
14341455

1456+
if bareMetalServer.MetadataService != nil {
1457+
metadataServiceList := make([]map[string]interface{}, 0)
1458+
metadataServiceMap := map[string]interface{}{}
1459+
1460+
metadataServiceMap[isBareMetalServerMetadataServiceEnabled] = *bareMetalServer.MetadataService.Enabled
1461+
if bareMetalServer.MetadataService.Protocol != nil {
1462+
metadataServiceMap[isBareMetalServerMetadataServiceProtocol] = *bareMetalServer.MetadataService.Protocol
1463+
}
1464+
metadataServiceList = append(metadataServiceList, metadataServiceMap)
1465+
if err = d.Set(isBareMetalServerMetadataService, metadataServiceList); err != nil {
1466+
return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting metadata service: %s", err), "(Data) ibm_is_bare_metal_server", "read", "set-metadata-service").GetDiag()
1467+
}
1468+
}
1469+
14351470
return nil
14361471
}
14371472

ibm/service/vpc/data_source_ibm_is_bare_metal_server_initialization.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,39 @@ func DataSourceIBMIsBareMetalServerInitialization() *schema.Resource {
5757
Description: "Passphrase for Bare Metal Server Private Key file",
5858
},
5959

60+
isBareMetalServerDefaultTrustedProfile: {
61+
Type: schema.TypeList,
62+
Computed: true,
63+
Elem: &schema.Resource{
64+
Schema: map[string]*schema.Schema{
65+
"auto_link": {
66+
Type: schema.TypeBool,
67+
Computed: true,
68+
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.",
69+
},
70+
"target": {
71+
Type: schema.TypeList,
72+
Computed: true,
73+
Description: "The default IAM trusted profile to use for this bare metal server",
74+
Elem: &schema.Resource{
75+
Schema: map[string]*schema.Schema{
76+
"id": {
77+
Type: schema.TypeString,
78+
Computed: true,
79+
Description: "The unique identifier for this trusted profile",
80+
},
81+
"crn": {
82+
Type: schema.TypeString,
83+
Computed: true,
84+
Description: "The CRN for this trusted profile",
85+
},
86+
},
87+
},
88+
},
89+
},
90+
},
91+
},
92+
6093
isBareMetalServerImage: {
6194
Type: schema.TypeString,
6295
Computed: true,
@@ -147,6 +180,23 @@ func dataSourceIBMISBareMetalServerInitializationRead(context context.Context, d
147180
}
148181
}
149182

183+
if initialization.DefaultTrustedProfile != nil {
184+
defaultTrustedProfileList := make([]map[string]interface{}, 0)
185+
defaultTrustedProfileMap := map[string]interface{}{}
186+
187+
targetMap := map[string]interface{}{}
188+
targetMap["id"] = *initialization.DefaultTrustedProfile.Target.ID
189+
targetMap["crn"] = *initialization.DefaultTrustedProfile.Target.CRN
190+
191+
defaultTrustedProfileMap["auto_link"] = *initialization.DefaultTrustedProfile.AutoLink
192+
defaultTrustedProfileMap["target"] = []map[string]interface{}{targetMap}
193+
194+
defaultTrustedProfileList = append(defaultTrustedProfileList, defaultTrustedProfileMap)
195+
if err = d.Set(isBareMetalServerDefaultTrustedProfile, defaultTrustedProfileList); err != nil {
196+
return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting default_trusted_profile: %s", err), "(Data) ibm_is_bare_metal_server_initialization", "read", "set-default_trusted_profile").GetDiag()
197+
}
198+
}
199+
150200
var keys []string
151201
keys = make([]string, 0)
152202
if initialization.Keys != nil {

ibm/service/vpc/data_source_ibm_is_bare_metal_server_initialization_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCKVmnMOlHKcZK8tpt3MP1lqOLAcqcJzhsvJcjscgVE
3232
Config: testAccCheckIBMISBareMetalServerInitializationDataSourceConfig(vpcname, subnetname, sshname, publicKey, name),
3333
Check: resource.ComposeTestCheckFunc(
3434
testAccCheckIBMISBareMetalServerExists("ibm_is_bare_metal_server.testacc_bms", server),
35-
resource.TestCheckResourceAttr(resName, "name", name),
35+
resource.TestCheckResourceAttrSet(resName, "default_trusted_profile.#"),
3636
),
3737
},
3838
},
@@ -41,7 +41,8 @@ ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCKVmnMOlHKcZK8tpt3MP1lqOLAcqcJzhsvJcjscgVE
4141

4242
func testAccCheckIBMISBareMetalServerInitializationDataSourceConfig(vpcname, subnetname, sshname, publicKey, name string) string {
4343
// status filter defaults to empty
44-
return testAccCheckIBMISBareMetalServerConfig(vpcname, subnetname, sshname, publicKey, name) +
44+
userdata1 := "a"
45+
return testAccCheckIBMISBareMetalServerInitializationConfig(vpcname, subnetname, sshname, publicKey, name, acc.IsBareMetalServerImage, userdata1, true, "https", true) +
4546
fmt.Sprintf(`
4647
data "ibm_is_bare_metal_server_initialization" "test1" {
4748
bare_metal_server = ibm_is_bare_metal_server.testacc_bms.id

ibm/service/vpc/data_source_ibm_is_bare_metal_server_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,42 @@ ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCKVmnMOlHKcZK8tpt3MP1lqOLAcqcJzhsvJcjscgVE
7878
},
7979
})
8080
}
81+
func TestAccIBMISBMSDataSource_MetadataService(t *testing.T) {
82+
resName := "data.ibm_is_bare_metal_server.test1"
83+
var server string
84+
vpcname := fmt.Sprintf("tf-vpc-%d", acctest.RandIntRange(10, 100))
85+
name := fmt.Sprintf("tf-server-%d", acctest.RandIntRange(10, 100))
86+
subnetname := fmt.Sprintf("tfip-subnet-%d", acctest.RandIntRange(10, 100))
87+
publicKey := strings.TrimSpace(`
88+
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCKVmnMOlHKcZK8tpt3MP1lqOLAcqcJzhsvJcjscgVERRN7/9484SOBJ3HSKxxNG5JN8owAjy5f9yYwcUg+JaUVuytn5Pv3aeYROHGGg+5G346xaq3DAwX6Y5ykr2fvjObgncQBnuU5KHWCECO/4h8uWuwh/kfniXPVjFToc+gnkqA+3RKpAecZhFXwfalQ9mMuYGFxn+fwn8cYEApsJbsEmb0iJwPiZ5hjFC8wREuiTlhPHDgkBLOiycd20op2nXzDbHfCHInquEe/gYxEitALONxm0swBOwJZwlTDOB7C6y2dzlrtxr1L59m7pCkWI4EtTRLvleehBoj3u7jB4usR
89+
`)
90+
sshname := fmt.Sprintf("tf-sshname-%d", acctest.RandIntRange(10, 100))
91+
92+
resource.Test(t, resource.TestCase{
93+
PreCheck: func() { acc.TestAccPreCheck(t) },
94+
Providers: acc.TestAccProviders,
95+
Steps: []resource.TestStep{
96+
{
97+
Config: testAccCheckIBMISBMSDataSourceMetadataServiceConfig(vpcname, subnetname, sshname, publicKey, name, true, "https"),
98+
Check: resource.ComposeTestCheckFunc(
99+
testAccCheckIBMISBareMetalServerExists("ibm_is_bare_metal_server.testacc_bms", server),
100+
resource.TestCheckResourceAttrSet(resName, "metadata_service.0.enabled"),
101+
resource.TestCheckResourceAttrSet(resName, "metadata_service.0.protocol"),
102+
),
103+
},
104+
},
105+
})
106+
}
107+
108+
func testAccCheckIBMISBMSDataSourceMetadataServiceConfig(vpcname, subnetname, sshname, publicKey, name string, enabled bool, protocol string) string {
109+
// status filter defaults to empty
110+
return testAccCheckIBMISBareMetalServerMetadataServiceConfig(vpcname, subnetname, sshname, publicKey, name, enabled, protocol) + fmt.Sprintf(`
111+
data "ibm_is_bare_metal_server" "test1" {
112+
depends_on = [ ibm_is_bare_metal_server.testacc_bms ]
113+
name = "%s"
114+
}`, name)
115+
}
116+
81117
func TestAccIBMISBMSDataSourceVNI_basic(t *testing.T) {
82118
var server string
83119
resName := "data.ibm_is_bare_metal_server.test1"

ibm/service/vpc/data_source_ibm_is_bare_metal_servers.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,26 @@ func DataSourceIBMIsBareMetalServers() *schema.Resource {
119119
},
120120
},
121121
},
122+
isBareMetalServerMetadataService: {
123+
Type: schema.TypeList,
124+
Computed: true,
125+
Description: "The metadata service configuration",
126+
Elem: &schema.Resource{
127+
Schema: map[string]*schema.Schema{
128+
isBareMetalServerMetadataServiceEnabled: {
129+
Type: schema.TypeBool,
130+
Computed: true,
131+
Description: "Indicates whether the metadata service endpoint will be available to the bare metal server",
132+
},
133+
134+
isBareMetalServerMetadataServiceProtocol: {
135+
Type: schema.TypeString,
136+
Computed: true,
137+
Description: "The communication protocol to use for the metadata service endpoint. Applies only when the metadata service is enabled.",
138+
},
139+
},
140+
},
141+
},
122142
isBareMetalServerBootTarget: {
123143
Type: schema.TypeString,
124144
Computed: true,
@@ -1407,6 +1427,17 @@ func dataSourceIBMISBareMetalServersRead(context context.Context, d *schema.Reso
14071427
resList = append(resList, res)
14081428
l[isReservation] = resList
14091429
}
1430+
if bms.MetadataService != nil {
1431+
metadataServiceList := make([]map[string]interface{}, 0)
1432+
metadataServiceMap := map[string]interface{}{}
1433+
1434+
metadataServiceMap[isBareMetalServerMetadataServiceEnabled] = *bms.MetadataService.Enabled
1435+
if bms.MetadataService.Protocol != nil {
1436+
metadataServiceMap[isBareMetalServerMetadataServiceProtocol] = *bms.MetadataService.Protocol
1437+
}
1438+
metadataServiceList = append(metadataServiceList, metadataServiceMap)
1439+
l[isBareMetalServerMetadataService] = metadataServiceList
1440+
}
14101441
serversInfo = append(serversInfo, l)
14111442
}
14121443
d.SetId(dataSourceIBMISBareMetalServersID(d))

ibm/service/vpc/data_source_ibm_is_bare_metal_servers_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,41 @@ ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCKVmnMOlHKcZK8tpt3MP1lqOLAcqcJzhsvJcjscgVE
7676
})
7777
}
7878

79+
func TestAccIBMISBMSsDataSource_MetadataService(t *testing.T) {
80+
resName := "data.ibm_is_bare_metal_servers.test1"
81+
var server string
82+
vpcname := fmt.Sprintf("tf-vpc-%d", acctest.RandIntRange(10, 100))
83+
name := fmt.Sprintf("tf-server-%d", acctest.RandIntRange(10, 100))
84+
subnetname := fmt.Sprintf("tfip-subnet-%d", acctest.RandIntRange(10, 100))
85+
publicKey := strings.TrimSpace(`
86+
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCKVmnMOlHKcZK8tpt3MP1lqOLAcqcJzhsvJcjscgVERRN7/9484SOBJ3HSKxxNG5JN8owAjy5f9yYwcUg+JaUVuytn5Pv3aeYROHGGg+5G346xaq3DAwX6Y5ykr2fvjObgncQBnuU5KHWCECO/4h8uWuwh/kfniXPVjFToc+gnkqA+3RKpAecZhFXwfalQ9mMuYGFxn+fwn8cYEApsJbsEmb0iJwPiZ5hjFC8wREuiTlhPHDgkBLOiycd20op2nXzDbHfCHInquEe/gYxEitALONxm0swBOwJZwlTDOB7C6y2dzlrtxr1L59m7pCkWI4EtTRLvleehBoj3u7jB4usR
87+
`)
88+
sshname := fmt.Sprintf("tf-sshname-%d", acctest.RandIntRange(10, 100))
89+
90+
resource.Test(t, resource.TestCase{
91+
PreCheck: func() { acc.TestAccPreCheck(t) },
92+
Providers: acc.TestAccProviders,
93+
Steps: []resource.TestStep{
94+
{
95+
Config: testAccCheckIBMISBMSsDataSourceMetadataServiceConfig(vpcname, subnetname, sshname, publicKey, name, true, "https"),
96+
Check: resource.ComposeTestCheckFunc(
97+
testAccCheckIBMISBareMetalServerExists("ibm_is_bare_metal_server.testacc_bms", server),
98+
resource.TestCheckResourceAttrSet(resName, "servers.0.metadata_service.0.enabled"),
99+
resource.TestCheckResourceAttrSet(resName, "servers.0.metadata_service.0.protocol"),
100+
),
101+
},
102+
},
103+
})
104+
}
105+
106+
func testAccCheckIBMISBMSsDataSourceMetadataServiceConfig(vpcname, subnetname, sshname, publicKey, name string, enabled bool, protocol string) string {
107+
// status filter defaults to empty
108+
return testAccCheckIBMISBareMetalServerMetadataServiceConfig(vpcname, subnetname, sshname, publicKey, name, enabled, protocol) + fmt.Sprintf(`
109+
data "ibm_is_bare_metal_servers" "test1" {
110+
depends_on = [ ibm_is_bare_metal_server.testacc_bms ]
111+
}`)
112+
}
113+
79114
func testAccCheckIBMISBMSsDataSourceConfig(vpcname, subnetname, sshname, publicKey, name string) string {
80115
// status filter defaults to empty
81116
return testAccCheckIBMISBareMetalServerConfig(vpcname, subnetname, sshname, publicKey, name) + fmt.Sprintf(`

0 commit comments

Comments
 (0)