diff --git a/docs/resources/cce_cluster.md b/docs/resources/cce_cluster.md index 1aab752d3b..e678f4bd28 100644 --- a/docs/resources/cce_cluster.md +++ b/docs/resources/cce_cluster.md @@ -141,6 +141,8 @@ versions are available, choose Dashboard > Buy Cluster on the CCE console. Chang - iptables: Traditional kube-proxy uses iptables rules to implement service load balancing. In this mode, too many iptables rules will be generated when many services are deployed. In addition, non-incremental updates will cause a latency and even obvious performance issues in the case of heavy service traffic. - ipvs: Optimized kube-proxy mode with higher throughput and faster speed. This mode supports incremental updates and can keep connections uninterrupted during service updates. It is suitable for large-sized clusters. +* `enterprise_project_id` - (Optional) The enterprise project id of the cce cluster. Changing this creates a new cluster. + ## Attributes Reference All above argument parameters can be exported as attribute parameters along with attribute reference. diff --git a/docs/resources/obs_bucket.md b/docs/resources/obs_bucket.md index cebb38d5a4..e613eb246a 100644 --- a/docs/resources/obs_bucket.md +++ b/docs/resources/obs_bucket.md @@ -254,6 +254,8 @@ The `noncurrent_version_transition` object supports the following * `days` (Required) Specifies the number of days when noncurrent object versions are automatically transitioned to the specified storage class. * `storage_class` - (Required) The class of storage used to store the object. Only `WARM` and `COLD` are supported. +* `enterprise_project_id` - (Optional) The enterprise project id of the OBS bucket. Changing this creates a OBS bucket. + ## Attributes Reference The following attributes are exported: diff --git a/docs/resources/rds_instance.md b/docs/resources/rds_instance.md index f4eee1a48c..24237a2404 100644 --- a/docs/resources/rds_instance.md +++ b/docs/resources/rds_instance.md @@ -171,6 +171,10 @@ The following arguments are supported: (Optional) Specifies the parameter group ID. Changing this parameter will create a new resource. +* `enterprise_project_id` - + (Optional) + The enterprise project id of the RDS. Changing this creates a new RDS. + The `db` block supports: * `password` - diff --git a/docs/resources/sfs_file_system.md b/docs/resources/sfs_file_system.md index 6e20c63445..3723362f05 100644 --- a/docs/resources/sfs_file_system.md +++ b/docs/resources/sfs_file_system.md @@ -47,6 +47,8 @@ The following arguments are supported: * `access_type` - (Optional) Specifies the type of the share access rule. The default value is *cert*. Changing this will create a new access rule. +* `enterprise_project_id` - (Optional) The enterprise project id of the SFS. Changing this creates a new SFS. + * `access_to` - (Optional) Specifies the value that defines the access rule. The value contains 1 to 255 characters. Changing this will create a new access rule. The value varies according to the scenario: - Set the VPC ID in VPC authorization scenarios. diff --git a/docs/resources/vpc.md b/docs/resources/vpc.md index 8f812569b9..277608a3e1 100644 --- a/docs/resources/vpc.md +++ b/docs/resources/vpc.md @@ -45,6 +45,8 @@ The following arguments are supported: * `tags` - (Optional) The key/value pairs to associate with the vpc. +* `enterprise_project_id` - (Optional) The enterprise project id of the vpc. Changing this creates a new vpc. + ## Attributes Reference The following attributes are exported: diff --git a/docs/resources/vpc_eip.md b/docs/resources/vpc_eip.md index f3f426ddf4..74faa7584a 100644 --- a/docs/resources/vpc_eip.md +++ b/docs/resources/vpc_eip.md @@ -50,6 +50,8 @@ The following arguments are supported: * `bandwidth` - (Required) The bandwidth object. +* `enterprise_project_id` - (Optional) The enterprise project id of the elastic IP. Changing this creates a new eip. + The `publicip` block supports: diff --git a/huaweicloud/resource_huaweicloud_cce_cluster_v3.go b/huaweicloud/resource_huaweicloud_cce_cluster_v3.go index 1568487032..7ef4757c69 100644 --- a/huaweicloud/resource_huaweicloud_cce_cluster_v3.go +++ b/huaweicloud/resource_huaweicloud_cce_cluster_v3.go @@ -139,6 +139,12 @@ func resourceCCEClusterV3() *schema.Resource { Optional: true, ForceNew: true, }, + "enterprise_project_id": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + Computed: true, + }, "status": { Type: schema.TypeString, Computed: true, @@ -209,7 +215,7 @@ func resourceClusterAnnotationsV3(d *schema.ResourceData) map[string]string { } return m } -func resourceClusterExtendParamV3(d *schema.ResourceData) map[string]string { +func resourceClusterExtendParamV3(d *schema.ResourceData, config *Config) map[string]string { m := make(map[string]string) for key, val := range d.Get("extend_param").(map[string]interface{}) { m[key] = val.(string) @@ -223,6 +229,12 @@ func resourceClusterExtendParamV3(d *schema.ResourceData) map[string]string { if eip, ok := d.GetOk("eip"); ok { m["clusterExternalIP"] = eip.(string) } + + epsID := GetEnterpriseProjectID(d, config) + + if epsID != "" { + m["enterpriseProjectId"] = epsID + } return m } @@ -263,7 +275,7 @@ func resourceCCEClusterV3Create(d *schema.ResourceData, meta interface{}) error AuthenticatingProxy: authenticating_proxy, }, BillingMode: d.Get("billing_mode").(int), - ExtendParam: resourceClusterExtendParamV3(d), + ExtendParam: resourceClusterExtendParamV3(d, config), }, } @@ -326,6 +338,7 @@ func resourceCCEClusterV3Read(d *schema.ResourceData, meta interface{}) error { d.Set("authentication_mode", n.Spec.Authentication.Mode) d.Set("security_group_id", n.Spec.HostNetwork.SecurityGroup) d.Set("region", GetRegion(d, config)) + d.Set("enterprise_project_id", n.Spec.ExtendParam["enterpriseProjectId"]) r := clusters.GetCert(cceClient, d.Id()) diff --git a/huaweicloud/resource_huaweicloud_cce_cluster_v3_test.go b/huaweicloud/resource_huaweicloud_cce_cluster_v3_test.go index 3766077682..fbd5327123 100644 --- a/huaweicloud/resource_huaweicloud_cce_cluster_v3_test.go +++ b/huaweicloud/resource_huaweicloud_cce_cluster_v3_test.go @@ -79,6 +79,28 @@ func TestAccCCEClusterV3_withEip(t *testing.T) { }) } +func TestAccCCEClusterV3_withEpsId(t *testing.T) { + var cluster clusters.Clusters + + rName := fmt.Sprintf("tf-acc-test-%s", acctest.RandString(5)) + resourceName := "huaweicloud_cce_cluster.test" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheckEpsID(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckCCEClusterV3Destroy, + Steps: []resource.TestStep{ + { + Config: testAccCCEClusterV3_withEpsId(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckCCEClusterV3Exists(resourceName, &cluster), + resource.TestCheckResourceAttr(resourceName, "enterprise_project_id", OS_ENTERPRISE_PROJECT_ID), + ), + }, + }, + }) +} + func testAccCheckCCEClusterV3Destroy(s *terraform.State) error { config := testAccProvider.Meta().(*Config) cceClient, err := config.cceV3Client(OS_REGION_NAME) @@ -209,3 +231,19 @@ resource "huaweicloud_cce_cluster_v3" "test" { } `, testAccCCEClusterV3_Base(rName), rName) } + +func testAccCCEClusterV3_withEpsId(rName string) string { + return fmt.Sprintf(` +%s + +resource "huaweicloud_cce_cluster" "test" { + name = "%s" + flavor_id = "cce.s1.small" + vpc_id = huaweicloud_vpc_v1.test.id + subnet_id = huaweicloud_vpc_subnet_v1.test.id + container_network_type = "overlay_l2" + enterprise_project_id = "%s" +} + +`, testAccCCEClusterV3_Base(rName), rName, OS_ENTERPRISE_PROJECT_ID) +} diff --git a/huaweicloud/resource_huaweicloud_obs_bucket.go b/huaweicloud/resource_huaweicloud_obs_bucket.go index a1af733f1e..0e01d10219 100644 --- a/huaweicloud/resource_huaweicloud_obs_bucket.go +++ b/huaweicloud/resource_huaweicloud_obs_bucket.go @@ -266,6 +266,13 @@ func resourceObsBucket() *schema.Resource { Computed: true, }, + "enterprise_project_id": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + Computed: true, + }, + "bucket_domain_name": { Type: schema.TypeString, Computed: true, @@ -289,6 +296,7 @@ func resourceObsBucketCreate(d *schema.ResourceData, meta interface{}) error { Bucket: bucket, ACL: obs.AclType(acl), StorageClass: obs.StorageClassType(class), + Epid: GetEnterpriseProjectID(d, config), } opts.Location = region log.Printf("[DEBUG] OBS bucket create opts: %#v", opts) @@ -415,6 +423,11 @@ func resourceObsBucketRead(d *schema.ResourceData, meta interface{}) error { return err } + // Read enterprise project id + if err := setObsBucketEnterpriseProjectID(obsClient, d); err != nil { + return err + } + // Read the versioning if err := setObsBucketVersioning(obsClient, d); err != nil { return err @@ -910,6 +923,23 @@ func setObsBucketStorageClass(obsClient *obs.ObsClient, d *schema.ResourceData) return nil } +func setObsBucketEnterpriseProjectID(obsClient *obs.ObsClient, d *schema.ResourceData) error { + bucket := d.Id() + input := &obs.GetBucketMetadataInput{ + Bucket: bucket, + } + output, err := obsClient.GetBucketMetadata(input) + if err != nil { + return getObsError("Error getting metadata of OBS bucket", bucket, err) + } + + epsId := string(output.Epid) + log.Printf("[DEBUG] getting enterprise project id of OBS bucket %s: %s", bucket, epsId) + d.Set("enterprise_project_id", epsId) + + return nil +} + func setObsBucketPolicy(obsClient *obs.ObsClient, d *schema.ResourceData) error { bucket := d.Id() output, err := obsClient.GetBucketPolicy(bucket) diff --git a/huaweicloud/resource_huaweicloud_obs_bucket_test.go b/huaweicloud/resource_huaweicloud_obs_bucket_test.go index 05993c47fb..ff9e7ed851 100644 --- a/huaweicloud/resource_huaweicloud_obs_bucket_test.go +++ b/huaweicloud/resource_huaweicloud_obs_bucket_test.go @@ -48,6 +48,29 @@ func TestAccObsBucket_basic(t *testing.T) { }) } +func TestAccObsBucket_withEpsId(t *testing.T) { + rInt := acctest.RandInt() + resourceName := "huaweicloud_obs_bucket.bucket" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheckEpsID(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckObsBucketDestroy, + Steps: []resource.TestStep{ + { + Config: testAccObsBucket_epsId(rInt), + Check: resource.ComposeTestCheckFunc( + testAccCheckObsBucketExists(resourceName), + resource.TestCheckResourceAttr( + resourceName, "bucket", testAccObsBucketName(rInt)), + resource.TestCheckResourceAttr( + resourceName, "enterprise_project_id", OS_ENTERPRISE_PROJECT_ID), + ), + }, + }, + }) +} + func TestAccObsBucket_tags(t *testing.T) { rInt := acctest.RandInt() resourceName := "huaweicloud_obs_bucket.bucket" @@ -337,6 +360,17 @@ resource "huaweicloud_obs_bucket" "bucket" { `, randInt) } +func testAccObsBucket_epsId(randInt int) string { + return fmt.Sprintf(` +resource "huaweicloud_obs_bucket" "bucket" { + bucket = "tf-test-bucket-%d" + storage_class = "STANDARD" + acl = "private" + enterprise_project_id = "%s" +} +`, randInt, OS_ENTERPRISE_PROJECT_ID) +} + func testAccObsBucket_basic_update(randInt int) string { return fmt.Sprintf(` resource "huaweicloud_obs_bucket" "bucket" { diff --git a/huaweicloud/resource_huaweicloud_rds_instance_v3.go b/huaweicloud/resource_huaweicloud_rds_instance_v3.go index 5c291344a2..79670c35d6 100644 --- a/huaweicloud/resource_huaweicloud_rds_instance_v3.go +++ b/huaweicloud/resource_huaweicloud_rds_instance_v3.go @@ -172,6 +172,13 @@ func resourceRdsInstanceV3() *schema.Resource { }, }, + "enterprise_project_id": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + Computed: true, + }, + "ha_replication_mode": { Type: schema.TypeString, Computed: true, @@ -264,6 +271,7 @@ func resourceRdsInstanceV3Create(d *schema.ResourceData, meta interface{}) error opts := resourceRdsInstanceV3UserInputParams(d) opts["region"] = GetRegion(d, config) + opts["enterprise_project_id"] = GetEnterpriseProjectID(d, config) arrayIndex := map[string]int{ "backup_strategy": 0, @@ -559,6 +567,16 @@ func buildRdsInstanceV3CreateParameters(opts map[string]interface{}, arrayIndex params["configuration_id"] = v } + v, err = navigateValue(opts, []string{"enterprise_project_id"}, arrayIndex) + if err != nil { + return nil, err + } + if e, err := isEmptyValue(reflect.ValueOf(v)); err != nil { + return nil, err + } else if !e { + params["enterprise_project_id"] = v + } + v, err = expandRdsInstanceV3CreateDatastore(opts, arrayIndex) if err != nil { return nil, err @@ -963,6 +981,14 @@ func setRdsInstanceV3Properties(d *schema.ResourceData, response map[string]inte return fmt.Errorf("Error setting Instance:created, err: %s", err) } + v, err = navigateValue(response, []string{"list", "enterprise_project_id"}, nil) + if err != nil { + return fmt.Errorf("Error reading Instance:enterprise_project_id, err: %s", err) + } + if err = d.Set("enterprise_project_id", v); err != nil { + return fmt.Errorf("Error setting Instance:enterprise_project_id, err: %s", err) + } + v, _ = opts["db"] v, err = flattenRdsInstanceV3Db(response, nil, v) if err != nil { diff --git a/huaweicloud/resource_huaweicloud_rds_instance_v3_test.go b/huaweicloud/resource_huaweicloud_rds_instance_v3_test.go index 47e2d3664e..49f8a2593b 100644 --- a/huaweicloud/resource_huaweicloud_rds_instance_v3_test.go +++ b/huaweicloud/resource_huaweicloud_rds_instance_v3_test.go @@ -56,8 +56,45 @@ func TestAccRdsInstanceV3_basic(t *testing.T) { }) } +func TestAccRdsInstanceV3_withEpsId(t *testing.T) { + name := acctest.RandString(10) + resourceName := "huaweicloud_rds_instance_v3.instance" + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheckEpsID(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckRdsInstanceV3Destroy, + Steps: []resource.TestStep{ + { + Config: testAccRdsInstanceV3_epsId(name), + Check: resource.ComposeTestCheckFunc( + testAccCheckRdsInstanceV3Exists(), + resource.TestCheckResourceAttr(resourceName, "enterprise_project_id", OS_ENTERPRISE_PROJECT_ID), + ), + }, + }, + }) +} + func testAccRdsInstanceV3_basic(val string) string { return fmt.Sprintf(` +resource "huaweicloud_vpc" "test" { + name = "vps-rds-test" + cidr = "192.168.0.0/16" +} + +resource "huaweicloud_vpc_subnet" "test" { + name = "subnet-rds-test" + cidr = "192.168.0.0/16" + gateway_ip = "192.168.0.1" + primary_dns = "100.125.1.250" + secondary_dns = "100.125.21.250" + vpc_id = huaweicloud_vpc.test.id +} + +resource "huaweicloud_networking_secgroup" "secgroup_1" { + name = "sg-rds-test" +} + resource "huaweicloud_rds_instance_v3" "instance" { availability_zone = ["%s"] db { @@ -67,9 +104,9 @@ resource "huaweicloud_rds_instance_v3" "instance" { port = "8635" } name = "terraform_test_rds_instance%s" - security_group_id = "3b5ceb06-3b8d-43ee-866a-dc0443b85de8" - subnet_id = "%s" - vpc_id = "%s" + security_group_id = huaweicloud_networking_secgroup.secgroup_1.id + subnet_id = huaweicloud_vpc_subnet.test.id + vpc_id = huaweicloud_vpc.test.id volume { type = "ULTRAHIGH" size = 50 @@ -80,7 +117,7 @@ resource "huaweicloud_rds_instance_v3" "instance" { keep_days = 1 } } - `, OS_AVAILABILITY_ZONE, val, OS_NETWORK_ID, OS_VPC_ID) + `, OS_AVAILABILITY_ZONE, val) } func testAccRdsInstanceV3_update(val string) string { @@ -110,6 +147,53 @@ resource "huaweicloud_rds_instance_v3" "instance" { `, OS_AVAILABILITY_ZONE, val, OS_NETWORK_ID, OS_VPC_ID) } +func testAccRdsInstanceV3_epsId(val string) string { + return fmt.Sprintf(` +resource "huaweicloud_vpc_v1" "test" { + name = "vps-rds-test" + cidr = "192.168.0.0/16" +} + +resource "huaweicloud_vpc_subnet_v1" "test" { + name = "subnet-rds-test" + cidr = "192.168.0.0/16" + gateway_ip = "192.168.0.1" + primary_dns = "100.125.1.250" + secondary_dns = "100.125.21.250" + vpc_id = huaweicloud_vpc_v1.test.id +} + +resource "huaweicloud_networking_secgroup_v2" "secgroup_1" { + name = "sg-rds-test" +} + +resource "huaweicloud_rds_instance_v3" "instance" { + availability_zone = ["%s"] + db { + password = "Huangwei!120521" + type = "PostgreSQL" + version = "10" + port = "8635" + } + name = "terraform_test_rds_instance%s" + security_group_id = huaweicloud_networking_secgroup_v2.secgroup_1.id + subnet_id = huaweicloud_vpc_subnet_v1.test.id + vpc_id = huaweicloud_vpc_v1.test.id + volume { + type = "ULTRAHIGH" + size = 50 + } + flavor = "rds.pg.c2.medium" + backup_strategy { + start_time = "08:00-09:00" + keep_days = 1 + } + enterprise_project_id = "%s" + +} + `, OS_AVAILABILITY_ZONE, val, OS_ENTERPRISE_PROJECT_ID) +} + func testAccCheckRdsInstanceV3Destroy(s *terraform.State) error { config := testAccProvider.Meta().(*Config) client, err := config.sdkClient(OS_REGION_NAME, "rdsv3", serviceProjectLevel) diff --git a/huaweicloud/resource_huaweicloud_sfs_file_system_v2.go b/huaweicloud/resource_huaweicloud_sfs_file_system_v2.go index 37dc54f73f..8f3740cca0 100644 --- a/huaweicloud/resource_huaweicloud_sfs_file_system_v2.go +++ b/huaweicloud/resource_huaweicloud_sfs_file_system_v2.go @@ -83,6 +83,12 @@ func resourceSFSFileSystemV2() *schema.Resource { Type: schema.TypeString, Optional: true, }, + "enterprise_project_id": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + Computed: true, + }, "share_access_id": { Type: schema.TypeString, Computed: true, @@ -149,7 +155,7 @@ func resourceSFSFileSystemV2Create(d *schema.ResourceData, meta interface{}) err Name: d.Get("name").(string), Description: d.Get("description").(string), IsPublic: d.Get("is_public").(bool), - Metadata: resourceSFSMetadataV2(d), + Metadata: resourceSFSMetadataV2(d, config), AvailabilityZone: d.Get("availability_zone").(string), } @@ -223,6 +229,7 @@ func resourceSFSFileSystemV2Read(d *schema.ResourceData, meta interface{}) error d.Set("region", GetRegion(d, config)) d.Set("export_location", n.ExportLocation) d.Set("host", n.Host) + d.Set("enterprise_project_id", n.Metadata["enterprise_project_id"]) // NOTE: This tries to remove system metadata. md := make(map[string]string) @@ -427,10 +434,17 @@ func waitForSFSFileDelete(sfsClient *golangsdk.ServiceClient, shareId string) re } } -func resourceSFSMetadataV2(d *schema.ResourceData) map[string]string { +func resourceSFSMetadataV2(d *schema.ResourceData, config *Config) map[string]string { m := make(map[string]string) for key, val := range d.Get("metadata").(map[string]interface{}) { m[key] = val.(string) } + + epsID := GetEnterpriseProjectID(d, config) + + if epsID != "" { + m["enterprise_project_id"] = epsID + } + return m } diff --git a/huaweicloud/resource_huaweicloud_sfs_file_system_v2_test.go b/huaweicloud/resource_huaweicloud_sfs_file_system_v2_test.go index 1c283a056a..d709c3fa00 100644 --- a/huaweicloud/resource_huaweicloud_sfs_file_system_v2_test.go +++ b/huaweicloud/resource_huaweicloud_sfs_file_system_v2_test.go @@ -62,6 +62,28 @@ func TestAccSFSFileSystemV2_basic(t *testing.T) { }) } +func TestAccSFSFileSystemV2_withEpsId(t *testing.T) { + var share shares.Share + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheckEpsID(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckSFSFileSystemV2Destroy, + Steps: []resource.TestStep{ + { + Config: testAccSFSFileSystemV2_epsId, + Check: resource.ComposeTestCheckFunc( + testAccCheckSFSFileSystemV2Exists("huaweicloud_sfs_file_system_v2.sfs_1", &share), + resource.TestCheckResourceAttr( + "huaweicloud_sfs_file_system_v2.sfs_1", "name", "sfs-test1"), + resource.TestCheckResourceAttr( + "huaweicloud_sfs_file_system_v2.sfs_1", "enterprise_project_id", OS_ENTERPRISE_PROJECT_ID), + ), + }, + }, + }) +} + func TestAccSFSFileSystemV2_without_rule(t *testing.T) { var share shares.Share @@ -172,6 +194,20 @@ resource "huaweicloud_sfs_file_system_v2" "sfs_1" { } `, OS_VPC_ID, OS_AVAILABILITY_ZONE) +var testAccSFSFileSystemV2_epsId = fmt.Sprintf(` +resource "huaweicloud_sfs_file_system_v2" "sfs_1" { + share_proto = "NFS" + size = 10 + name = "sfs-test1" + description = "sfs_c2c_test-file" + access_to = "%s" + access_type = "cert" + access_level = "rw" + availability_zone = "%s" + enterprise_project_id = "%s" +} +`, OS_VPC_ID, OS_AVAILABILITY_ZONE, OS_ENTERPRISE_PROJECT_ID) + var testAccSFSFileSystemV2_update = fmt.Sprintf(` resource "huaweicloud_sfs_file_system_v2" "sfs_1" { share_proto = "NFS" diff --git a/huaweicloud/resource_huaweicloud_vpc_test.go b/huaweicloud/resource_huaweicloud_vpc_test.go index 73bb93c2bd..2fa058cf0e 100644 --- a/huaweicloud/resource_huaweicloud_vpc_test.go +++ b/huaweicloud/resource_huaweicloud_vpc_test.go @@ -64,7 +64,7 @@ func TestAccVpcV1_WithEpsId(t *testing.T) { CheckDestroy: testAccCheckVpcV1Destroy, Steps: []resource.TestStep{ { - Config: testAccVpcV1_basic(rName), + Config: testAccVpcV1_epsId(rName), Check: resource.ComposeTestCheckFunc( testAccCheckVpcV1Exists(resourceName, &vpc), resource.TestCheckResourceAttr(resourceName, "name", rName),