diff --git a/go.mod b/go.mod index 7b6c7c5bc1a..c994adef350 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/hashicorp/errwrap v1.0.0 github.com/hashicorp/go-cleanhttp v0.5.1 github.com/hashicorp/terraform-plugin-sdk v1.13.0 - github.com/huaweicloud/golangsdk v0.0.0-20200825034233-150d13f435c6 + github.com/huaweicloud/golangsdk v0.0.0-20200826004603-97095eb9d28e github.com/jen20/awspolicyequivalence v0.0.0-20170831201602-3d48364a137a github.com/mitchellh/go-homedir v1.1.0 github.com/smartystreets/goconvey v0.0.0-20190222223459-a17d461953aa // indirect diff --git a/go.sum b/go.sum index d03186623b9..6f1668a3fb1 100644 --- a/go.sum +++ b/go.sum @@ -131,6 +131,8 @@ github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d h1:kJCB4vdITiW1eC1 github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM= github.com/huaweicloud/golangsdk v0.0.0-20200825034233-150d13f435c6 h1:YK3rhJit+LshGVxD5weCVd1HYCj1SGV8lNJEX9XfHpA= github.com/huaweicloud/golangsdk v0.0.0-20200825034233-150d13f435c6/go.mod h1:WQBcHRNX9shz3928lWEvstQJtAtYI7ks6XlgtRT9Tcw= +github.com/huaweicloud/golangsdk v0.0.0-20200826004603-97095eb9d28e h1:lpFMrN/V5grfGpITmlFHDCx+i1Mkd31C6bNHjN1Lo4Q= +github.com/huaweicloud/golangsdk v0.0.0-20200826004603-97095eb9d28e/go.mod h1:WQBcHRNX9shz3928lWEvstQJtAtYI7ks6XlgtRT9Tcw= github.com/jen20/awspolicyequivalence v0.0.0-20170831201602-3d48364a137a h1:FyS/ubzBR5xJlnJGRTwe7GUHpJOR4ukYK3y+LFNffuA= github.com/jen20/awspolicyequivalence v0.0.0-20170831201602-3d48364a137a/go.mod h1:uoIMjNxUfXi48Ci40IXkPRbghZ1vbti6v9LCbNqRgHY= github.com/jmespath/go-jmespath v0.0.0-20160202185014-0b12d6b521d8/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= diff --git a/huaweicloud/config.go b/huaweicloud/config.go index 8f951a0fa83..ad97093d8ab 100644 --- a/huaweicloud/config.go +++ b/huaweicloud/config.go @@ -513,6 +513,13 @@ func (c *Config) cceV3Client(region string) (*golangsdk.ServiceClient, error) { }) } +func (c *Config) cceAddonV3Client(region string) (*golangsdk.ServiceClient, error) { + return huaweisdk.NewCCEAddonV3(c.HwClient, golangsdk.EndpointOpts{ + Region: c.determineRegion(region), + Availability: c.getHwEndpointType(), + }) +} + func (c *Config) cciV1Client(region string) (*golangsdk.ServiceClient, error) { return huaweisdk.CCIV1(c.HwClient, golangsdk.EndpointOpts{ Region: c.determineRegion(region), diff --git a/huaweicloud/provider.go b/huaweicloud/provider.go index 7f9e77b1396..725187b90e6 100644 --- a/huaweicloud/provider.go +++ b/huaweicloud/provider.go @@ -263,6 +263,7 @@ func Provider() terraform.ResourceProvider { "huaweicloud_as_policy": resourceASPolicy(), "huaweicloud_cce_cluster": resourceCCEClusterV3(), "huaweicloud_cce_node": resourceCCENodeV3(), + "huaweicloud_cce_addon": resourceCCEAddonV3(), "huaweicloud_cci_network": resourceCCINetworkV1(), "huaweicloud_cdm_cluster": resourceCdmClusterV1(), "huaweicloud_cdn_domain": resourceCdnDomainV1(), diff --git a/huaweicloud/resource_huaweicloud_cce_addon_v3.go b/huaweicloud/resource_huaweicloud_cce_addon_v3.go new file mode 100644 index 00000000000..88b2b642f84 --- /dev/null +++ b/huaweicloud/resource_huaweicloud_cce_addon_v3.go @@ -0,0 +1,205 @@ +package huaweicloud + +import ( + "fmt" + "log" + "time" + + "github.com/huaweicloud/golangsdk" + "github.com/huaweicloud/golangsdk/openstack/cce/v3/addons" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" +) + +func resourceCCEAddonV3() *schema.Resource { + return &schema.Resource{ + Create: resourceCCEAddonV3Create, + Read: resourceCCEAddonV3Read, + Delete: resourceCCEAddonV3Delete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(10 * time.Minute), + Delete: schema.DefaultTimeout(3 * time.Minute), + }, + + Schema: map[string]*schema.Schema{ // request and response parameters + "authenticating_proxy_ca": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, + "cluster_id": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + "addon_version": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + "addon_template_name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "status": { + Type: schema.TypeString, + Computed: true, + }, + "region": { + Type: schema.TypeString, + Computed: true, + }, + }, + } +} + +func resourceCCEAddonV3Create(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + cceClient, err := config.cceAddonV3Client(GetRegion(d, config)) + + if err != nil { + return fmt.Errorf("Unable to create HuaweiCloud CCE client : %s", err) + } + authenticating_proxy := make(map[string]string) + if hasFilledOpt(d, "authenticating_proxy_ca") { + authenticating_proxy["ca"] = d.Get("authenticating_proxy_ca").(string) + } + createOpts := addons.CreateOpts{ + Kind: "Addon", + ApiVersion: "v3", + Metadata: addons.CreateMetadata{ + Anno: addons.Annotations{ + AddonInstallType: "install", + }, + }, + Spec: addons.RequestSpec{ + Version: d.Get("addon_version").(string), + ClusterID: d.Get("cluster_id").(string), + AddonTemplateName: d.Get("addon_template_name").(string), + Values: addons.Values{ + Basic: map[string]string{}, + }, + }, + } + + create, err := addons.Create(cceClient, createOpts, d.Get("cluster_id").(string)).Extract() + + if err != nil { + return fmt.Errorf("Error creating HuaweiCloud CCEAddon: %s", err) + } + + log.Printf("[DEBUG] Waiting for HuaweiCloud CCEAddon (%s) to become available", create.Metadata.Id) + + stateConf := &resource.StateChangeConf{ + Pending: []string{"installing", "abnormal"}, + Target: []string{"running"}, + Refresh: waitForCCEAddonActive(cceClient, create.Metadata.Id, d.Get("cluster_id").(string)), + Timeout: d.Timeout(schema.TimeoutCreate), + Delay: 5 * time.Second, + MinTimeout: 3 * time.Second, + } + + _, err = stateConf.WaitForState() + if err != nil { + return fmt.Errorf("Error creating HuaweiCloud CCEAddon: %s", err) + } + d.SetId(create.Metadata.Id) + + return resourceCCEAddonV3Read(d, meta) +} + +func resourceCCEAddonV3Read(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + cceClient, err := config.cceAddonV3Client(GetRegion(d, config)) + + if err != nil { + return fmt.Errorf("Error creating HuaweiCloud CCE client: %s", err) + } + + n, err := addons.Get(cceClient, d.Id(), d.Get("cluster_id").(string)).Extract() + if err != nil { + if _, ok := err.(golangsdk.ErrDefault404); ok { + d.SetId("") + return nil + } + + return fmt.Errorf("Error retrieving HuaweiCloud CCEAddon: %s", err) + } + + d.Set("name", n.Metadata.Name) + d.Set("status", n.Status.Status) + d.Set("region", GetRegion(d, config)) + + return nil +} + +func resourceCCEAddonV3Delete(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + cceClient, err := config.cceAddonV3Client(GetRegion(d, config)) + + if err != nil { + return fmt.Errorf("Error creating HuaweiCloud CCEAddon Client: %s", err) + } + err = addons.Delete(cceClient, d.Id(), d.Get("cluster_id").(string)).ExtractErr() + if err != nil { + return fmt.Errorf("Error deleting HuaweiCloud CCE Addon: %s", err) + } + stateConf := &resource.StateChangeConf{ + Pending: []string{"Deleting", "Available", "Unavailable"}, + Target: []string{"Deleted"}, + Refresh: waitForCCEAddonDelete(cceClient, d.Id(), d.Get("cluster_id").(string)), + Timeout: d.Timeout(schema.TimeoutDelete), + Delay: 5 * time.Second, + MinTimeout: 3 * time.Second, + } + + _, err = stateConf.WaitForState() + + if err != nil { + return fmt.Errorf("Error deleting HuaweiCloud CCE Addon: %s", err) + } + + d.SetId("") + return nil +} + +func waitForCCEAddonActive(cceAddonClient *golangsdk.ServiceClient, id, clusterID string) resource.StateRefreshFunc { + return func() (interface{}, string, error) { + n, err := addons.Get(cceAddonClient, id, clusterID).Extract() + if err != nil { + return nil, "", err + } + + return n, n.Status.Status, nil + } +} + +func waitForCCEAddonDelete(cceClient *golangsdk.ServiceClient, id, clusterID string) resource.StateRefreshFunc { + return func() (interface{}, string, error) { + log.Printf("[DEBUG] Attempting to delete HuaweiCloud CCE Addon %s.\n", id) + + r, err := addons.Get(cceClient, id, clusterID).Extract() + + if err != nil { + if _, ok := err.(golangsdk.ErrDefault404); ok { + log.Printf("[DEBUG] Successfully deleted HuaweiCloud CCE Addon %s", id) + return r, "Deleted", nil + } + } + if r.Status.Status == "Deleting" { + return r, "Deleting", nil + } + log.Printf("[DEBUG] HuaweiCloud CCE Addon %s still available.\n", id) + return r, "Available", nil + } +} diff --git a/huaweicloud/resource_huaweicloud_cce_addon_v3_test.go b/huaweicloud/resource_huaweicloud_cce_addon_v3_test.go new file mode 100644 index 00000000000..964549c6c61 --- /dev/null +++ b/huaweicloud/resource_huaweicloud_cce_addon_v3_test.go @@ -0,0 +1,137 @@ +package huaweicloud + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/terraform" + + "github.com/huaweicloud/golangsdk/openstack/cce/v3/addons" +) + +func TestAccCCEAddonV3_basic(t *testing.T) { + var addon addons.Addon + + rName := fmt.Sprintf("tf-acc-test-%s", acctest.RandString(5)) + resourceName := "huaweicloud_cce_addon_v3.test" + clusterName := "huaweicloud_cce_cluster_v3.test" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckCCEAddonV3Destroy, + Steps: []resource.TestStep{ + { + Config: testAccCCEAddonV3_basic(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckCCEAddonV3Exists(resourceName, clusterName, &addon), + //resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttr(resourceName, "status", "running"), + ), + }, + }, + }) +} + +func testAccCheckCCEAddonV3Destroy(s *terraform.State) error { + config := testAccProvider.Meta().(*Config) + cceClient, err := config.cceAddonV3Client(OS_REGION_NAME) + if err != nil { + return fmt.Errorf("Error creating HuaweiCloud CCE Addon client: %s", err) + } + + var clusterId string + + for _, rs := range s.RootModule().Resources { + if rs.Type == "huaweicloud_cce_cluster_v3" { + clusterId = rs.Primary.ID + } + + if rs.Type != "huaweicloud_cce_addon_v3" { + continue + } + + _, err := addons.Get(cceClient, rs.Primary.ID, clusterId).Extract() + if err == nil { + return fmt.Errorf("addon still exists") + } + } + return nil +} + +func testAccCheckCCEAddonV3Exists(n string, cluster string, addon *addons.Addon) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[n] + if !ok { + return fmt.Errorf("Not found: %s", n) + } + c, ok := s.RootModule().Resources[cluster] + if !ok { + return fmt.Errorf("Cluster not found: %s", c) + } + + if rs.Primary.ID == "" { + return fmt.Errorf("No ID is set") + } + if c.Primary.ID == "" { + return fmt.Errorf("Cluster id is not set") + } + + config := testAccProvider.Meta().(*Config) + cceClient, err := config.cceAddonV3Client(OS_REGION_NAME) + if err != nil { + return fmt.Errorf("Error creating HuaweiCloud CCE Addon client: %s", err) + } + + found, err := addons.Get(cceClient, rs.Primary.ID, c.Primary.ID).Extract() + if err != nil { + return err + } + + if found.Metadata.Id != rs.Primary.ID { + return fmt.Errorf("Addon not found") + } + + *addon = *found + + return nil + } +} + +func testAccCCEAddonV3_Base(rName string) string { + return fmt.Sprintf(` +%s + +resource "huaweicloud_cce_node_v3" "test" { + cluster_id = huaweicloud_cce_cluster_v3.test.id + name = "%s" + flavor_id = "s6.large.2" + availability_zone = data.huaweicloud_availability_zones.test.names[0] + key_pair = huaweicloud_compute_keypair_v2.test.name + + root_volume { + size = 40 + volumetype = "SATA" + } + data_volumes { + size = 100 + volumetype = "SATA" + } +} +`, testAccCCENodeV3_Base(rName), rName) +} + +func testAccCCEAddonV3_basic(rName string) string { + return fmt.Sprintf(` +%s + +resource "huaweicloud_cce_addon_v3" "test" { + cluster_id = huaweicloud_cce_cluster_v3.test.id + addon_version = "1.0.3" + addon_template_name = "metrics-server" + depends_on = [huaweicloud_cce_node_v3.test] +} +`, testAccCCEAddonV3_Base(rName)) +} diff --git a/vendor/github.com/huaweicloud/golangsdk/openstack/cce/v3/addons/requests.go b/vendor/github.com/huaweicloud/golangsdk/openstack/cce/v3/addons/requests.go new file mode 100644 index 00000000000..57df2b8c779 --- /dev/null +++ b/vendor/github.com/huaweicloud/golangsdk/openstack/cce/v3/addons/requests.go @@ -0,0 +1,87 @@ +package addons + +import ( + "github.com/huaweicloud/golangsdk" +) + +var RequestOpts golangsdk.RequestOpts = golangsdk.RequestOpts{ + MoreHeaders: map[string]string{"Content-Type": "application/json"}, +} + +// CreateOptsBuilder allows extensions to add additional parameters to the +// Create request. +type CreateOptsBuilder interface { + ToAddonCreateMap() (map[string]interface{}, error) +} + +// CreateOpts contains all the values needed to create a new addon +type CreateOpts struct { + // API type, fixed value Addon + Kind string `json:"kind" required:"true"` + // API version, fixed value v3 + ApiVersion string `json:"apiVersion" required:"true"` + // Metadata required to create an addon + Metadata CreateMetadata `json:"metadata" required:"true"` + // specifications to create an addon + Spec RequestSpec `json:"spec" required:"true"` +} + +type CreateMetadata struct { + Anno Annotations `json:"annotations" required:"true"` +} + +type Annotations struct { + AddonInstallType string `json:"addon.install/type" required:"true"` +} + +//Specifications to create an addon +type RequestSpec struct { + // For the addon version. + Version string `json:"version" required:"true"` + // Cluster ID. + ClusterID string `json:"clusterID" required:"true"` + // Addon Template Name. + AddonTemplateName string `json:"addonTemplateName" required:"true"` + // Addon Parameters + Values Values `json:"values" required:"true"` +} + +type Values struct { + Basic map[string]string `json:"basic" required:"true"` +} + +// ToAddonCreateMap builds a create request body from CreateOpts. +func (opts CreateOpts) ToAddonCreateMap() (map[string]interface{}, error) { + return golangsdk.BuildRequestBody(opts, "") +} + +// Create accepts a CreateOpts struct and uses the values to create a new +// addon. +func Create(c *golangsdk.ServiceClient, opts CreateOptsBuilder, cluster_id string) (r CreateResult) { + b, err := opts.ToAddonCreateMap() + if err != nil { + r.Err = err + return + } + reqOpt := &golangsdk.RequestOpts{OkCodes: []int{201}} + _, r.Err = c.Post(rootURL(c, cluster_id), b, &r.Body, reqOpt) + return +} + +// Get retrieves a particular addon based on its unique ID. +func Get(c *golangsdk.ServiceClient, id, cluster_id string) (r GetResult) { + _, r.Err = c.Get(resourceURL(c, id, cluster_id), &r.Body, &golangsdk.RequestOpts{ + OkCodes: []int{200}, + MoreHeaders: RequestOpts.MoreHeaders, JSONBody: nil, + }) + return +} + +// Delete will permanently delete a particular addon based on its unique ID. +func Delete(c *golangsdk.ServiceClient, id, cluster_id string) (r DeleteResult) { + _, r.Err = c.Delete(resourceURL(c, id, cluster_id), &golangsdk.RequestOpts{ + OkCodes: []int{200}, + MoreHeaders: RequestOpts.MoreHeaders, JSONBody: nil, + }) + return +} diff --git a/vendor/github.com/huaweicloud/golangsdk/openstack/cce/v3/addons/results.go b/vendor/github.com/huaweicloud/golangsdk/openstack/cce/v3/addons/results.go new file mode 100644 index 00000000000..f59ca6ddb17 --- /dev/null +++ b/vendor/github.com/huaweicloud/golangsdk/openstack/cce/v3/addons/results.go @@ -0,0 +1,94 @@ +package addons + +import ( + "github.com/huaweicloud/golangsdk" +) + +type Addon struct { + // API type, fixed value Addon + Kind string `json:"kind" required:"true"` + // API version, fixed value v3 + ApiVersion string `json:"apiVersion" required:"true"` + // Metadata of an Addon + Metadata MetaData `json:"metadata" required:"true"` + // Specifications of an Addon + Spec Spec `json:"spec" required:"true"` + // Status of an Addon + Status Status `json:"status"` +} + +//Metadata required to create an addon +type MetaData struct { + // Addon unique name + Name string `json:"name"` + // Addon unique Id + Id string `json:"uid"` + // Addon tag, key/value pair format + Labels map[string]string `json:"lables"` + // Addon annotation, key/value pair format + Annotations map[string]string `json:"annotaions"` +} + +//Specifications to create an addon +type Spec struct { + // For the addon version. + Version string `json:"version" required:"true"` + // Cluster ID. + ClusterID string `json:"clusterID" required:"true"` + // Addon Template Name. + AddonTemplateName string `json:"addonTemplateName" required:"true"` + // Addon Template Type. + AddonTemplateType string `json:"addonTemplateType" required:"true"` + // Addon Template Labels. + AddonTemplateLables []string `json:"addonTemplateLables,omitempty"` + // Addon Description. + Description string `json:"description" required:"true"` + // Addon Parameters + Values Values `json:"values" required:"true"` +} + +type Status struct { + //The state of the addon + Status string `json:"status"` + //Reasons for the addon to become current + Reason string `json:"reason"` + //Error Message + Message string `json:"message"` + //The target versions of the addon + TargetVersions []string `json:"targetVersions"` +} + +type commonResult struct { + golangsdk.Result +} + +// Extract is a function that accepts a result and extracts an Addon. +func (r commonResult) Extract() (*Addon, error) { + var s Addon + err := r.ExtractInto(&s) + return &s, err +} + +// CreateResult represents the result of a create operation. Call its Extract +// method to interpret it as an Addon. +type CreateResult struct { + commonResult +} + +// GetResult represents the result of a get operation. Call its Extract +// method to interpret it as an Addon. +type GetResult struct { + commonResult +} + +// UpdateResult represents the result of an update operation. Call its Extract +// method to interpret it as an Addon. +type UpdataResult struct { + commonResult +} + +// DeleteResult represents the result of a delete operation. Call its ExtractErr +// method to determine if the request succeeded or failed. +type DeleteResult struct { + golangsdk.ErrResult +} diff --git a/vendor/github.com/huaweicloud/golangsdk/openstack/cce/v3/addons/urls.go b/vendor/github.com/huaweicloud/golangsdk/openstack/cce/v3/addons/urls.go new file mode 100644 index 00000000000..4e4b0fee41e --- /dev/null +++ b/vendor/github.com/huaweicloud/golangsdk/openstack/cce/v3/addons/urls.go @@ -0,0 +1,24 @@ +package addons + +import ( + "strings" + + "github.com/huaweicloud/golangsdk" +) + +const ( + rootPath = "addons" +) + +func rootURL(client *golangsdk.ServiceClient, cluster_id string) string { + return CCEServiceURL(client, cluster_id, rootPath) +} + +func resourceURL(client *golangsdk.ServiceClient, id, cluster_id string) string { + return CCEServiceURL(client, cluster_id, rootPath, id+"?cluster_id="+cluster_id) +} + +func CCEServiceURL(client *golangsdk.ServiceClient, cluster_id string, parts ...string) string { + rbUrl := "https://" + cluster_id + "." + client.ResourceBaseURL()[8:] + return rbUrl + strings.Join(parts, "/") +} diff --git a/vendor/github.com/huaweicloud/golangsdk/openstack/client.go b/vendor/github.com/huaweicloud/golangsdk/openstack/client.go index 07798da5ded..5880775c762 100644 --- a/vendor/github.com/huaweicloud/golangsdk/openstack/client.go +++ b/vendor/github.com/huaweicloud/golangsdk/openstack/client.go @@ -863,6 +863,14 @@ func NewCCEV3(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*gol return sc, err } +func NewCCEAddonV3(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*golangsdk.ServiceClient, error) { + sc, err := initClientOpts(client, eo, "network") + sc.Endpoint = strings.Replace(sc.Endpoint, "vpc", "cce", 1) + sc.Endpoint = strings.Replace(sc.Endpoint, "myhwclouds", "myhuaweicloud", 1) + sc.ResourceBase = sc.Endpoint + "api/v3/" + return sc, err +} + // NewDMSServiceV1 creates a ServiceClient that may be used to access the v1 Distributed Message Service. func NewDMSServiceV1(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*golangsdk.ServiceClient, error) { sc, err := initClientOpts(client, eo, "network") diff --git a/vendor/github.com/huaweicloud/golangsdk/openstack/geminidb/v3/instances/requests.go b/vendor/github.com/huaweicloud/golangsdk/openstack/geminidb/v3/instances/requests.go index ff8e157ca50..6b07815d8a7 100644 --- a/vendor/github.com/huaweicloud/golangsdk/openstack/geminidb/v3/instances/requests.go +++ b/vendor/github.com/huaweicloud/golangsdk/openstack/geminidb/v3/instances/requests.go @@ -227,3 +227,63 @@ func GetInstanceByID(client *golangsdk.ServiceClient, instanceId string) (Gemini instance = all.Instances[0] return instance, nil } + +type UpdateNameOpts struct { + Name string `json:"name" required:"true"` +} + +type UpdateNameBuilder interface { + ToNameUpdateMap() (map[string]interface{}, error) +} + +func (opts UpdateNameOpts) ToNameUpdateMap() (map[string]interface{}, error) { + b, err := golangsdk.BuildRequestBody(opts, "") + if err != nil { + return nil, err + } + return b, nil +} + +func UpdateName(client *golangsdk.ServiceClient, instanceId string, opts UpdateNameBuilder) (r UpdateResult) { + b, err := opts.ToNameUpdateMap() + if err != nil { + r.Err = err + return + } + + _, r.Err = client.Put(updateNameURL(client, instanceId), b, &r.Body, &golangsdk.RequestOpts{ + OkCodes: []int{202}, + MoreHeaders: map[string]string{"Content-Type": "application/json", "X-Language": "en-us"}, + }) + return +} + +type UpdatePassOpts struct { + Password string `json:"password" required:"true"` +} + +type UpdatePassBuilder interface { + ToPassUpdateMap() (map[string]interface{}, error) +} + +func (opts UpdatePassOpts) ToPassUpdateMap() (map[string]interface{}, error) { + b, err := golangsdk.BuildRequestBody(opts, "") + if err != nil { + return nil, err + } + return b, nil +} + +func UpdatePass(client *golangsdk.ServiceClient, instanceId string, opts UpdatePassBuilder) (r UpdateResult) { + b, err := opts.ToPassUpdateMap() + if err != nil { + r.Err = err + return + } + + _, r.Err = client.Put(updatePassURL(client, instanceId), b, &r.Body, &golangsdk.RequestOpts{ + OkCodes: []int{202}, + MoreHeaders: map[string]string{"Content-Type": "application/json", "X-Language": "en-us"}, + }) + return +} diff --git a/vendor/github.com/huaweicloud/golangsdk/openstack/geminidb/v3/instances/results.go b/vendor/github.com/huaweicloud/golangsdk/openstack/geminidb/v3/instances/results.go index 109347fd716..257cd059bf1 100644 --- a/vendor/github.com/huaweicloud/golangsdk/openstack/geminidb/v3/instances/results.go +++ b/vendor/github.com/huaweicloud/golangsdk/openstack/geminidb/v3/instances/results.go @@ -124,6 +124,10 @@ func (r ExtendResult) Extract() (*ExtendResponse, error) { return &response, err } +type UpdateResult struct { + golangsdk.ErrResult +} + type ListGeminiDBResult struct { commonResult } diff --git a/vendor/github.com/huaweicloud/golangsdk/openstack/geminidb/v3/instances/urls.go b/vendor/github.com/huaweicloud/golangsdk/openstack/geminidb/v3/instances/urls.go index f55c1794db6..2d78bf375e2 100644 --- a/vendor/github.com/huaweicloud/golangsdk/openstack/geminidb/v3/instances/urls.go +++ b/vendor/github.com/huaweicloud/golangsdk/openstack/geminidb/v3/instances/urls.go @@ -22,6 +22,14 @@ func reduceNodeURL(c *golangsdk.ServiceClient, instanceID string) string { return c.ServiceURL("instances", instanceID, "reduce-node") } +func updateNameURL(c *golangsdk.ServiceClient, instanceID string) string { + return c.ServiceURL("instances", instanceID, "name") +} + +func updatePassURL(c *golangsdk.ServiceClient, instanceID string) string { + return c.ServiceURL("instances", instanceID, "password") +} + func listURL(c *golangsdk.ServiceClient) string { return c.ServiceURL("instances") } diff --git a/vendor/modules.txt b/vendor/modules.txt index 14f517283a0..c2d4cbf8e84 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -186,7 +186,7 @@ github.com/hashicorp/terraform-svchost/auth github.com/hashicorp/terraform-svchost/disco # github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d github.com/hashicorp/yamux -# github.com/huaweicloud/golangsdk v0.0.0-20200825034233-150d13f435c6 +# github.com/huaweicloud/golangsdk v0.0.0-20200826004603-97095eb9d28e ## explicit github.com/huaweicloud/golangsdk github.com/huaweicloud/golangsdk/internal @@ -201,6 +201,7 @@ github.com/huaweicloud/golangsdk/openstack/autoscaling/v1/policies github.com/huaweicloud/golangsdk/openstack/autoscaling/v1/tags github.com/huaweicloud/golangsdk/openstack/blockstorage/extensions/volumeactions github.com/huaweicloud/golangsdk/openstack/blockstorage/v2/volumes +github.com/huaweicloud/golangsdk/openstack/cce/v3/addons github.com/huaweicloud/golangsdk/openstack/cce/v3/clusters github.com/huaweicloud/golangsdk/openstack/cce/v3/nodes github.com/huaweicloud/golangsdk/openstack/cci/v1/networks diff --git a/website/docs/r/cce_addon.html.markdown b/website/docs/r/cce_addon.html.markdown new file mode 100644 index 00000000000..99d9532b5ac --- /dev/null +++ b/website/docs/r/cce_addon.html.markdown @@ -0,0 +1,40 @@ +--- +layout: "huaweicloud" +page_title: "huaweicloud: huaweicloud_cce_addon" +sidebar_current: "docs-huaweicloud-resource-cce-addon" +description: |- + Add an addon to a container cluster. +--- + +# huaweicloud\_cce\_addon +Add an addon to a container cluster. +This is an alternative to `huaweicloud_cce_addon` + +## Example Usage +```hcl +variable "cluster_id" { } + +resource "huaweicloud_cce_addon" "addon_test" { + cluster_id = var.cluster_id + addon_template_name = "metrics-server" + addon_version = "1.0.0" +} +``` + +## Argument Reference +The following arguments are supported: +* `cluster_id` - (Required) ID of the cluster. Changing this parameter will create a new resource. +* `addon_template_name` - (Required) Name of the addon template. Changing this parameter will create a new resource. +* `addon_version` - (Required) Version of the addon. Changing this parameter will create a new resource. + +## Attributes Reference + +All above argument parameters can be exported as attribute parameters along with attribute reference. + + * `id` - ID of the addon instance. + + * `name` - Addon instance name. + + * `region` - The regin of cluster. + + * `status` - Addon status information. \ No newline at end of file diff --git a/website/huaweicloud.erb b/website/huaweicloud.erb index 807db31c25d..d4b4cc8e278 100644 --- a/website/huaweicloud.erb +++ b/website/huaweicloud.erb @@ -93,6 +93,9 @@