Skip to content

Commit

Permalink
Adding diskless support to VMC provider
Browse files Browse the repository at this point in the history
- Adding diskless types support
- Adding e2e tests

Signed-off-by: Vasil Atanasov <[email protected]>
  • Loading branch information
vasilsatanasov committed Jan 19, 2024
1 parent 71e608b commit 400ef2e
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 1 deletion.
3 changes: 3 additions & 0 deletions vmc/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ const (
HostInstancetypeI3 string = "I3_METAL"
HostInstancetypeI3EN string = "I3EN_METAL"
HostInstancetypeI4I string = "I4I_METAL"
HostInstancetypeC6I string = "C6I_METAL"
HostInstancetypeM7i24xl string = "M7I_24XL_METAL"
HostInstancetypeM7i48xl string = "M7I_48XL_METAL"

// Availability Zones
SingleAvailabilityZone string = "SingleAZ"
Expand Down
2 changes: 1 addition & 1 deletion vmc/resource_vmc_sddc.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func sddcSchema() map[string]*schema.Schema {
Optional: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice(
[]string{constants.HostInstancetypeI3, constants.HostInstancetypeI3EN, constants.HostInstancetypeI4I}, false),
[]string{constants.HostInstancetypeI3, constants.HostInstancetypeI3EN, constants.HostInstancetypeI4I, constants.HostInstancetypeC6I, constants.HostInstancetypeM7i24xl, constants.HostInstancetypeM7i48xl}, false),
},
"edrs_policy_type": {
Type: schema.TypeString,
Expand Down
99 changes: 99 additions & 0 deletions vmc/resource_vmc_sddc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/vmware/terraform-provider-vmc/vmc/connector"
"github.com/vmware/terraform-provider-vmc/vmc/constants"
"os"
"strings"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
Expand Down Expand Up @@ -90,6 +91,54 @@ func TestAccResourceVmcSddcRequiredFieldsOnlyZerocloud(t *testing.T) {
})
}

func TestAccResourceVmcSddcC6iMetal(t *testing.T) {
var sddcResource model.Sddc
sddcName := "terraform_sddc_c6i_test_" + acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum)
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheckZerocloud(t) },
Providers: testAccProviders,
CheckDestroy: testCheckVmcSddcDestroy,
Steps: []resource.TestStep{
{
Config: testAccVmcSddcConfigDiskless(sddcName, constants.HostInstancetypeC6I),
Check: resource.ComposeTestCheckFunc(
testCheckVmcSddcExists("vmc_sddc.sddc_c6i", &sddcResource),
testCheckSddcAttributes(&sddcResource),
resource.TestCheckResourceAttr("vmc_sddc.sddc_c6i", "sddc_state", "READY"),
resource.TestCheckResourceAttrSet("vmc_sddc.sddc_c6i", "vc_url"),
resource.TestCheckResourceAttrSet("vmc_sddc.sddc_c6i", "cloud_username"),
resource.TestCheckResourceAttrSet("vmc_sddc.sddc_c6i", "cloud_password"),
resource.TestCheckResourceAttrSet("vmc_sddc.sddc_c6i", "nsxt_reverse_proxy_url"),
),
},
},
})
}

func TestAccResourceVmcSddcM7i24xlMetal(t *testing.T) {
var sddcResource model.Sddc
sddcName := "terraform_sddc_m7i_24_xl_test_" + acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum)
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheckZerocloud(t) },
Providers: testAccProviders,
CheckDestroy: testCheckVmcSddcDestroy,
Steps: []resource.TestStep{
{
Config: testAccVmcSddcConfigDiskless(sddcName, constants.HostInstancetypeM7i24xl),
Check: resource.ComposeTestCheckFunc(
testCheckVmcSddcExists("vmc_sddc.sddc_c6i", &sddcResource),
testCheckSddcAttributes(&sddcResource),
resource.TestCheckResourceAttr("vmc_sddc.sddc_sddc_m7i_24xl", "sddc_state", "READY"),
resource.TestCheckResourceAttrSet("vmc_sddc.sddc_sddc_m7i_24xl", "vc_url"),
resource.TestCheckResourceAttrSet("vmc_sddc.sddc_sddc_m7i_24xl", "cloud_username"),
resource.TestCheckResourceAttrSet("vmc_sddc.sddc_sddc_m7i_24xl", "cloud_password"),
resource.TestCheckResourceAttrSet("vmc_sddc.sddc_sddc_m7i_24xl", "nsxt_reverse_proxy_url"),
),
},
},
})
}

func testCheckVmcSddcExists(name string, sddcResource *model.Sddc) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[name]
Expand Down Expand Up @@ -238,6 +287,56 @@ resource "vmc_sddc" "sddc_zerocloud" {
sddcName,
)
}
func testAccVmcSddcConfigDiskless(sddcName string, hostInstanceType string) string {

sddcResourceName := "sddc_" + strings.Replace(strings.ToLower(hostInstanceType), "_metal", "", 1)
return fmt.Sprintf(`
data "vmc_connected_accounts" "my_accounts" {
account_number = %q
}
data "vmc_customer_subnets" "my_subnets" {
connected_account_id = data.vmc_connected_accounts.my_accounts.id
region = "US_WEST_2"
}
resource "vmc_sddc" %q {
sddc_name = %q
vpc_cidr = "10.40.0.0/16"
num_host = 3
provider_type = "ZEROCLOUD"
host_instance_type = %q
region = "US_WEST_2"
vxlan_subnet = "192.168.1.0/24"
delay_account_link = false
skip_creating_vxlan = false
sso_domain = "vmc.local"
deployment_type = "SingleAZ"
account_link_sddc_config {
customer_subnet_ids = [data.vmc_customer_subnets.my_subnets.ids[0]]
connected_account_id = data.vmc_connected_accounts.my_accounts.id
}
timeouts {
create = "300m"
update = "300m"
delete = "180m"
}
microsoft_licensing_config {
mssql_licensing = "ENABLED"
windows_licensing = "DISABLED"
}
}
`,
os.Getenv(constants.AwsAccountNumber),
sddcResourceName,
sddcName,
hostInstanceType,
)
}

func testAccVmcSddcConfigRequiredFieldsZerocloud(sddcName string) string {
return fmt.Sprintf(`
Expand Down
6 changes: 6 additions & 0 deletions vmc/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ func toHostInstanceType(userPassedHostInstanceType string) (string, error) {
return model.SddcConfig_HOST_INSTANCE_TYPE_I3EN_METAL, nil
case constants.HostInstancetypeI4I:
return model.SddcConfig_HOST_INSTANCE_TYPE_I4I_METAL, nil
case constants.HostInstancetypeC6I:
return "c6i.metal", nil
case constants.HostInstancetypeM7i24xl:
return "m7i.metal-24xl", nil
case constants.HostInstancetypeM7i48xl:
return "m7i.metal-48xl", nil
default:
return "", fmt.Errorf("unknown host instance type: %s", userPassedHostInstanceType)
}
Expand Down

0 comments on commit 400ef2e

Please sign in to comment.