Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added open telekom cloud configuration for the resource rancher2_cloud_credential #8

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion rancher2/data_source_rancher2_cloud_credential.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions rancher2/resource_rancher2_cloud_credential.go
Original file line number Diff line number Diff line change
Expand Up @@ -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("opentelekomcloud_credential_config").([]interface{}))
default:
return fmt.Errorf("[ERROR] updating cloud credential: Unsupported driver \"%s\"", driver)
}
Expand Down
96 changes: 96 additions & 0 deletions rancher2/resource_rancher2_cloud_credential_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,32 @@ resource "` + testAccRancher2CloudCredentialType + `" "foo-vsphere" {
username = "user"
vcenter = "vcenter2"
}
}
`
testAccRancher2CloudCredentialConfigOpenTelekomCloud = `
resource "` + testAccRancher2CloudCredentialType + `" "foo-otc" {
name = "foo-otc"
description= "Terraform cloudCredential acceptance test"
opentelekomcloud_credential_config {
user_name = "user"
password = "XXXXXXXXXXXXXXXXXXXX"
access_key = "anyaccesskey"
secret_key = "anysecretkey"
token = "anytoken"
}
}
`
testAccRancher2CloudCredentialUpdateConfigOpenTelekomCloud = `
resource "` + testAccRancher2CloudCredentialType + `" "foo-otc" {
name = "foo-otc"
description= "Terraform cloudCredential acceptance test - updated"
opentelekomcloud_credential_config {
user_name = "user"
password = "YYYYYYYYYYYYYYYYYYYY"
access_key = "anyaccesskey2"
secret_key = "anysecretkey2"
token = "anytoken2"
}
}
`
)
Expand Down Expand Up @@ -685,6 +711,76 @@ 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", "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"),
),
},
{
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", "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"),
),
},
{
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", "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")),
},
},
})
}

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 {
Expand Down
30 changes: 21 additions & 9 deletions rancher2/schema_cloud_credential.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -28,7 +29,9 @@ var allCloudCredentialDriverConfigFields = []string{
"linode_credential_config",
"openstack_credential_config",
"s3_credential_config",
"vsphere_credential_config"}
"vsphere_credential_config",
"opentelekomcloud_credential_config",
}

//Schemas

Expand Down Expand Up @@ -127,6 +130,15 @@ func cloudCredentialFields() map[string]*schema.Schema {
Schema: cloudCredentialVsphereFields(),
},
},
"opentelekomcloud_credential_config": {
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
ConflictsWith: getConflicts(allCloudCredentialDriverConfigFields, "opentelekomcloud_credential_config"),
Elem: &schema.Resource{
Schema: cloudCredentialOpenTelekomCloudFields(),
},
},
}

for k, v := range commonAnnotationLabelFields() {
Expand Down
56 changes: 56 additions & 0 deletions rancher2/schema_cloud_credential_otc.go
Original file line number Diff line number Diff line change
@@ -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
}
Loading