Skip to content
This repository has been archived by the owner on Jul 21, 2020. It is now read-only.

Add generic_config to node template resource #75

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

yamamoto-febc
Copy link

This PR adds generic_config to node template resource.
This allows driver specific parameters to be specified as key/value pairs to support various node drivers in the node template.

Motivation

Rancher is supporting many node drivers.
However, this provider only supports amazonec2, azure, and digitalocean now.

It is extendable by implements driver specific codes(e.g.: for vsphere), but it limits Rancher's flexibility.

This PR opens the door to enable various node drivers to be used without driver specific codes.

Implementation

  • Added generic_config to schema of node template resource.
  • The values specified by generic_config are held in NodeTemplate struct.
  • NoteTemplate implements MarshalJSON/UnmarshalJSON to communicate driver specific parameters with the Rancher API.

Example usage of generic_config

With builtin driver

resource "rancher2_node_template" "foo" {
  name        = "foo"
  description = "Terraform node template with vsphere driver"

  generic_config {
    driver = "vmwarevsphere"

    config {
      # Specify driver specific parameters here
      username    = "XXXXXXXXXXXXXXXXXXXX"
      password    = "XXXXXXXXXXXXXXXXXXXX"
      vcenter     = "127.0.0.1"
      vcenterPort = "443"
    }
  }
}

With custom driver

resource "rancher2_node_driver" "example" {
  active            = true
  builtin           = false
  checksum          = "xxx"
  name              = "example"
  ui_url            = "https://www.example.com/ui-driver-example/component.js"
  url               = "https://www.example.com/ui-driver-example/docker-machine-driver-example_linux-amd64.zip"
  whitelist_domains = ["www.example.com"]
}

resource "rancher2_node_template" "example" {
  name        = "example-template"
  description = "Terraform node template with generic driver"

  generic_config {
    driver = "${rancher2_node_driver.example.id}"

    config {
      # Specify driver specific parameters here
      username = "XXXXXXXXXXXXXXXXXXXX"
      password = "XXXXXXXXXXXXXXXXXXXX"
    }
  }
}

@yamamoto-febc
Copy link
Author

I know #70 and #72 are working in progress.
I'll rebase this PR after they are merged.

@yamamoto-febc
Copy link
Author

@yamamoto-febc yamamoto-febc force-pushed the feature/generic-node-driver branch from 1e31d02 to d0f9c4a Compare April 18, 2019 01:17
@yamamoto-febc
Copy link
Author

  • rebased on 4de644c
  • Updated unit test to use table-driven style

@ernst-at-tv2
Copy link

Am I correct in understanding that this will lay the groundwork for a vSphere node template? but not the actual vSphere node template?

Can someone from Rancher comment on when vSphere support is expected?

@JasonvanBrackel
Copy link

@yamamoto-febc Can you take resolve the merge conflict?

@ernst-at-tv2 I'll look into that.

@rodcloutier
Copy link
Contributor

This is a step in the right direction but I was wondering if it would be possible to keep some sort of type validation in the configuration?

As it is proposed right now, there would be no validation and if a field is wrong (ie wrong type) this would only be reflected at node creation time.

Would it be possible to maybe add a schema resource to do type validation? Or do you think that we could maybe write our own provider that could be the input for the configuration?

@rawmind0
Copy link
Contributor

rawmind0 commented May 6, 2019

@yamamoto-febc, thanks for your PR and sorry for the delay.
Due to hashicorp development review requirements #67, provider has suffered a big transformation. Also, to support node template to rancher 2.2.x, we've added cloud credential support to the provider. Could you please adapt your PR code to new files structure?? Take a look to PR #91. You also need to add cloud credential support. Please, tell me if you have any question.

@ernst-at-tv2, vsphere cloud credential and node template support is added on PR #91

@rodcloutier, the scope of generic driver is to be able to add generic fields. Then validation or type check is not possible. I think it's a good idea to use it, if concrete driver support is not implemented yet.

@yamamoto-febc yamamoto-febc force-pushed the feature/generic-node-driver branch from d0f9c4a to e749486 Compare May 7, 2019 11:20
@yamamoto-febc
Copy link
Author

yamamoto-febc commented May 7, 2019

I have just rebased on latest master.

This update includes followings:

  • Adapted to new source file structure
  • Added Cloud credential support

Copy link
Contributor

@rawmind0 rawmind0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yamamoto-febc, could you please take a look to changes requested?? Take special care reviewing driverID and driverName assignments and use.

@@ -14,6 +17,89 @@ type CloudCredential struct {
DigitaloceanCredentialConfig *digitaloceanCredentialConfig `json:"digitaloceancredentialConfig,omitempty" yaml:"digitaloceancredentialConfig,omitempty"`
OpenstackCredentialConfig *openstackCredentialConfig `json:"openstackcredentialConfig,omitempty" yaml:"openstackcredentialConfig,omitempty"`
VmwarevsphereCredentialConfig *vmwarevsphereCredentialConfig `json:"vmwarevspherecredentialConfig,omitempty" yaml:"vmwarevspherecredentialConfig,omitempty"`
genericCredentialConfig *genericCredentialConfig
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please make genericCredentialConfig field public and add json and yaml definition??

-	genericCredentialConfig       *genericCredentialConfig
+	GenericCredentialConfig       *genericCredentialConfig `json:"genericcredentialConfig,omitempty" yaml:"genericcredentialConfig,omitempty"`

return ""
}

func (n *CloudCredential) UnmarshalJSON(data []byte) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't find it, but is UnmarshalJSON function used anywhere??

return nil
}

func (n *CloudCredential) MarshalJSON() ([]byte, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't find it, but is MarshalJSON function used anywhere??

driverName == vmwarevsphereConfigDriver
}

func (n *NodeTemplate) UnmarshalJSON(data []byte) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't find it, but is UnmarshalJSON function used anywhere??

return nil
}

func (n *NodeTemplate) MarshalJSON() ([]byte, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't find it, but is MarshalJSON function used anywhere??

}

return s
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

genericCredentialConfig has 3 fields defined, but just 2 fields defined on cloudCredentialGenericFields function.

Do you really need driverName?? If it's needed, please define it as field on cloudCredentialGenericFields function.

@@ -14,6 +17,72 @@ type NodeTemplate struct {
DigitaloceanConfig *digitaloceanConfig `json:"digitaloceanConfig,omitempty" yaml:"digitaloceanConfig,omitempty"`
OpenstackConfig *openstackConfig `json:"openstackConfig,omitempty" yaml:"openstackConfig,omitempty"`
VmwarevsphereConfig *vmwarevsphereConfig `json:"vmwarevsphereConfig,omitempty" yaml:"vmwarevsphereConfig,omitempty"`
genericConfig *genericNodeTemplateConfig
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please make genericConfig field public and add json and yaml definition??

-	genericConfig       * genericNodeTemplateConfig
+	GenericConfig       * genericNodeTemplateConfig `json:"genericConfig,omitempty" yaml:"genericConfig,omitempty"`

genericConfig *genericNodeTemplateConfig
}

func isTypedNodeDriver(driverName string) bool {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to clarify, amazonec2ConfigDriver and others are driver ID's not names.

return nil, fmt.Errorf("[ERROR] Driver %s can not be used with generic_credential_config", gc.driverID)
}
obj.genericCredentialConfig = gc
in.Set("driver", obj.genericCredentialConfig.driverName)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

driver should be set as driverID not driverName

return nil, fmt.Errorf("[ERROR] Node template driver %s can not be used with generic_config", gc.driverID)
}
obj.genericConfig = gc
obj.Driver = obj.genericConfig.driverName
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

obj.Driver should be set as driverID not driverName

@rawmind0
Copy link
Contributor

Due to rancher2 terraform provider is already officially supported by Hashicorp, this repo is going to be archived in favour of https://github.com/terraform-providers/terraform-provider-rancher2

Are you still interested in this PR??

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants