From ea31e824c0adbaadf5084c4a31c098990ac232e6 Mon Sep 17 00:00:00 2001 From: Sergei Martynov Date: Wed, 3 Apr 2024 13:47:05 +0200 Subject: [PATCH 1/2] auth first implementation --- .../data_source_rancher2_cloud_credential.go | 5 +- .../resource_rancher2_cloud_credential.go | 2 + ...resource_rancher2_cloud_credential_test.go | 87 +++++++ rancher2/schema_cloud_credential.go | 30 ++- rancher2/schema_cloud_credential_otc.go | 56 +++++ rancher2/schema_node_template_otc.go | 223 ++++++++++++++++++ rancher2/structure_cloud_credential.go | 14 ++ rancher2/structure_cloud_credential_otc.go | 70 ++++++ 8 files changed, 477 insertions(+), 10 deletions(-) create mode 100644 rancher2/schema_cloud_credential_otc.go create mode 100644 rancher2/schema_node_template_otc.go create mode 100644 rancher2/structure_cloud_credential_otc.go diff --git a/rancher2/data_source_rancher2_cloud_credential.go b/rancher2/data_source_rancher2_cloud_credential.go index 3bc3bae9..3bdc5903 100644 --- a/rancher2/data_source_rancher2_cloud_credential.go +++ b/rancher2/data_source_rancher2_cloud_credential.go @@ -53,7 +53,10 @@ func dataSourceRancher2CloudCredentialRead(d *schema.ResourceData, meta interfac credential := credentials.Data[0] d.SetId(credential.ID) - d.Set("name", credential.Name) + err = d.Set("name", credential.Name) + if err != nil { + return err + } err = d.Set("annotations", toMapInterface(credential.Annotations)) if err != nil { return err diff --git a/rancher2/resource_rancher2_cloud_credential.go b/rancher2/resource_rancher2_cloud_credential.go index cce9ea28..076b23d0 100644 --- a/rancher2/resource_rancher2_cloud_credential.go +++ b/rancher2/resource_rancher2_cloud_credential.go @@ -136,6 +136,8 @@ func resourceRancher2CloudCredentialUpdate(d *schema.ResourceData, meta interfac update["s3credentialConfig"] = expandCloudCredentialS3(d.Get("s3_credential_config").([]interface{})) case vmwarevsphereConfigDriver: update["vmwarevspherecredentialConfig"] = expandCloudCredentialVsphere(d.Get("vsphere_credential_config").([]interface{})) + case openTelekomCloudConfigDriver: + update["opentelekomcloudcredentialConfig"] = expandCloudCredentialOpenTelekomCloud(d.Get("open_telekom_cloud_credential_config").([]interface{})) default: return fmt.Errorf("[ERROR] updating cloud credential: Unsupported driver \"%s\"", driver) } diff --git a/rancher2/resource_rancher2_cloud_credential_test.go b/rancher2/resource_rancher2_cloud_credential_test.go index b11574ef..5e95dbf4 100644 --- a/rancher2/resource_rancher2_cloud_credential_test.go +++ b/rancher2/resource_rancher2_cloud_credential_test.go @@ -176,6 +176,28 @@ resource "` + testAccRancher2CloudCredentialType + `" "foo-vsphere" { username = "user" vcenter = "vcenter2" } +} + ` + testAccRancher2CloudCredentialConfigOpenTelekomCloud = ` +resource "` + testAccRancher2CloudCredentialType + `" "foo-otc" { + name = "foo-vsphere" + description= "Terraform cloudCredential acceptance test" + vsphere_credential_config { + password = "XXXXXXXXXXXXXXXXXXXX" + username = "user" + vcenter = "vcenter" + } +} +` + testAccRancher2CloudCredentialUpdateConfigOpenTelekomCloud = ` +resource "` + testAccRancher2CloudCredentialType + `" "foo-otc" { + name = "foo-vsphere" + description= "Terraform cloudCredential acceptance test - updated" + vsphere_credential_config { + password = "YYYYYYYYYYYYYYYYYYYY" + username = "user" + vcenter = "vcenter2" + } } ` ) @@ -685,6 +707,71 @@ func TestAccRancher2CloudCredential_disappears_Vsphere(t *testing.T) { }) } +func TestAccRancher2CloudCredential_basic_OTC(t *testing.T) { + var cloudCredential *CloudCredential + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckRancher2CloudCredentialDestroy, + Steps: []resource.TestStep{ + { + Config: testAccRancher2CloudCredentialConfigOpenTelekomCloud, + Check: resource.ComposeTestCheckFunc( + testAccCheckRancher2CloudCredentialExists(testAccRancher2CloudCredentialType+".foo-otc", cloudCredential), + resource.TestCheckResourceAttr(testAccRancher2CloudCredentialType+".foo-otc", "name", "foo-otc"), + resource.TestCheckResourceAttr(testAccRancher2CloudCredentialType+".foo-otc", "description", "Terraform cloudCredential acceptance test"), + resource.TestCheckResourceAttr(testAccRancher2CloudCredentialType+".foo-otc", "driver", openTelekomCloudConfigDriver), + resource.TestCheckResourceAttr(testAccRancher2CloudCredentialType+".foo-otc", "open_telekom_cloud_credential_config.0.password", "XXXXXXXXXXXXXXXXXXXX"), + resource.TestCheckResourceAttr(testAccRancher2CloudCredentialType+".foo-otc", "open_telekom_cloud_credential_config.0.vcenter", "vcenter"), + ), + }, + { + Config: testAccRancher2CloudCredentialUpdateConfigOpenTelekomCloud, + Check: resource.ComposeTestCheckFunc( + testAccCheckRancher2CloudCredentialExists(testAccRancher2CloudCredentialType+".foo-otc", cloudCredential), + resource.TestCheckResourceAttr(testAccRancher2CloudCredentialType+".foo-otc", "name", "foo-otc"), + resource.TestCheckResourceAttr(testAccRancher2CloudCredentialType+".foo-otc", "description", "Terraform cloudCredential acceptance test - updated"), + resource.TestCheckResourceAttr(testAccRancher2CloudCredentialType+".foo-otc", "driver", openTelekomCloudConfigDriver), + resource.TestCheckResourceAttr(testAccRancher2CloudCredentialType+".foo-otc", "open_telekom_cloud_credential_config.0.password", "YYYYYYYYYYYYYYYYYYYY"), + resource.TestCheckResourceAttr(testAccRancher2CloudCredentialType+".foo-otc", "open_telekom_cloud_credential_config.0.vcenter", "vcenter2"), + ), + }, + { + Config: testAccRancher2CloudCredentialConfigOpenTelekomCloud, + Check: resource.ComposeTestCheckFunc( + testAccCheckRancher2CloudCredentialExists(testAccRancher2CloudCredentialType+".foo-otc", cloudCredential), + resource.TestCheckResourceAttr(testAccRancher2CloudCredentialType+".foo-otc", "name", "foo-otc"), + resource.TestCheckResourceAttr(testAccRancher2CloudCredentialType+".foo-otc", "description", "Terraform cloudCredential acceptance test"), + resource.TestCheckResourceAttr(testAccRancher2CloudCredentialType+".foo-otc", "driver", openTelekomCloudConfigDriver), + resource.TestCheckResourceAttr(testAccRancher2CloudCredentialType+".foo-otc", "open_telekom_cloud_credential_config.0.password", "XXXXXXXXXXXXXXXXXXXX"), + resource.TestCheckResourceAttr(testAccRancher2CloudCredentialType+".foo-otc", "open_telekom_cloud_credential_config.0.vcenter", "vcenter"), + ), + }, + }, + }) +} + +func TestAccRancher2CloudCredential_disappears_OTC(t *testing.T) { + var cloudCredential *CloudCredential + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckRancher2CloudCredentialDestroy, + Steps: []resource.TestStep{ + { + Config: testAccRancher2CloudCredentialConfigOpenTelekomCloud, + Check: resource.ComposeTestCheckFunc( + testAccCheckRancher2CloudCredentialExists(testAccRancher2CloudCredentialType+".foo-otc", cloudCredential), + testAccRancher2CloudCredentialDisappears(cloudCredential), + ), + ExpectNonEmptyPlan: true, + }, + }, + }) +} + func testAccRancher2CloudCredentialDisappears(cloudCredential *CloudCredential) resource.TestCheckFunc { return func(s *terraform.State) error { for _, rs := range s.RootModule().Resources { diff --git a/rancher2/schema_cloud_credential.go b/rancher2/schema_cloud_credential.go index 12818c8e..01d0e117 100644 --- a/rancher2/schema_cloud_credential.go +++ b/rancher2/schema_cloud_credential.go @@ -9,14 +9,15 @@ import ( type CloudCredential struct { managementClient.CloudCredential - Amazonec2CredentialConfig *amazonec2CredentialConfig `json:"amazonec2credentialConfig,omitempty" yaml:"amazonec2credentialConfig,omitempty"` - AzureCredentialConfig *azureCredentialConfig `json:"azurecredentialConfig,omitempty" yaml:"azurecredentialConfig,omitempty"` - DigitaloceanCredentialConfig *digitaloceanCredentialConfig `json:"digitaloceancredentialConfig,omitempty" yaml:"digitaloceancredentialConfig,omitempty"` - GoogleCredentialConfig *googleCredentialConfig `json:"googlecredentialConfig,omitempty" yaml:"googlecredentialConfig,omitempty"` - HarvesterCredentialConfig *harvesterCredentialConfig `json:"harvestercredentialConfig,omitempty" yaml:"harvestercredentialConfig,omitempty"` - LinodeCredentialConfig *linodeCredentialConfig `json:"linodecredentialConfig,omitempty" yaml:"linodecredentialConfig,omitempty"` - OpenstackCredentialConfig *openstackCredentialConfig `json:"openstackcredentialConfig,omitempty" yaml:"openstackcredentialConfig,omitempty"` - VmwarevsphereCredentialConfig *vmwarevsphereCredentialConfig `json:"vmwarevspherecredentialConfig,omitempty" yaml:"vmwarevspherecredentialConfig,omitempty"` + Amazonec2CredentialConfig *amazonec2CredentialConfig `json:"amazonec2credentialConfig,omitempty" yaml:"amazonec2credentialConfig,omitempty"` + AzureCredentialConfig *azureCredentialConfig `json:"azurecredentialConfig,omitempty" yaml:"azurecredentialConfig,omitempty"` + DigitaloceanCredentialConfig *digitaloceanCredentialConfig `json:"digitaloceancredentialConfig,omitempty" yaml:"digitaloceancredentialConfig,omitempty"` + GoogleCredentialConfig *googleCredentialConfig `json:"googlecredentialConfig,omitempty" yaml:"googlecredentialConfig,omitempty"` + HarvesterCredentialConfig *harvesterCredentialConfig `json:"harvestercredentialConfig,omitempty" yaml:"harvestercredentialConfig,omitempty"` + LinodeCredentialConfig *linodeCredentialConfig `json:"linodecredentialConfig,omitempty" yaml:"linodecredentialConfig,omitempty"` + OpenstackCredentialConfig *openstackCredentialConfig `json:"openstackcredentialConfig,omitempty" yaml:"openstackcredentialConfig,omitempty"` + VmwarevsphereCredentialConfig *vmwarevsphereCredentialConfig `json:"vmwarevspherecredentialConfig,omitempty" yaml:"vmwarevspherecredentialConfig,omitempty"` + OpenTelekomCloudCredentialConfig *openTelekomCloudCredentialConfig `json:"opentelekomcloudcredentialConfig,omitempty" yaml:"opentelekomcloudcredentialConfig,omitempty"` } var allCloudCredentialDriverConfigFields = []string{ @@ -28,7 +29,9 @@ var allCloudCredentialDriverConfigFields = []string{ "linode_credential_config", "openstack_credential_config", "s3_credential_config", - "vsphere_credential_config"} + "vsphere_credential_config", + "open_telekom_cloud_credential_config", +} //Schemas @@ -127,6 +130,15 @@ func cloudCredentialFields() map[string]*schema.Schema { Schema: cloudCredentialVsphereFields(), }, }, + "open_telekom_cloud_credential_config": { + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + ConflictsWith: getConflicts(allCloudCredentialDriverConfigFields, "open_telekom_cloud_credential_config"), + Elem: &schema.Resource{ + Schema: cloudCredentialOpenTelekomCloudFields(), + }, + }, } for k, v := range commonAnnotationLabelFields() { diff --git a/rancher2/schema_cloud_credential_otc.go b/rancher2/schema_cloud_credential_otc.go new file mode 100644 index 00000000..40fbe75c --- /dev/null +++ b/rancher2/schema_cloud_credential_otc.go @@ -0,0 +1,56 @@ +package rancher2 + +import ( + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" +) + +//Types + +type openTelekomCloudCredentialConfig struct { + UserName string `json:"userName,omitempty" yaml:"userName,omitempty"` + Password string `json:"password,omitempty" yaml:"password,omitempty"` + + AccessKey string `json:"accessKey,omitempty" yaml:"accessKey,omitempty"` + SecretKey string `json:"secretKey,omitempty" yaml:"secretKey,omitempty"` + + Token string `json:"token,omitempty" yaml:"token,omitempty"` +} + +//Schemas + +func cloudCredentialOpenTelekomCloudFields() map[string]*schema.Schema { + s := map[string]*schema.Schema{ + "user_name": { + Type: schema.TypeString, + Optional: true, + Sensitive: true, + Description: "Open Telekom Cloud username", + }, + "password": { + Type: schema.TypeString, + Optional: true, + Sensitive: true, + Description: "Open Telekom Cloud password", + }, + "access_key": { + Type: schema.TypeString, + Optional: true, + Sensitive: true, + Description: "Open Telekom Cloud access key", + }, + "secret_key": { + Type: schema.TypeString, + Optional: true, + Sensitive: true, + Description: "Open Telekom Cloud secret key", + }, + "token": { + Type: schema.TypeString, + Optional: true, + Sensitive: true, + Description: "Open Telekom Cloud token", + }, + } + + return s +} diff --git a/rancher2/schema_node_template_otc.go b/rancher2/schema_node_template_otc.go new file mode 100644 index 00000000..e79cece6 --- /dev/null +++ b/rancher2/schema_node_template_otc.go @@ -0,0 +1,223 @@ +package rancher2 + +import ( + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" +) + +const ( + openTelekomCloudConfigDriver = "otccce" +) + +//Types + +type openTelekomCloudConfig struct { + ActiveTimeout string `json:"activeTimeout,omitempty" yaml:"activeTimeout,omitempty"` + AuthURL string `json:"authUrl,omitempty" yaml:"authUrl,omitempty"` + AvailabilityZone string `json:"availabilityZone,omitempty" yaml:"availabilityZone,omitempty"` + CaCert string `json:"cacert,omitempty" yaml:"cacert,omitempty"` + ConfigDrive bool `json:"configDrive,omitempty" yaml:"configDrive,omitempty"` + DomainID string `json:"domainId,omitempty" yaml:"domainId,omitempty"` + DomainName string `json:"domainName,omitempty" yaml:"domainName,omitempty"` + EndpointType string `json:"endpointType,omitempty" yaml:"endpointType,omitempty"` + FlavorID string `json:"flavorId,omitempty" yaml:"flavorId,omitempty"` + FlavorName string `json:"flavorName,omitempty" yaml:"flavorName,omitempty"` + FloatingIPPool string `json:"floatingipPool,omitempty" yaml:"floatingipPool,omitempty"` + ImageID string `json:"imageId,omitempty" yaml:"imageId,omitempty"` + ImageName string `json:"imageName,omitempty" yaml:"imageName,omitempty"` + Insecure bool `json:"insecure,omitempty" yaml:"insecure,omitempty"` + IPVersion string `json:"ipVersion,omitempty" yaml:"ipVersion,omitempty"` + KeypairName string `json:"keypairName,omitempty" yaml:"keypairName,omitempty"` + NetID string `json:"netId,omitempty" yaml:"netId,omitempty"` + NetName string `json:"netName,omitempty" yaml:"netName,omitempty"` + NovaNetwork bool `json:"novaNetwork,omitempty" yaml:"novaNetwork,omitempty"` + Password string `json:"password,omitempty" yaml:"password,omitempty"` + PrivateKeyFile string `json:"privateKeyFile,omitempty" yaml:"privateKeyFile,omitempty"` + Region string `json:"region,omitempty" yaml:"region,omitempty"` + SecGroups string `json:"secGroups,omitempty" yaml:"secGroups,omitempty"` + SSHPort string `json:"sshPort,omitempty" yaml:"sshPort,omitempty"` + SSHUser string `json:"sshUser,omitempty" yaml:"sshUser,omitempty"` + TenantID string `json:"tenantId,omitempty" yaml:"tenantId,omitempty"` + TenantName string `json:"tenantName,omitempty" yaml:"tenantName,omitempty"` + UserDataFile string `json:"userDataFile,omitempty" yaml:"userDataFile,omitempty"` + Username string `json:"username,omitempty" yaml:"username,omitempty"` + ApplicationCredentialID string `json:"applicationCredentialId,omitempty" yaml:"applicationCredentialId,omitempty"` + ApplicationCredentialName string `json:"applicationCredentialName,omitempty" yaml:"applicationCredentialName,omitempty"` + ApplicationCredentialSecret string `json:"applicationCredentialSecret,omitempty" yaml:"applicationCredentialSecret,omitempty"` + BootFromVolume bool `json:"bootFromVolume,omitempty" yaml:"bootFromVolume,omitempty"` + VolumeType string `json:"volumeType,omitempty" yaml:"volumeType,omitempty"` + VolumeSize string `json:"volumeSize,omitempty" yaml:"volumeSize,omitempty"` + VolumeID string `json:"volumeId,omitempty" yaml:"volumeId,omitempty"` + VolumeName string `json:"volumeName,omitempty" yaml:"volumeName,omitempty"` + VolumeDevicePath string `json:"volumeDevicePath,omitempty" yaml:"volumeDevicePath,omitempty"` +} + +//Schemas + +func openTelekomCloudConfigFields() map[string]*schema.Schema { + s := map[string]*schema.Schema{ + "auth_url": { + Type: schema.TypeString, + Required: true, + }, + "availability_zone": { + Type: schema.TypeString, + Required: true, + }, + "region": { + Type: schema.TypeString, + Required: true, + }, + "username": { + Type: schema.TypeString, + Optional: true, + }, + "active_timeout": { + Type: schema.TypeString, + Optional: true, + Default: "200", + }, + "cacert": { + Type: schema.TypeString, + Optional: true, + }, + "config_drive": { + Type: schema.TypeBool, + Optional: true, + Default: false, + }, + "domain_id": { + Type: schema.TypeString, + Optional: true, + }, + "domain_name": { + Type: schema.TypeString, + Optional: true, + }, + "endpoint_type": { + Type: schema.TypeString, + Optional: true, + }, + "flavor_id": { + Type: schema.TypeString, + Optional: true, + }, + "flavor_name": { + Type: schema.TypeString, + Optional: true, + }, + "floating_ip_pool": { + Type: schema.TypeString, + Optional: true, + }, + "image_id": { + Type: schema.TypeString, + Optional: true, + }, + "image_name": { + Type: schema.TypeString, + Optional: true, + }, + "insecure": { + Type: schema.TypeBool, + Optional: true, + Default: false, + }, + "ip_version": { + Type: schema.TypeString, + Optional: true, + Default: "4", + }, + "keypair_name": { + Type: schema.TypeString, + Optional: true, + }, + "net_id": { + Type: schema.TypeString, + Optional: true, + }, + "net_name": { + Type: schema.TypeString, + Optional: true, + }, + "nova_network": { + Type: schema.TypeBool, + Optional: true, + Default: false, + }, + "password": { + Type: schema.TypeString, + Optional: true, + Sensitive: true, + }, + "private_key_file": { + Type: schema.TypeString, + Optional: true, + Sensitive: true, + }, + "sec_groups": { + Type: schema.TypeString, + Optional: true, + }, + "ssh_port": { + Type: schema.TypeString, + Optional: true, + Default: "22", + }, + "ssh_user": { + Type: schema.TypeString, + Optional: true, + Default: "root", + }, + "tenant_id": { + Type: schema.TypeString, + Optional: true, + }, + "tenant_name": { + Type: schema.TypeString, + Optional: true, + }, + "user_data_file": { + Type: schema.TypeString, + Optional: true, + }, + "application_credential_id": { + Type: schema.TypeString, + Optional: true, + }, + "application_credential_name": { + Type: schema.TypeString, + Optional: true, + }, + "application_credential_secret": { + Type: schema.TypeString, + Optional: true, + Sensitive: true, + }, + "boot_from_volume": { + Type: schema.TypeBool, + Optional: true, + Default: false, + }, + "volume_size": { + Type: schema.TypeString, + Optional: true, + }, + "volume_type": { + Type: schema.TypeString, + Optional: true, + }, + "volume_id": { + Type: schema.TypeString, + Optional: true, + }, + "volume_name": { + Type: schema.TypeString, + Optional: true, + }, + "volume_device_path": { + Type: schema.TypeString, + Optional: true, + }, + } + return s +} diff --git a/rancher2/structure_cloud_credential.go b/rancher2/structure_cloud_credential.go index 547c0ec0..fd5ee9b6 100644 --- a/rancher2/structure_cloud_credential.go +++ b/rancher2/structure_cloud_credential.go @@ -102,6 +102,15 @@ func flattenCloudCredential(d *schema.ResourceData, in *CloudCredential) error { if err != nil { return err } + case openTelekomCloudConfigDriver: + v, ok := d.Get("open_telekom_cloud_credential_config").([]interface{}) + if !ok { + v = []interface{}{} + } + err := d.Set("open_telekom_cloud_credential_config", flattenCloudCredentialOpenTelekomCloud(in.OpenTelekomCloudCredentialConfig, v)) + if err != nil { + return err + } default: return fmt.Errorf("[ERROR] Unsupported driver on cloud credential: %s", driver) } @@ -185,6 +194,11 @@ func expandCloudCredential(in *schema.ResourceData) *CloudCredential { in.Set("driver", vmwarevsphereConfigDriver) } + if v, ok := in.Get("open_telekom_cloud_credential_config").([]interface{}); ok && len(v) > 0 { + obj.OpenTelekomCloudCredentialConfig = expandCloudCredentialOpenTelekomCloud(v) + in.Set("driver", openTelekomCloudConfigDriver) + } + if v, ok := in.Get("annotations").(map[string]interface{}); ok && len(v) > 0 { obj.Annotations = toMapString(v) } diff --git a/rancher2/structure_cloud_credential_otc.go b/rancher2/structure_cloud_credential_otc.go new file mode 100644 index 00000000..cdc2ca2c --- /dev/null +++ b/rancher2/structure_cloud_credential_otc.go @@ -0,0 +1,70 @@ +package rancher2 + +// Flatteners + +func flattenCloudCredentialOpenTelekomCloud(in *openTelekomCloudCredentialConfig, p []interface{}) []interface{} { + var obj map[string]interface{} + if len(p) == 0 || p[0] == nil { + obj = make(map[string]interface{}) + } else { + obj = p[0].(map[string]interface{}) + } + + if in == nil { + return []interface{}{} + } + + if len(in.UserName) > 0 { + obj["user_name"] = in.UserName + } + + if len(in.Password) > 0 { + obj["password"] = in.Password + } + + if len(in.AccessKey) > 0 { + obj["access_key"] = in.AccessKey + } + + if len(in.SecretKey) > 0 { + obj["secret_key"] = in.SecretKey + } + + if len(in.Token) > 0 { + obj["token"] = in.Token + } + + return []interface{}{obj} +} + +// Expanders + +func expandCloudCredentialOpenTelekomCloud(p []interface{}) *openTelekomCloudCredentialConfig { + obj := &openTelekomCloudCredentialConfig{} + if len(p) == 0 || p[0] == nil { + return obj + } + in := p[0].(map[string]interface{}) + + if v, ok := in["user_name"].(string); ok && len(v) > 0 { + obj.UserName = v + } + + if v, ok := in["password"].(string); ok && len(v) > 0 { + obj.Password = v + } + + if v, ok := in["access_key"].(string); ok && len(v) > 0 { + obj.AccessKey = v + } + + if v, ok := in["secret_key"].(string); ok && len(v) > 0 { + obj.SecretKey = v + } + + if v, ok := in["token"].(string); ok && len(v) > 0 { + obj.Token = v + } + + return obj +} From cff1b4c645f551f32844d29b3c3beb8b27766117 Mon Sep 17 00:00:00 2001 From: Sergei Martynov Date: Thu, 4 Apr 2024 12:37:33 +0200 Subject: [PATCH 2/2] fix naming --- .../resource_rancher2_cloud_credential.go | 2 +- ...resource_rancher2_cloud_credential_test.go | 39 ++++++++++++------- rancher2/schema_cloud_credential.go | 6 +-- rancher2/structure_cloud_credential.go | 6 +-- 4 files changed, 31 insertions(+), 22 deletions(-) diff --git a/rancher2/resource_rancher2_cloud_credential.go b/rancher2/resource_rancher2_cloud_credential.go index 076b23d0..fb41dfbf 100644 --- a/rancher2/resource_rancher2_cloud_credential.go +++ b/rancher2/resource_rancher2_cloud_credential.go @@ -137,7 +137,7 @@ func resourceRancher2CloudCredentialUpdate(d *schema.ResourceData, meta interfac case vmwarevsphereConfigDriver: update["vmwarevspherecredentialConfig"] = expandCloudCredentialVsphere(d.Get("vsphere_credential_config").([]interface{})) case openTelekomCloudConfigDriver: - update["opentelekomcloudcredentialConfig"] = expandCloudCredentialOpenTelekomCloud(d.Get("open_telekom_cloud_credential_config").([]interface{})) + update["opentelekomcloudcredentialConfig"] = expandCloudCredentialOpenTelekomCloud(d.Get("opentelekomcloud_credential_config").([]interface{})) default: return fmt.Errorf("[ERROR] updating cloud credential: Unsupported driver \"%s\"", driver) } diff --git a/rancher2/resource_rancher2_cloud_credential_test.go b/rancher2/resource_rancher2_cloud_credential_test.go index 5e95dbf4..2213f464 100644 --- a/rancher2/resource_rancher2_cloud_credential_test.go +++ b/rancher2/resource_rancher2_cloud_credential_test.go @@ -180,23 +180,27 @@ resource "` + testAccRancher2CloudCredentialType + `" "foo-vsphere" { ` testAccRancher2CloudCredentialConfigOpenTelekomCloud = ` resource "` + testAccRancher2CloudCredentialType + `" "foo-otc" { - name = "foo-vsphere" + name = "foo-otc" description= "Terraform cloudCredential acceptance test" - vsphere_credential_config { + opentelekomcloud_credential_config { + user_name = "user" password = "XXXXXXXXXXXXXXXXXXXX" - username = "user" - vcenter = "vcenter" + access_key = "anyaccesskey" + secret_key = "anysecretkey" + token = "anytoken" } } ` testAccRancher2CloudCredentialUpdateConfigOpenTelekomCloud = ` resource "` + testAccRancher2CloudCredentialType + `" "foo-otc" { - name = "foo-vsphere" + name = "foo-otc" description= "Terraform cloudCredential acceptance test - updated" - vsphere_credential_config { + opentelekomcloud_credential_config { + user_name = "user" password = "YYYYYYYYYYYYYYYYYYYY" - username = "user" - vcenter = "vcenter2" + access_key = "anyaccesskey2" + secret_key = "anysecretkey2" + token = "anytoken2" } } ` @@ -722,8 +726,10 @@ func TestAccRancher2CloudCredential_basic_OTC(t *testing.T) { resource.TestCheckResourceAttr(testAccRancher2CloudCredentialType+".foo-otc", "name", "foo-otc"), resource.TestCheckResourceAttr(testAccRancher2CloudCredentialType+".foo-otc", "description", "Terraform cloudCredential acceptance test"), resource.TestCheckResourceAttr(testAccRancher2CloudCredentialType+".foo-otc", "driver", openTelekomCloudConfigDriver), - resource.TestCheckResourceAttr(testAccRancher2CloudCredentialType+".foo-otc", "open_telekom_cloud_credential_config.0.password", "XXXXXXXXXXXXXXXXXXXX"), - resource.TestCheckResourceAttr(testAccRancher2CloudCredentialType+".foo-otc", "open_telekom_cloud_credential_config.0.vcenter", "vcenter"), + resource.TestCheckResourceAttr(testAccRancher2CloudCredentialType+".foo-otc", "opentelekomcloud_credential_config.0.password", "XXXXXXXXXXXXXXXXXXXX"), + resource.TestCheckResourceAttr(testAccRancher2CloudCredentialType+".foo-otc", "opentelekomcloud_credential_config.0.access_key", "anyaccesskey"), + resource.TestCheckResourceAttr(testAccRancher2CloudCredentialType+".foo-otc", "opentelekomcloud_credential_config.0.secret_key", "anysecretkey"), + resource.TestCheckResourceAttr(testAccRancher2CloudCredentialType+".foo-otc", "opentelekomcloud_credential_config.0.token", "anytoken"), ), }, { @@ -733,8 +739,10 @@ func TestAccRancher2CloudCredential_basic_OTC(t *testing.T) { resource.TestCheckResourceAttr(testAccRancher2CloudCredentialType+".foo-otc", "name", "foo-otc"), resource.TestCheckResourceAttr(testAccRancher2CloudCredentialType+".foo-otc", "description", "Terraform cloudCredential acceptance test - updated"), resource.TestCheckResourceAttr(testAccRancher2CloudCredentialType+".foo-otc", "driver", openTelekomCloudConfigDriver), - resource.TestCheckResourceAttr(testAccRancher2CloudCredentialType+".foo-otc", "open_telekom_cloud_credential_config.0.password", "YYYYYYYYYYYYYYYYYYYY"), - resource.TestCheckResourceAttr(testAccRancher2CloudCredentialType+".foo-otc", "open_telekom_cloud_credential_config.0.vcenter", "vcenter2"), + resource.TestCheckResourceAttr(testAccRancher2CloudCredentialType+".foo-otc", "opentelekomcloud_credential_config.0.password", "YYYYYYYYYYYYYYYYYYYY"), + resource.TestCheckResourceAttr(testAccRancher2CloudCredentialType+".foo-otc", "opentelekomcloud_credential_config.0.access_key", "anyaccesskey2"), + resource.TestCheckResourceAttr(testAccRancher2CloudCredentialType+".foo-otc", "opentelekomcloud_credential_config.0.secret_key", "anysecretkey2"), + resource.TestCheckResourceAttr(testAccRancher2CloudCredentialType+".foo-otc", "opentelekomcloud_credential_config.0.token", "anytoken2"), ), }, { @@ -744,9 +752,10 @@ func TestAccRancher2CloudCredential_basic_OTC(t *testing.T) { resource.TestCheckResourceAttr(testAccRancher2CloudCredentialType+".foo-otc", "name", "foo-otc"), resource.TestCheckResourceAttr(testAccRancher2CloudCredentialType+".foo-otc", "description", "Terraform cloudCredential acceptance test"), resource.TestCheckResourceAttr(testAccRancher2CloudCredentialType+".foo-otc", "driver", openTelekomCloudConfigDriver), - resource.TestCheckResourceAttr(testAccRancher2CloudCredentialType+".foo-otc", "open_telekom_cloud_credential_config.0.password", "XXXXXXXXXXXXXXXXXXXX"), - resource.TestCheckResourceAttr(testAccRancher2CloudCredentialType+".foo-otc", "open_telekom_cloud_credential_config.0.vcenter", "vcenter"), - ), + resource.TestCheckResourceAttr(testAccRancher2CloudCredentialType+".foo-otc", "opentelekomcloud_credential_config.0.password", "XXXXXXXXXXXXXXXXXXXX"), + resource.TestCheckResourceAttr(testAccRancher2CloudCredentialType+".foo-otc", "opentelekomcloud_credential_config.0.access_key", "anyaccesskey"), + resource.TestCheckResourceAttr(testAccRancher2CloudCredentialType+".foo-otc", "opentelekomcloud_credential_config.0.secret_key", "anysecretkey"), + resource.TestCheckResourceAttr(testAccRancher2CloudCredentialType+".foo-otc", "opentelekomcloud_credential_config.0.token", "anytoken")), }, }, }) diff --git a/rancher2/schema_cloud_credential.go b/rancher2/schema_cloud_credential.go index 01d0e117..31fb6bbb 100644 --- a/rancher2/schema_cloud_credential.go +++ b/rancher2/schema_cloud_credential.go @@ -30,7 +30,7 @@ var allCloudCredentialDriverConfigFields = []string{ "openstack_credential_config", "s3_credential_config", "vsphere_credential_config", - "open_telekom_cloud_credential_config", + "opentelekomcloud_credential_config", } //Schemas @@ -130,11 +130,11 @@ func cloudCredentialFields() map[string]*schema.Schema { Schema: cloudCredentialVsphereFields(), }, }, - "open_telekom_cloud_credential_config": { + "opentelekomcloud_credential_config": { Type: schema.TypeList, MaxItems: 1, Optional: true, - ConflictsWith: getConflicts(allCloudCredentialDriverConfigFields, "open_telekom_cloud_credential_config"), + ConflictsWith: getConflicts(allCloudCredentialDriverConfigFields, "opentelekomcloud_credential_config"), Elem: &schema.Resource{ Schema: cloudCredentialOpenTelekomCloudFields(), }, diff --git a/rancher2/structure_cloud_credential.go b/rancher2/structure_cloud_credential.go index fd5ee9b6..5aab9122 100644 --- a/rancher2/structure_cloud_credential.go +++ b/rancher2/structure_cloud_credential.go @@ -103,11 +103,11 @@ func flattenCloudCredential(d *schema.ResourceData, in *CloudCredential) error { return err } case openTelekomCloudConfigDriver: - v, ok := d.Get("open_telekom_cloud_credential_config").([]interface{}) + v, ok := d.Get("opentelekomcloud_credential_config").([]interface{}) if !ok { v = []interface{}{} } - err := d.Set("open_telekom_cloud_credential_config", flattenCloudCredentialOpenTelekomCloud(in.OpenTelekomCloudCredentialConfig, v)) + err := d.Set("opentelekomcloud_credential_config", flattenCloudCredentialOpenTelekomCloud(in.OpenTelekomCloudCredentialConfig, v)) if err != nil { return err } @@ -194,7 +194,7 @@ func expandCloudCredential(in *schema.ResourceData) *CloudCredential { in.Set("driver", vmwarevsphereConfigDriver) } - if v, ok := in.Get("open_telekom_cloud_credential_config").([]interface{}); ok && len(v) > 0 { + if v, ok := in.Get("opentelekomcloud_credential_config").([]interface{}); ok && len(v) > 0 { obj.OpenTelekomCloudCredentialConfig = expandCloudCredentialOpenTelekomCloud(v) in.Set("driver", openTelekomCloudConfigDriver) }