diff --git a/go.mod b/go.mod index 7b6c7c5bc1a..7633f5abe65 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-20200827051055-27c9c7b6b988 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..806a2f1cb01 100644 --- a/go.sum +++ b/go.sum @@ -131,6 +131,10 @@ 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/huaweicloud/golangsdk v0.0.0-20200827051055-27c9c7b6b988 h1:a/lJW8PBLTcr1h062r1zKZBBB6Z23VteWcSnwF9JCds= +github.com/huaweicloud/golangsdk v0.0.0-20200827051055-27c9c7b6b988/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..81eac7647e5 --- /dev/null +++ b/huaweicloud/resource_huaweicloud_cce_addon_v3.go @@ -0,0 +1,215 @@ +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, + + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(10 * time.Minute), + Delete: schema.DefaultTimeout(3 * time.Minute), + }, + + Schema: map[string]*schema.Schema{ // request and response parameters + "cluster_id": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + "version": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + "template_name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "status": { + Type: schema.TypeString, + Computed: true, + }, + "description": { + Type: schema.TypeString, + Computed: true, + }, + "kind": { + Type: schema.TypeString, + Computed: true, + }, + "api_version": { + 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) + } + + var cluster_id = d.Get("cluster_id").(string) + + createOpts := addons.CreateOpts{ + Kind: "Addon", + ApiVersion: "v3", + Metadata: addons.CreateMetadata{ + Anno: addons.Annotations{ + AddonInstallType: "install", + }, + }, + Spec: addons.RequestSpec{ + Version: d.Get("version").(string), + ClusterID: cluster_id, + AddonTemplateName: d.Get("template_name").(string), + Values: addons.Values{ + Basic: map[string]string{}, + }, + }, + } + + create, err := addons.Create(cceClient, createOpts, cluster_id).Extract() + + d.SetId(create.Metadata.Id) + + 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, cluster_id), + 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) + } + + 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) + } + + var cluster_id = d.Get("cluster_id").(string) + + n, err := addons.Get(cceClient, d.Id(), cluster_id).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("cluster_id", n.Spec.ClusterID) + d.Set("version", n.Spec.Version) + d.Set("template_name", n.Spec.AddonTemplateName) + d.Set("name", n.Metadata.Name) + d.Set("status", n.Status.Status) + d.Set("description", n.Spec.Description) + d.Set("kind", n.Kind) + d.Set("api_version", n.ApiVersion) + + 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) + } + + var cluster_id = d.Get("cluster_id").(string) + + err = addons.Delete(cceClient, d.Id(), cluster_id).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..334e8e7e990 --- /dev/null +++ b/huaweicloud/resource_huaweicloud_cce_addon_v3_test.go @@ -0,0 +1,138 @@ +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.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, "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" { + continue + } + + if clusterId != "" { + _, 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" "test" { + cluster_id = huaweicloud_cce_cluster_v3.test.id + version = "1.0.3" + 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..89983fcff6d 100644 --- a/vendor/github.com/huaweicloud/golangsdk/openstack/client.go +++ b/vendor/github.com/huaweicloud/golangsdk/openstack/client.go @@ -9,10 +9,9 @@ import ( "github.com/huaweicloud/golangsdk" tokens2 "github.com/huaweicloud/golangsdk/openstack/identity/v2/tokens" + "github.com/huaweicloud/golangsdk/openstack/identity/v3/catalog" "github.com/huaweicloud/golangsdk/openstack/identity/v3/domains" - "github.com/huaweicloud/golangsdk/openstack/identity/v3/endpoints" "github.com/huaweicloud/golangsdk/openstack/identity/v3/projects" - "github.com/huaweicloud/golangsdk/openstack/identity/v3/services" tokens3 "github.com/huaweicloud/golangsdk/openstack/identity/v3/tokens" "github.com/huaweicloud/golangsdk/openstack/utils" "github.com/huaweicloud/golangsdk/pagination" @@ -313,17 +312,20 @@ func v3AKSKAuth(client *golangsdk.ProviderClient, endpoint string, options golan return err } + // Override the generated service endpoint with the one returned by the version endpoint. if endpoint != "" { v3Client.Endpoint = endpoint } + // update AKSKAuthOptions of ProviderClient + // ProviderClient(client) is a reference to the ServiceClient(v3Client) defer func() { - v3Client.AKSKAuthOptions.ProjectId = options.ProjectId - v3Client.AKSKAuthOptions.DomainID = options.DomainID + client.AKSKAuthOptions.ProjectId = options.ProjectId + client.AKSKAuthOptions.DomainID = options.DomainID }() - v3Client.AKSKAuthOptions = options - v3Client.AKSKAuthOptions.ProjectId = "" - v3Client.AKSKAuthOptions.DomainID = "" + + client.AKSKAuthOptions = options + client.AKSKAuthOptions.DomainID = "" if options.ProjectId == "" && options.ProjectName != "" { id, err := getProjectID(v3Client, options.ProjectName) @@ -331,6 +333,7 @@ func v3AKSKAuth(client *golangsdk.ProviderClient, endpoint string, options golan return err } options.ProjectId = id + client.AKSKAuthOptions.ProjectId = options.ProjectId } if options.DomainID == "" && options.Domain != "" { @@ -353,23 +356,15 @@ func v3AKSKAuth(client *golangsdk.ProviderClient, endpoint string, options golan client.ProjectID = options.ProjectId client.DomainID = options.BssDomainID - v3Client.ProjectID = options.ProjectId var entries = make([]tokens3.CatalogEntry, 0, 1) - err = services.List(v3Client, services.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) { - serviceLst, err := services.ExtractServices(page) + err = catalog.List(v3Client).EachPage(func(page pagination.Page) (bool, error) { + catalogList, err := catalog.ExtractServiceCatalog(page) if err != nil { return false, err } - for _, svc := range serviceLst { - entry := tokens3.CatalogEntry{ - Type: svc.Type, - //Name: svc.Name, - ID: svc.ID, - } - entries = append(entries, entry) - } + entries = append(entries, catalogList...) return true, nil }) @@ -378,30 +373,6 @@ func v3AKSKAuth(client *golangsdk.ProviderClient, endpoint string, options golan return err } - err = endpoints.List(v3Client, endpoints.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) { - endpoints, err := endpoints.ExtractEndpoints(page) - if err != nil { - return false, err - } - - for _, endpoint := range endpoints { - entry := getEntryByServiceId(entries, endpoint.ServiceID) - - if entry != nil { - entry.Endpoints = append(entry.Endpoints, tokens3.Endpoint{ - URL: strings.Replace(endpoint.URL, "$(tenant_id)s", options.ProjectId, -1), - Region: endpoint.Region, - Interface: string(endpoint.Availability), - ID: endpoint.ID, - }) - } - } - return true, nil - }) - if err != nil { - return err - } - client.EndpointLocator = func(opts golangsdk.EndpointOpts) (string, error) { return V3EndpointURL(&tokens3.ServiceCatalog{ Entries: entries, @@ -863,6 +834,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..52810846b4f 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{204}, + 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{204}, + 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/github.com/huaweicloud/golangsdk/openstack/identity/v3/catalog/requests.go b/vendor/github.com/huaweicloud/golangsdk/openstack/identity/v3/catalog/requests.go new file mode 100644 index 00000000000..4164cbb295e --- /dev/null +++ b/vendor/github.com/huaweicloud/golangsdk/openstack/identity/v3/catalog/requests.go @@ -0,0 +1,14 @@ +package catalog + +import ( + "github.com/huaweicloud/golangsdk" + "github.com/huaweicloud/golangsdk/pagination" +) + +// List enumerates the services available to a specific user. +func List(client *golangsdk.ServiceClient) pagination.Pager { + url := listURL(client) + return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { + return CatalogPage{pagination.LinkedPageBase{PageResult: r}} + }) +} diff --git a/vendor/github.com/huaweicloud/golangsdk/openstack/identity/v3/catalog/results.go b/vendor/github.com/huaweicloud/golangsdk/openstack/identity/v3/catalog/results.go new file mode 100644 index 00000000000..e14bce0687c --- /dev/null +++ b/vendor/github.com/huaweicloud/golangsdk/openstack/identity/v3/catalog/results.go @@ -0,0 +1,42 @@ +package catalog + +import ( + "github.com/huaweicloud/golangsdk/openstack/identity/v3/tokens" + "github.com/huaweicloud/golangsdk/pagination" +) + +// CatalogPage is a single page of Service results. +type CatalogPage struct { + pagination.LinkedPageBase +} + +// IsEmpty returns true if the CatalogPage contains no results. +func (p CatalogPage) IsEmpty() (bool, error) { + services, err := ExtractServiceCatalog(p) + return len(services) == 0, err +} + +// NextPageURL extracts the "next" link from the links section of the result. +func (r CatalogPage) NextPageURL() (string, error) { + var s struct { + Links struct { + Next string `json:"next"` + Previous string `json:"previous"` + } `json:"links"` + } + err := r.ExtractInto(&s) + if err != nil { + return "", err + } + return s.Links.Next, err +} + +// ExtractServiceCatalog extracts a slice of Catalog from a Collection acquired +// from List. +func ExtractServiceCatalog(r pagination.Page) ([]tokens.CatalogEntry, error) { + var s struct { + Entries []tokens.CatalogEntry `json:"catalog"` + } + err := (r.(CatalogPage)).ExtractInto(&s) + return s.Entries, err +} diff --git a/vendor/github.com/huaweicloud/golangsdk/openstack/identity/v3/catalog/urls.go b/vendor/github.com/huaweicloud/golangsdk/openstack/identity/v3/catalog/urls.go new file mode 100644 index 00000000000..da9b15019c8 --- /dev/null +++ b/vendor/github.com/huaweicloud/golangsdk/openstack/identity/v3/catalog/urls.go @@ -0,0 +1,7 @@ +package catalog + +import "github.com/huaweicloud/golangsdk" + +func listURL(client *golangsdk.ServiceClient) string { + return client.ServiceURL("auth/catalog") +} diff --git a/vendor/github.com/huaweicloud/golangsdk/openstack/identity/v3/endpoints/doc.go b/vendor/github.com/huaweicloud/golangsdk/openstack/identity/v3/endpoints/doc.go deleted file mode 100644 index 380a3f38e85..00000000000 --- a/vendor/github.com/huaweicloud/golangsdk/openstack/identity/v3/endpoints/doc.go +++ /dev/null @@ -1,69 +0,0 @@ -/* -Package endpoints provides information and interaction with the service -endpoints API resource in the OpenStack Identity service. - -For more information, see: -http://developer.openstack.org/api-ref-identity-v3.html#endpoints-v3 - -Example to List Endpoints - - serviceID := "e629d6e599d9489fb3ae5d9cc12eaea3" - - listOpts := endpoints.ListOpts{ - ServiceID: serviceID, - } - - allPages, err := endpoints.List(identityClient, listOpts).AllPages() - if err != nil { - panic(err) - } - - allEndpoints, err := endpoints.ExtractEndpoints(allPages) - if err != nil { - panic(err) - } - - for _, endpoint := range allEndpoints { - fmt.Printf("%+v\n", endpoint) - } - -Example to Create an Endpoint - - serviceID := "e629d6e599d9489fb3ae5d9cc12eaea3" - - createOpts := endpoints.CreateOpts{ - Availability: golangsdk.AvailabilityPublic, - Name: "neutron", - Region: "RegionOne", - URL: "https://localhost:9696", - ServiceID: serviceID, - } - - endpoint, err := endpoints.Create(identityClient, createOpts).Extract() - if err != nil { - panic(err) - } - - -Example to Update an Endpoint - - endpointID := "ad59deeec5154d1fa0dcff518596f499" - - updateOpts := endpoints.UpdateOpts{ - Region: "RegionTwo", - } - - endpoint, err := endpoints.Update(identityClient, endpointID, updateOpts).Extract() - if err != nil { - panic(err) - } - -Example to Delete an Endpoint - - endpointID := "ad59deeec5154d1fa0dcff518596f499" - err := endpoints.Delete(identityClient, endpointID).ExtractErr() - if err != nil { - panic(err) - } -*/ -package endpoints diff --git a/vendor/github.com/huaweicloud/golangsdk/openstack/identity/v3/endpoints/requests.go b/vendor/github.com/huaweicloud/golangsdk/openstack/identity/v3/endpoints/requests.go deleted file mode 100644 index 54f101de901..00000000000 --- a/vendor/github.com/huaweicloud/golangsdk/openstack/identity/v3/endpoints/requests.go +++ /dev/null @@ -1,139 +0,0 @@ -package endpoints - -import ( - "github.com/huaweicloud/golangsdk" - "github.com/huaweicloud/golangsdk/pagination" -) - -type CreateOptsBuilder interface { - ToEndpointCreateMap() (map[string]interface{}, error) -} - -// CreateOpts contains the subset of Endpoint attributes that should be used -// to create an Endpoint. -type CreateOpts struct { - // Availability is the interface type of the Endpoint (admin, internal, - // or public), referenced by the golangsdk.Availability type. - Availability golangsdk.Availability `json:"interface" required:"true"` - - // Name is the name of the Endpoint. - Name string `json:"name" required:"true"` - - // Region is the region the Endpoint is located in. - // This field can be omitted or left as a blank string. - Region string `json:"region,omitempty"` - - // URL is the url of the Endpoint. - URL string `json:"url" required:"true"` - - // ServiceID is the ID of the service the Endpoint refers to. - ServiceID string `json:"service_id" required:"true"` -} - -// ToEndpointCreateMap builds a request body from the Endpoint Create options. -func (opts CreateOpts) ToEndpointCreateMap() (map[string]interface{}, error) { - return golangsdk.BuildRequestBody(opts, "endpoint") -} - -// Create inserts a new Endpoint into the service catalog. -func Create(client *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { - b, err := opts.ToEndpointCreateMap() - if err != nil { - r.Err = err - return - } - _, r.Err = client.Post(listURL(client), &b, &r.Body, nil) - return -} - -// ListOptsBuilder allows extensions to add parameters to the List request. -type ListOptsBuilder interface { - ToEndpointListParams() (string, error) -} - -// ListOpts allows finer control over the endpoints returned by a List call. -// All fields are optional. -type ListOpts struct { - // Availability is the interface type of the Endpoint (admin, internal, - // or public), referenced by the golangsdk.Availability type. - Availability golangsdk.Availability `q:"interface"` - - // ServiceID is the ID of the service the Endpoint refers to. - ServiceID string `q:"service_id"` - - // Page is a result page to reference in the results. - Page int `q:"page"` - - // PerPage determines how many results per page are returned. - PerPage int `q:"per_page"` -} - -// ToEndpointListParams builds a list request from the List options. -func (opts ListOpts) ToEndpointListParams() (string, error) { - q, err := golangsdk.BuildQueryString(opts) - return q.String(), err -} - -// List enumerates endpoints in a paginated collection, optionally filtered -// by ListOpts criteria. -func List(client *golangsdk.ServiceClient, opts ListOptsBuilder) pagination.Pager { - u := listURL(client) - if opts != nil { - q, err := golangsdk.BuildQueryString(opts) - if err != nil { - return pagination.Pager{Err: err} - } - u += q.String() - } - return pagination.NewPager(client, u, func(r pagination.PageResult) pagination.Page { - return EndpointPage{pagination.LinkedPageBase{PageResult: r}} - }) -} - -// UpdateOptsBuilder allows extensions to add parameters to the Update request. -type UpdateOptsBuilder interface { - ToEndpointUpdateMap() (map[string]interface{}, error) -} - -// UpdateOpts contains the subset of Endpoint attributes that should be used to -// update an Endpoint. -type UpdateOpts struct { - // Availability is the interface type of the Endpoint (admin, internal, - // or public), referenced by the golangsdk.Availability type. - Availability golangsdk.Availability `json:"interface,omitempty"` - - // Name is the name of the Endpoint. - Name string `json:"name,omitempty"` - - // Region is the region the Endpoint is located in. - // This field can be omitted or left as a blank string. - Region string `json:"region,omitempty"` - - // URL is the url of the Endpoint. - URL string `json:"url,omitempty"` - - // ServiceID is the ID of the service the Endpoint refers to. - ServiceID string `json:"service_id,omitempty"` -} - -// ToEndpointUpdateMap builds an update request body from the Update options. -func (opts UpdateOpts) ToEndpointUpdateMap() (map[string]interface{}, error) { - return golangsdk.BuildRequestBody(opts, "endpoint") -} - -// Update changes an existing endpoint with new data. -func Update(client *golangsdk.ServiceClient, endpointID string, opts UpdateOptsBuilder) (r UpdateResult) { - b, err := opts.ToEndpointUpdateMap() - if err != nil { - r.Err = err - return - } - _, r.Err = client.Patch(endpointURL(client, endpointID), &b, &r.Body, nil) - return -} - -// Delete removes an endpoint from the service catalog. -func Delete(client *golangsdk.ServiceClient, endpointID string) (r DeleteResult) { - _, r.Err = client.Delete(endpointURL(client, endpointID), nil) - return -} diff --git a/vendor/github.com/huaweicloud/golangsdk/openstack/identity/v3/endpoints/results.go b/vendor/github.com/huaweicloud/golangsdk/openstack/identity/v3/endpoints/results.go deleted file mode 100644 index fccf7350db4..00000000000 --- a/vendor/github.com/huaweicloud/golangsdk/openstack/identity/v3/endpoints/results.go +++ /dev/null @@ -1,80 +0,0 @@ -package endpoints - -import ( - "github.com/huaweicloud/golangsdk" - "github.com/huaweicloud/golangsdk/pagination" -) - -type commonResult struct { - golangsdk.Result -} - -// Extract interprets a GetResult, CreateResult or UpdateResult as a concrete -// Endpoint. An error is returned if the original call or the extraction failed. -func (r commonResult) Extract() (*Endpoint, error) { - var s struct { - Endpoint *Endpoint `json:"endpoint"` - } - err := r.ExtractInto(&s) - return s.Endpoint, err -} - -// CreateResult is the response from a Create operation. Call its Extract -// method to interpret it as an Endpoint. -type CreateResult struct { - commonResult -} - -// UpdateResult is the response from an Update operation. Call its Extract -// method to interpret it as an Endpoint. -type UpdateResult struct { - commonResult -} - -// DeleteResult is the response from a Delete operation. Call its ExtractErr -// method to determine if the call succeeded or failed. -type DeleteResult struct { - golangsdk.ErrResult -} - -// Endpoint describes the entry point for another service's API. -type Endpoint struct { - // ID is the unique ID of the endpoint. - ID string `json:"id"` - - // Availability is the interface type of the Endpoint (admin, internal, - // or public), referenced by the golangsdk.Availability type. - Availability golangsdk.Availability `json:"interface"` - - // Name is the name of the Endpoint. - Name string `json:"name"` - - // Region is the region the Endpoint is located in. - Region string `json:"region"` - - // ServiceID is the ID of the service the Endpoint refers to. - ServiceID string `json:"service_id"` - - // URL is the url of the Endpoint. - URL string `json:"url"` -} - -// EndpointPage is a single page of Endpoint results. -type EndpointPage struct { - pagination.LinkedPageBase -} - -// IsEmpty returns true if no Endpoints were returned. -func (r EndpointPage) IsEmpty() (bool, error) { - es, err := ExtractEndpoints(r) - return len(es) == 0, err -} - -// ExtractEndpoints extracts an Endpoint slice from a Page. -func ExtractEndpoints(r pagination.Page) ([]Endpoint, error) { - var s struct { - Endpoints []Endpoint `json:"endpoints"` - } - err := (r.(EndpointPage)).ExtractInto(&s) - return s.Endpoints, err -} diff --git a/vendor/github.com/huaweicloud/golangsdk/openstack/identity/v3/endpoints/urls.go b/vendor/github.com/huaweicloud/golangsdk/openstack/identity/v3/endpoints/urls.go deleted file mode 100644 index d799d22e109..00000000000 --- a/vendor/github.com/huaweicloud/golangsdk/openstack/identity/v3/endpoints/urls.go +++ /dev/null @@ -1,11 +0,0 @@ -package endpoints - -import "github.com/huaweicloud/golangsdk" - -func listURL(client *golangsdk.ServiceClient) string { - return client.ServiceURL("endpoints") -} - -func endpointURL(client *golangsdk.ServiceClient, endpointID string) string { - return client.ServiceURL("endpoints", endpointID) -} diff --git a/vendor/github.com/huaweicloud/golangsdk/openstack/identity/v3/services/doc.go b/vendor/github.com/huaweicloud/golangsdk/openstack/identity/v3/services/doc.go deleted file mode 100644 index 81702359ac8..00000000000 --- a/vendor/github.com/huaweicloud/golangsdk/openstack/identity/v3/services/doc.go +++ /dev/null @@ -1,66 +0,0 @@ -/* -Package services provides information and interaction with the services API -resource for the OpenStack Identity service. - -Example to List Services - - listOpts := services.ListOpts{ - ServiceType: "compute", - } - - allPages, err := services.List(identityClient, listOpts).AllPages() - if err != nil { - panic(err) - } - - allServices, err := services.ExtractServices(allPages) - if err != nil { - panic(err) - } - - for _, service := range allServices { - fmt.Printf("%+v\n", service) - } - -Example to Create a Service - - createOpts := services.CreateOpts{ - Type: "compute", - Extra: map[string]interface{}{ - "name": "compute-service", - "description": "Compute Service", - }, - } - - service, err := services.Create(identityClient, createOpts).Extract() - if err != nil { - panic(err) - } - -Example to Update a Service - - serviceID := "3c7bbe9a6ecb453ca1789586291380ed" - - var iFalse bool = false - updateOpts := services.UpdateOpts{ - Enabled: &iFalse, - Extra: map[string]interface{}{ - "description": "Disabled Compute Service" - }, - } - - service, err := services.Update(identityClient, serviceID, updateOpts).Extract() - if err != nil { - panic(err) - } - -Example to Delete a Service - - serviceID := "3c7bbe9a6ecb453ca1789586291380ed" - err := services.Delete(identityClient, serviceID).ExtractErr() - if err != nil { - panic(err) - } - -*/ -package services diff --git a/vendor/github.com/huaweicloud/golangsdk/openstack/identity/v3/services/requests.go b/vendor/github.com/huaweicloud/golangsdk/openstack/identity/v3/services/requests.go deleted file mode 100644 index cf3fae6bec5..00000000000 --- a/vendor/github.com/huaweicloud/golangsdk/openstack/identity/v3/services/requests.go +++ /dev/null @@ -1,154 +0,0 @@ -package services - -import ( - "github.com/huaweicloud/golangsdk" - "github.com/huaweicloud/golangsdk/pagination" -) - -// CreateOptsBuilder allows extensions to add additional parameters to -// the Create request. -type CreateOptsBuilder interface { - ToServiceCreateMap() (map[string]interface{}, error) -} - -// CreateOpts provides options used to create a service. -type CreateOpts struct { - // Type is the type of the service. - Type string `json:"type"` - - // Enabled is whether or not the service is enabled. - Enabled *bool `json:"enabled,omitempty"` - - // Extra is free-form extra key/value pairs to describe the service. - Extra map[string]interface{} `json:"-"` -} - -// ToServiceCreateMap formats a CreateOpts into a create request. -func (opts CreateOpts) ToServiceCreateMap() (map[string]interface{}, error) { - b, err := golangsdk.BuildRequestBody(opts, "service") - if err != nil { - return nil, err - } - - if opts.Extra != nil { - if v, ok := b["service"].(map[string]interface{}); ok { - for key, value := range opts.Extra { - v[key] = value - } - } - } - - return b, nil -} - -// Create adds a new service of the requested type to the catalog. -func Create(client *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { - b, err := opts.ToServiceCreateMap() - if err != nil { - r.Err = err - return - } - _, r.Err = client.Post(createURL(client), &b, &r.Body, &golangsdk.RequestOpts{ - OkCodes: []int{201}, - }) - return -} - -// ListOptsBuilder enables extensions to add additional parameters to the List -// request. -type ListOptsBuilder interface { - ToServiceListMap() (string, error) -} - -// ListOpts provides options for filtering the List results. -type ListOpts struct { - // ServiceType filter the response by a type of service. - ServiceType string `q:"type"` - - // Name filters the response by a service name. - Name string `q:"name"` -} - -// ToServiceListMap builds a list query from the list options. -func (opts ListOpts) ToServiceListMap() (string, error) { - q, err := golangsdk.BuildQueryString(opts) - return q.String(), err -} - -// List enumerates the services available to a specific user. -func List(client *golangsdk.ServiceClient, opts ListOptsBuilder) pagination.Pager { - url := listURL(client) - if opts != nil { - query, err := opts.ToServiceListMap() - if err != nil { - return pagination.Pager{Err: err} - } - url += query - } - return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { - return ServicePage{pagination.LinkedPageBase{PageResult: r}} - }) -} - -// Get returns additional information about a service, given its ID. -func Get(client *golangsdk.ServiceClient, serviceID string) (r GetResult) { - _, r.Err = client.Get(serviceURL(client, serviceID), &r.Body, nil) - return -} - -// UpdateOptsBuilder allows extensions to add additional parameters to -// the Update request. -type UpdateOptsBuilder interface { - ToServiceUpdateMap() (map[string]interface{}, error) -} - -// UpdateOpts provides options for updating a service. -type UpdateOpts struct { - // Type is the type of the service. - Type string `json:"type"` - - // Enabled is whether or not the service is enabled. - Enabled *bool `json:"enabled,omitempty"` - - // Extra is free-form extra key/value pairs to describe the service. - Extra map[string]interface{} `json:"-"` -} - -// ToServiceUpdateMap formats a UpdateOpts into an update request. -func (opts UpdateOpts) ToServiceUpdateMap() (map[string]interface{}, error) { - b, err := golangsdk.BuildRequestBody(opts, "service") - if err != nil { - return nil, err - } - - if opts.Extra != nil { - if v, ok := b["service"].(map[string]interface{}); ok { - for key, value := range opts.Extra { - v[key] = value - } - } - } - - return b, nil -} - -// Update updates an existing Service. -func Update(client *golangsdk.ServiceClient, serviceID string, opts UpdateOptsBuilder) (r UpdateResult) { - b, err := opts.ToServiceUpdateMap() - if err != nil { - r.Err = err - return - } - _, r.Err = client.Patch(updateURL(client, serviceID), &b, &r.Body, &golangsdk.RequestOpts{ - OkCodes: []int{200}, - }) - return -} - -// Delete removes an existing service. -// It either deletes all associated endpoints, or fails until all endpoints -// are deleted. -func Delete(client *golangsdk.ServiceClient, serviceID string) (r DeleteResult) { - _, r.Err = client.Delete(serviceURL(client, serviceID), nil) - return -} diff --git a/vendor/github.com/huaweicloud/golangsdk/openstack/identity/v3/services/results.go b/vendor/github.com/huaweicloud/golangsdk/openstack/identity/v3/services/results.go deleted file mode 100644 index f49f00ef668..00000000000 --- a/vendor/github.com/huaweicloud/golangsdk/openstack/identity/v3/services/results.go +++ /dev/null @@ -1,131 +0,0 @@ -package services - -import ( - "encoding/json" - - "github.com/huaweicloud/golangsdk" - "github.com/huaweicloud/golangsdk/internal" - "github.com/huaweicloud/golangsdk/pagination" -) - -type serviceResult struct { - golangsdk.Result -} - -// Extract interprets a GetResult, CreateResult or UpdateResult as a concrete -// Service. An error is returned if the original call or the extraction failed. -func (r serviceResult) Extract() (*Service, error) { - var s struct { - Service *Service `json:"service"` - } - err := r.ExtractInto(&s) - return s.Service, err -} - -// CreateResult is the response from a Create request. Call its Extract method -// to interpret it as a Service. -type CreateResult struct { - serviceResult -} - -// GetResult is the response from a Get request. Call its Extract method -// to interpret it as a Service. -type GetResult struct { - serviceResult -} - -// UpdateResult is the response from an Update request. Call its Extract method -// to interpret it as a Service. -type UpdateResult struct { - serviceResult -} - -// DeleteResult is the response from a Delete request. Call its ExtractErr -// method to interpret it as a Service. -type DeleteResult struct { - golangsdk.ErrResult -} - -// Service represents an OpenStack Service. -type Service struct { - // ID is the unique ID of the service. - ID string `json:"id"` - - // Type is the type of the service. - Type string `json:"type"` - - // Enabled is whether or not the service is enabled. - Enabled bool `json:"enabled"` - - // Links contains referencing links to the service. - Links map[string]interface{} `json:"links"` - - // Extra is a collection of miscellaneous key/values. - Extra map[string]interface{} `json:"-"` -} - -func (r *Service) UnmarshalJSON(b []byte) error { - type tmp Service - var s struct { - tmp - Extra map[string]interface{} `json:"extra"` - } - err := json.Unmarshal(b, &s) - if err != nil { - return err - } - *r = Service(s.tmp) - - // Collect other fields and bundle them into Extra - // but only if a field titled "extra" wasn't sent. - if s.Extra != nil { - r.Extra = s.Extra - } else { - var result interface{} - err := json.Unmarshal(b, &result) - if err != nil { - return err - } - if resultMap, ok := result.(map[string]interface{}); ok { - r.Extra = internal.RemainingKeys(Service{}, resultMap) - } - } - - return err -} - -// ServicePage is a single page of Service results. -type ServicePage struct { - pagination.LinkedPageBase -} - -// IsEmpty returns true if the ServicePage contains no results. -func (p ServicePage) IsEmpty() (bool, error) { - services, err := ExtractServices(p) - return len(services) == 0, err -} - -// NextPageURL extracts the "next" link from the links section of the result. -func (r ServicePage) NextPageURL() (string, error) { - var s struct { - Links struct { - Next string `json:"next"` - Previous string `json:"previous"` - } `json:"links"` - } - err := r.ExtractInto(&s) - if err != nil { - return "", err - } - return s.Links.Next, err -} - -// ExtractServices extracts a slice of Services from a Collection acquired -// from List. -func ExtractServices(r pagination.Page) ([]Service, error) { - var s struct { - Services []Service `json:"services"` - } - err := (r.(ServicePage)).ExtractInto(&s) - return s.Services, err -} diff --git a/vendor/github.com/huaweicloud/golangsdk/openstack/identity/v3/services/urls.go b/vendor/github.com/huaweicloud/golangsdk/openstack/identity/v3/services/urls.go deleted file mode 100644 index f2b2e84e727..00000000000 --- a/vendor/github.com/huaweicloud/golangsdk/openstack/identity/v3/services/urls.go +++ /dev/null @@ -1,19 +0,0 @@ -package services - -import "github.com/huaweicloud/golangsdk" - -func listURL(client *golangsdk.ServiceClient) string { - return client.ServiceURL("services") -} - -func createURL(client *golangsdk.ServiceClient) string { - return client.ServiceURL("services") -} - -func serviceURL(client *golangsdk.ServiceClient, serviceID string) string { - return client.ServiceURL("services", serviceID) -} - -func updateURL(client *golangsdk.ServiceClient, serviceID string) string { - return client.ServiceURL("services", serviceID) -} diff --git a/vendor/github.com/huaweicloud/golangsdk/openstack/taurusdb/v3/instances/requests.go b/vendor/github.com/huaweicloud/golangsdk/openstack/taurusdb/v3/instances/requests.go index 584e0ac49b7..b8f1896cebd 100644 --- a/vendor/github.com/huaweicloud/golangsdk/openstack/taurusdb/v3/instances/requests.go +++ b/vendor/github.com/huaweicloud/golangsdk/openstack/taurusdb/v3/instances/requests.go @@ -38,7 +38,7 @@ type CreateTaurusDBOpts struct { ConfigurationId string `json:"configuration_id,omitempty"` EnterpriseProjectId string `json:"enterprise_project_id,omitempty"` DataStore DataStoreOpt `json:"datastore" required:"true"` - BackupStrategy *BackupStrategyOpt `json:"backup_strategy" required:"true"` + BackupStrategy *BackupStrategyOpt `json:"backup_strategy,omitempty"` ChargeInfo *ChargeInfoOpt `json:"charge_info,omitempty"` } diff --git a/vendor/modules.txt b/vendor/modules.txt index 14f517283a0..c8c04cd8ce9 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-20200827051055-27c9c7b6b988 ## 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 @@ -253,12 +254,11 @@ github.com/huaweicloud/golangsdk/openstack/geminidb/v3/instances github.com/huaweicloud/golangsdk/openstack/identity/v2/tenants github.com/huaweicloud/golangsdk/openstack/identity/v2/tokens github.com/huaweicloud/golangsdk/openstack/identity/v3/agency +github.com/huaweicloud/golangsdk/openstack/identity/v3/catalog github.com/huaweicloud/golangsdk/openstack/identity/v3/domains -github.com/huaweicloud/golangsdk/openstack/identity/v3/endpoints github.com/huaweicloud/golangsdk/openstack/identity/v3/groups github.com/huaweicloud/golangsdk/openstack/identity/v3/projects github.com/huaweicloud/golangsdk/openstack/identity/v3/roles -github.com/huaweicloud/golangsdk/openstack/identity/v3/services github.com/huaweicloud/golangsdk/openstack/identity/v3/tokens github.com/huaweicloud/golangsdk/openstack/identity/v3/users github.com/huaweicloud/golangsdk/openstack/imageservice/v2/imagedata diff --git a/website/docs/r/cce_addon.html.markdown b/website/docs/r/cce_addon.html.markdown new file mode 100644 index 00000000000..dc9fb64e5dd --- /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. +--- + +## Example Usage +```hcl +variable "cluster_id" { } + +resource "huaweicloud_cce_addon" "addon_test" { + cluster_id = var.cluster_id + template_name = "metrics-server" + 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. +* `template_name` - (Required) Name of the addon template. Changing this parameter will create a new resource. +* `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. + + * `status` - Addon status information. + + * `description` - Description of addon instance. + + * `kind` - The instance kind. + + * `api_version` - The API version. \ 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 @@
  • huaweicloud_cce_node
  • +
  • + huaweicloud_cce_addon +