From 111a8a22e5f420976567d1e0f3f76332d6e825b2 Mon Sep 17 00:00:00 2001 From: Thiery Ouattara Date: Wed, 11 Dec 2024 14:17:16 +0000 Subject: [PATCH 1/9] Add functions/variables for EIM resouces and somes refactoring --- ...data_source_outscale_load_balancer_test.go | 14 ++++---- ..._outscale_load_balancer_attributes_test.go | 13 ++++--- utils/utils.go | 36 ++++++++++++------- 3 files changed, 39 insertions(+), 24 deletions(-) diff --git a/outscale/data_source_outscale_load_balancer_test.go b/outscale/data_source_outscale_load_balancer_test.go index 47ccd16f6..7167f9efa 100644 --- a/outscale/data_source_outscale_load_balancer_test.go +++ b/outscale/data_source_outscale_load_balancer_test.go @@ -13,14 +13,14 @@ import ( func TestAccOthers_LBU_basic(t *testing.T) { t.Parallel() const ( - MIN_LB_NAME_SUFFIX int = 20 - MAX_LB_NAME_SUFFIX int = 35 + MIN_LB_NAME_SUFFIX int = 1000 + MAX_LB_NAME_SUFFIX int = 5000 ) var conf oscgo.LoadBalancer zone := fmt.Sprintf("%sa", utils.GetRegion()) - number := utils.RandIntRange(MIN_LB_NAME_SUFFIX, MAX_LB_NAME_SUFFIX) + suffix := utils.RandIntRange(MIN_LB_NAME_SUFFIX, MAX_LB_NAME_SUFFIX) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) @@ -30,7 +30,7 @@ func TestAccOthers_LBU_basic(t *testing.T) { CheckDestroy: testAccCheckOutscaleLBUDestroy, Steps: []resource.TestStep{ { - Config: testAccDSOutscaleLBUConfig(zone, number), + Config: testAccDSOutscaleLBUConfig(zone, suffix), Check: resource.ComposeTestCheckFunc( testAccCheckOutscaleLBUExists("outscale_load_balancer.dataLb", &conf), resource.TestCheckResourceAttr( @@ -42,11 +42,11 @@ func TestAccOthers_LBU_basic(t *testing.T) { }) } -func testAccDSOutscaleLBUConfig(zone string, number int) string { +func testAccDSOutscaleLBUConfig(zone string, suffix int) string { return fmt.Sprintf(` resource "outscale_load_balancer" "dataLb" { subregion_names = ["%s"] - load_balancer_name = "data-terraform-elb-%v" + load_balancer_name = "data-terraform-elb-%d" listeners { backend_port = 8000 @@ -64,5 +64,5 @@ func testAccDSOutscaleLBUConfig(zone string, number int) string { data "outscale_load_balancer" "dataTest" { load_balancer_name = outscale_load_balancer.dataLb.id } -`, zone, number) +`, zone, suffix) } diff --git a/outscale/resource_outscale_load_balancer_attributes_test.go b/outscale/resource_outscale_load_balancer_attributes_test.go index f994bb9fc..c1e929b6d 100644 --- a/outscale/resource_outscale_load_balancer_attributes_test.go +++ b/outscale/resource_outscale_load_balancer_attributes_test.go @@ -14,8 +14,11 @@ import ( func TestAccOthers_LBUAttr_basic(t *testing.T) { t.Parallel() var conf oscgo.AccessLog - - r := utils.RandIntRange(20, 30) + const ( + MIN_LB_NAME_SUFFIX int = 1 + MAX_LB_NAME_SUFFIX int = 1000 + ) + suffix := utils.RandIntRange(MIN_LB_NAME_SUFFIX, MAX_LB_NAME_SUFFIX) resource.Test(t, resource.TestCase{ PreCheck: func() { @@ -25,7 +28,7 @@ func TestAccOthers_LBUAttr_basic(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccOutscaleLBUAttrConfig(utils.GetRegion(), r), + Config: testAccOutscaleLBUAttrConfig(utils.GetRegion(), suffix), Check: resource.ComposeTestCheckFunc( testAccCheckOutscaleLBUAttrExists("outscale_load_balancer_attributes.bar2", &conf), )}, @@ -48,7 +51,7 @@ func testAccCheckOutscaleLBUAttrExists(n string, res *oscgo.AccessLog) resource. } } -func testAccOutscaleLBUAttrConfig(region string, r int) string { +func testAccOutscaleLBUAttrConfig(region string, suffix int) string { return fmt.Sprintf(` resource "outscale_load_balancer" "barAtt" { subregion_names = ["%sa"] @@ -72,5 +75,5 @@ resource "outscale_load_balancer_attributes" "bar2" { } load_balancer_name = outscale_load_balancer.barAtt.id } -`, region, r) +`, region, suffix) } diff --git a/utils/utils.go b/utils/utils.go index 409888008..8dc31be3a 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -10,6 +10,7 @@ import ( "math/rand" "net/http" "os" + "regexp" "strconv" "time" @@ -23,16 +24,19 @@ import ( // PrintToJSON method helper to debug responses const ( - randMin float32 = 1.0 - randMax float32 = 20.0 - MinPort int = 1 - MaxPort int = 65535 - MinIops int = 100 - MaxIops int = 13000 - DefaultIops int32 = 150 - MaxSize int = 14901 - InvalidState string = "InvalidState" - VolumeIOPSError string = ` + randMin float32 = 1.0 + randMax float32 = 20.0 + MinPort int = 1 + MaxPort int = 65535 + MinIops int = 100 + MaxIops int = 13000 + DefaultIops int32 = 150 + MaxSize int = 14901 + LinkedPolicyNotFound string = "5102" + InvalidState string = "InvalidState" + pathRegex string = "^(/[a-zA-Z0-9/_]+/)" + pathError string = "path must begin and end with '/' and contain only alphanumeric characters and/or '/', '_' characters" + VolumeIOPSError string = ` - The "iops" parameter can only be set if "io1" volume type is created. - "Standard" volume types have a default value of 150 iops. - For "gp2" volume types, iops value depend on your volume size. @@ -288,9 +292,9 @@ func I32toa(i int32) string { } func GetRegion() string { - region := fmt.Sprintf("%s", os.Getenv("OUTSCALE_REGION")) + region := os.Getenv("OUTSCALE_REGION") if region == "" { - region = fmt.Sprintf("%s", os.Getenv("OSC_REGION")) + region = os.Getenv("OSC_REGION") } return region } @@ -332,3 +336,11 @@ func GetEnvVariableValue(envVariables []string) string { } return "" } +func CheckPath(path string) error { + reg := regexp.MustCompile(pathRegex) + + if reg.MatchString(path) || path == "/" { + return nil + } + return fmt.Errorf("invalid path:\n %v", pathError) +} From dc789207ce8d989dbb885f98bd814fc5b4909da2 Mon Sep 17 00:00:00 2001 From: Thiery Ouattara Date: Wed, 11 Dec 2024 15:57:09 +0000 Subject: [PATCH 2/9] Add EIM user resource/datasources and update access_key --- outscale/data_source_outscale_access_key.go | 24 +- outscale/data_source_outscale_access_keys.go | 25 +- outscale/data_source_outscale_user.go | 119 ++++++ outscale/data_source_outscale_user_test.go | 38 ++ outscale/data_source_outscale_users.go | 97 +++++ outscale/data_source_outscale_users_test.go | 34 ++ outscale/resource_outscale_access_key.go | 66 +++- outscale/resource_outscale_user.go | 364 ++++++++++++++++++ outscale/resource_outscale_user_test.go | 78 ++++ ...p1.access_key_datasource_attributes_ok.ref | 6 +- ...p2.access_key_datasource_attributes_ok.ref | 6 +- ...p3.access_key_datasource_attributes_ok.ref | 6 +- ...tep1.access_key_resource_attributes_ok.ref | 3 +- ...tep2.access_key_resource_attributes_ok.ref | 3 +- ...tep3.access_key_resource_attributes_ok.ref | 3 +- ...1.access_keys_datasource_attributes_ok.ref | 3 +- ...2.access_keys_datasource_attributes_ok.ref | 9 +- .../step1.user_resource_attributes_ok.ref | 33 ++ .../step1.user_resource_attributes_ok.tf | 4 + .../step2.user_resource_attributes_ok.ref | 72 ++++ .../step2.user_resource_attributes_ok.tf | 14 + 21 files changed, 958 insertions(+), 49 deletions(-) create mode 100644 outscale/data_source_outscale_user.go create mode 100644 outscale/data_source_outscale_user_test.go create mode 100644 outscale/data_source_outscale_users.go create mode 100644 outscale/data_source_outscale_users_test.go create mode 100644 outscale/resource_outscale_user.go create mode 100644 outscale/resource_outscale_user_test.go create mode 100644 tests/qa_provider_oapi/data/user/TF-01_user_resource_attributes_ok/step1.user_resource_attributes_ok.ref create mode 100644 tests/qa_provider_oapi/data/user/TF-01_user_resource_attributes_ok/step1.user_resource_attributes_ok.tf create mode 100644 tests/qa_provider_oapi/data/user/TF-01_user_resource_attributes_ok/step2.user_resource_attributes_ok.ref create mode 100644 tests/qa_provider_oapi/data/user/TF-01_user_resource_attributes_ok/step2.user_resource_attributes_ok.tf diff --git a/outscale/data_source_outscale_access_key.go b/outscale/data_source_outscale_access_key.go index 80d55c929..f3183bae4 100644 --- a/outscale/data_source_outscale_access_key.go +++ b/outscale/data_source_outscale_access_key.go @@ -19,6 +19,10 @@ func DataSourceOutscaleAccessKey() *schema.Resource { Read: DataSourceOutscaleAccessKeyRead, Schema: map[string]*schema.Schema{ "filter": dataSourceFiltersSchema(), + "user_name": { + Type: schema.TypeString, + Optional: true, + }, "access_key_id": { Type: schema.TypeString, Optional: true, @@ -54,12 +58,14 @@ func DataSourceOutscaleAccessKeyRead(d *schema.ResourceData, meta interface{}) e filters, filtersOk := d.GetOk("filter") accessKeyID, accessKeyOk := d.GetOk("access_key_id") state, stateOk := d.GetOk("state") + userName, userNameOk := d.GetOk("user_name") - if !filtersOk && !accessKeyOk && !stateOk { - return fmt.Errorf("One of filters, access_key_id or state must be assigned") + if !filtersOk && !accessKeyOk && !stateOk && !userNameOk { + return fmt.Errorf("one of filters: access_key_id, state or user_name must be assigned") } filterReq := &oscgo.FiltersAccessKeys{} + if filtersOk { filterReq = buildOutscaleDataSourceAccessKeyFilters(filters.(*schema.Set)) } @@ -69,11 +75,15 @@ func DataSourceOutscaleAccessKeyRead(d *schema.ResourceData, meta interface{}) e if stateOk { filterReq.SetStates([]string{state.(string)}) } - + req := oscgo.ReadAccessKeysRequest{} + req.SetFilters(*filterReq) + if userNameOk { + req.SetUserName(userName.(string)) + } var resp oscgo.ReadAccessKeysResponse - var err error - err = resource.Retry(5*time.Minute, func() *resource.RetryError { - rp, httpResp, err := conn.AccessKeyApi.ReadAccessKeys(context.Background()).ReadAccessKeysRequest(oscgo.ReadAccessKeysRequest{Filters: filterReq}).Execute() + + err := resource.Retry(5*time.Minute, func() *resource.RetryError { + rp, httpResp, err := conn.AccessKeyApi.ReadAccessKeys(context.Background()).ReadAccessKeysRequest(req).Execute() if err != nil { return utils.CheckThrottling(httpResp, err) } @@ -85,7 +95,7 @@ func DataSourceOutscaleAccessKeyRead(d *schema.ResourceData, meta interface{}) e } if len(resp.GetAccessKeys()) == 0 { - return fmt.Errorf("Unable to find Access Key") + return fmt.Errorf("unable to find Access Key") } if len(resp.GetAccessKeys()) > 1 { diff --git a/outscale/data_source_outscale_access_keys.go b/outscale/data_source_outscale_access_keys.go index 0f5cbbd6b..598a9b9e4 100644 --- a/outscale/data_source_outscale_access_keys.go +++ b/outscale/data_source_outscale_access_keys.go @@ -31,6 +31,10 @@ func DataSourceOutscaleAccessKeys() *schema.Resource { ValidateFunc: validation.StringInSlice([]string{"ACTIVE", "INACTIVE"}, false), }, }, + "user_name": { + Type: schema.TypeString, + Optional: true, + }, "access_keys": { Type: schema.TypeList, Computed: true, @@ -73,12 +77,8 @@ func DataSourceOutscaleAccessKeysRead(d *schema.ResourceData, meta interface{}) filters, filtersOk := d.GetOk("filter") accessKeyID, accessKeyOk := d.GetOk("access_key_ids") state, stateOk := d.GetOk("states") - - if !filtersOk && !accessKeyOk && !stateOk { - return fmt.Errorf("One of filters, access_key_ids or states must be assigned") - } - filterReq := &oscgo.FiltersAccessKeys{} + if filtersOk { filterReq = buildOutscaleDataSourceAccessKeyFilters(filters.(*schema.Set)) } @@ -88,13 +88,16 @@ func DataSourceOutscaleAccessKeysRead(d *schema.ResourceData, meta interface{}) if stateOk { filterReq.SetStates(utils.InterfaceSliceToStringSlice(state.([]interface{}))) } + req := oscgo.ReadAccessKeysRequest{ + Filters: filterReq, + } + if userName := d.Get("user_name").(string); userName != "" { + req.SetUserName(userName) + } var resp oscgo.ReadAccessKeysResponse - var err error - err = resource.Retry(5*time.Minute, func() *resource.RetryError { - rp, httpResp, err := conn.AccessKeyApi.ReadAccessKeys(context.Background()).ReadAccessKeysRequest(oscgo.ReadAccessKeysRequest{ - Filters: filterReq, - }).Execute() + err := resource.Retry(5*time.Minute, func() *resource.RetryError { + rp, httpResp, err := conn.AccessKeyApi.ReadAccessKeys(context.Background()).ReadAccessKeysRequest(req).Execute() if err != nil { return utils.CheckThrottling(httpResp, err) } @@ -106,7 +109,7 @@ func DataSourceOutscaleAccessKeysRead(d *schema.ResourceData, meta interface{}) } if len(resp.GetAccessKeys()) == 0 { - return fmt.Errorf("Unable to find Access Keys") + return fmt.Errorf("unable to find Access Keys") } if err := d.Set("access_keys", flattenAccessKeys(resp.GetAccessKeys())); err != nil { diff --git a/outscale/data_source_outscale_user.go b/outscale/data_source_outscale_user.go new file mode 100644 index 000000000..4b3bb884b --- /dev/null +++ b/outscale/data_source_outscale_user.go @@ -0,0 +1,119 @@ +package outscale + +import ( + "context" + "fmt" + "log" + "time" + + oscgo "github.com/outscale/osc-sdk-go/v2" + "github.com/outscale/terraform-provider-outscale/utils" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +func DataSourceUser() *schema.Resource { + return &schema.Resource{ + Read: DataSourceUserRead, + Schema: map[string]*schema.Schema{ + "filter": dataSourceFiltersSchema(), + "user_name": { + Type: schema.TypeString, + Computed: true, + }, + "user_id": { + Type: schema.TypeString, + Computed: true, + }, + "user_email": { + Type: schema.TypeString, + Computed: true, + }, + "path": { + Type: schema.TypeString, + Computed: true, + }, + "creation_date": { + Type: schema.TypeString, + Computed: true, + }, + "last_modification_date": { + Type: schema.TypeString, + Computed: true, + }, + }, + } +} + +func DataSourceUserRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*OutscaleClient).OSCAPI + filters, filtersOk := d.GetOk("filter") + if !filtersOk { + return fmt.Errorf("filters: user_ids must be assigned") + } + req := oscgo.NewReadUsersRequest() + filterReq := buildUsersFilters(filters.(*schema.Set)) + req.SetFilters(*filterReq) + var resp oscgo.ReadUsersResponse + + err := resource.Retry(2*time.Minute, func() *resource.RetryError { + rp, httpResp, err := conn.UserApi.ReadUsers(context.Background()).ReadUsersRequest(*req).Execute() + if err != nil { + return utils.CheckThrottling(httpResp, err) + } + resp = rp + return nil + }) + + if err != nil { + return err + } + users := resp.GetUsers() + d.SetId(resource.UniqueId()) + if len(users) == 0 { + return fmt.Errorf("Unable to find user") + } + if len(users) > 1 { + return fmt.Errorf("Find To many users") + } + + if err := d.Set("user_name", users[0].GetUserName()); err != nil { + return err + } + if err := d.Set("user_email", users[0].GetUserEmail()); err != nil { + return err + } + if err := d.Set("user_id", users[0].GetUserId()); err != nil { + return err + } + if err := d.Set("path", users[0].GetPath()); err != nil { + return err + } + if err := d.Set("creation_date", users[0].GetCreationDate()); err != nil { + return err + } + if err := d.Set("last_modification_date", users[0].GetLastModificationDate()); err != nil { + return err + } + return nil +} + +func buildUsersFilters(set *schema.Set) *oscgo.FiltersUsers { + var filters oscgo.FiltersUsers + for _, v := range set.List() { + m := v.(map[string]interface{}) + var filterValues []string + for _, e := range m["values"].([]interface{}) { + filterValues = append(filterValues, e.(string)) + } + + switch name := m["name"].(string); name { + case "user_ids": + filters.SetUserIds(filterValues) + default: + log.Printf("[Debug] Unknown Filter Name: %s.", name) + } + } + return &filters +} diff --git a/outscale/data_source_outscale_user_test.go b/outscale/data_source_outscale_user_test.go new file mode 100644 index 000000000..cac3a5ad9 --- /dev/null +++ b/outscale/data_source_outscale_user_test.go @@ -0,0 +1,38 @@ +package outscale + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccOthers_data_user_basic(t *testing.T) { + t.Parallel() + resourceName := "data.outscale_user.basicTestUser" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataUserBasicConfig, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet(resourceName, "user_id"), + ), + }, + }, + }) +} + +const testAccDataUserBasicConfig = ` + resource "outscale_user" "basic_dataUser" { + user_name = "ACC_user_data1" + path = "/" + } + data "outscale_user" "basicTestUser" { + filter { + name = "user_ids" + values = [outscale_user.basic_dataUser.user_id] + } + } +` diff --git a/outscale/data_source_outscale_users.go b/outscale/data_source_outscale_users.go new file mode 100644 index 000000000..daa64eac3 --- /dev/null +++ b/outscale/data_source_outscale_users.go @@ -0,0 +1,97 @@ +package outscale + +import ( + "context" + "fmt" + "time" + + oscgo "github.com/outscale/osc-sdk-go/v2" + "github.com/outscale/terraform-provider-outscale/utils" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +func DataSourceUsers() *schema.Resource { + return &schema.Resource{ + Read: DataSourceUsersRead, + Schema: map[string]*schema.Schema{ + "filter": dataSourceFiltersSchema(), + "users": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "user_name": { + Type: schema.TypeString, + Computed: true, + }, + "user_id": { + Type: schema.TypeString, + Computed: true, + }, + "user_email": { + Type: schema.TypeString, + Computed: true, + }, + "path": { + Type: schema.TypeString, + Computed: true, + }, + "creation_date": { + Type: schema.TypeString, + Computed: true, + }, + "last_modification_date": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + }, + } +} + +func DataSourceUsersRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*OutscaleClient).OSCAPI + filters, filtersOk := d.GetOk("filter") + req := oscgo.NewReadUsersRequest() + if filtersOk { + filterReq := buildUsersFilters(filters.(*schema.Set)) + req.SetFilters(*filterReq) + } + var resp oscgo.ReadUsersResponse + + err := resource.Retry(2*time.Minute, func() *resource.RetryError { + rp, httpResp, err := conn.UserApi.ReadUsers(context.Background()).ReadUsersRequest(*req).Execute() + if err != nil { + return utils.CheckThrottling(httpResp, err) + } + resp = rp + return nil + }) + + if err != nil { + return err + } + users := resp.GetUsers() + d.SetId(resource.UniqueId()) + if len(users) == 0 { + return fmt.Errorf("Unable to find users") + } + d.SetId(resource.UniqueId()) + usersToSet := make([]map[string]interface{}, len(users)) + for i, v := range users { + user := make(map[string]interface{}) + + user["user_id"] = v.GetUserId() + user["user_name"] = v.GetUserName() + user["user_email"] = v.GetUserEmail() + user["path"] = v.GetPath() + user["creation_date"] = v.GetCreationDate() + user["last_modification_date"] = v.GetLastModificationDate() + usersToSet[i] = user + } + return d.Set("users", usersToSet) +} diff --git a/outscale/data_source_outscale_users_test.go b/outscale/data_source_outscale_users_test.go new file mode 100644 index 000000000..d9950b824 --- /dev/null +++ b/outscale/data_source_outscale_users_test.go @@ -0,0 +1,34 @@ +package outscale + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccOthers_users_basic(t *testing.T) { + t.Parallel() + resourceName := "data.outscale_users.basicTestUsers" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccOutscaleDataUserBasicConfig, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet(resourceName, "users.#"), + ), + }, + }, + }) +} + +const testAccOutscaleDataUserBasicConfig = ` + resource "outscale_user" "basic_data_users" { + user_name = "ACC_test_data1" + path = "/" + } + data "outscale_users" "basicTestUsers" { + depends_on = [outscale_user.basic_data_users] + }` diff --git a/outscale/resource_outscale_access_key.go b/outscale/resource_outscale_access_key.go index be35dede7..b53031b3b 100644 --- a/outscale/resource_outscale_access_key.go +++ b/outscale/resource_outscale_access_key.go @@ -24,6 +24,11 @@ func ResourceOutscaleAccessKey() *schema.Resource { }, Schema: map[string]*schema.Schema{ + "user_name": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, "access_key_id": { Type: schema.TypeString, Computed: true, @@ -76,6 +81,9 @@ func ResourceOutscaleAccessKeyCreate(d *schema.ResourceData, meta interface{}) e } req.ExpirationDate = &expirDate } + if userName := d.Get("user_name").(string); userName != "" { + req.SetUserName(userName) + } var resp oscgo.CreateAccessKeyResponse err = resource.Retry(5*time.Minute, func() *resource.RetryError { @@ -91,17 +99,14 @@ func ResourceOutscaleAccessKeyCreate(d *schema.ResourceData, meta interface{}) e } d.SetId(*resp.GetAccessKey().AccessKeyId) - if err := d.Set("secret_key", *resp.GetAccessKey().SecretKey); err != nil { return err } - if d.Get("state").(string) != "ACTIVE" { - if err := updateAccessKey(conn, d.Id(), "INACTIVE"); err != nil { + if err := inactiveAccessKey(d, conn, "INACTIVE"); err != nil { return err } } - return ResourceOutscaleAccessKeyRead(d, meta) } @@ -115,7 +120,9 @@ func ResourceOutscaleAccessKeyRead(d *schema.ResourceData, meta interface{}) err req := oscgo.ReadAccessKeysRequest{ Filters: &filter, } - + if userName := d.Get("user_name").(string); userName != "" { + req.SetUserName(userName) + } var resp oscgo.ReadAccessKeysResponse err := resource.Retry(2*time.Minute, func() *resource.RetryError { rp, httpResp, err := conn.AccessKeyApi.ReadAccessKeys(context.Background()).ReadAccessKeysRequest(req).Execute() @@ -135,7 +142,11 @@ func ResourceOutscaleAccessKeyRead(d *schema.ResourceData, meta interface{}) err d.SetId("") return nil } - + if userName := d.Get("user_name").(string); userName != "" { + if err := d.Set("user_name", userName); err != nil { + return err + } + } if err := d.Set("access_key_id", accessKey[0].GetAccessKeyId()); err != nil { return err } @@ -148,7 +159,6 @@ func ResourceOutscaleAccessKeyRead(d *schema.ResourceData, meta interface{}) err if err := d.Set("last_modification_date", accessKey[0].GetLastModificationDate()); err != nil { return err } - if err := d.Set("state", accessKey[0].GetState()); err != nil { return err } @@ -160,9 +170,16 @@ func ResourceOutscaleAccessKeyUpdate(d *schema.ResourceData, meta interface{}) e conn := meta.(*OutscaleClient).OSCAPI req := oscgo.UpdateAccessKeyRequest{AccessKeyId: d.Id()} + if expirDate, newdate := d.GetChange("expiration_date"); newdate.(string) != "" { + req.SetExpirationDate(expirDate.(string)) + } + if userName := d.Get("user_name").(string); userName != "" { + req.SetUserName(userName) + } if d.HasChange("state") { req.State = d.Get("state").(string) } + if d.HasChange("expiration_date") { newExpirDate := d.Get("expiration_date").(string) state := d.Get("state").(string) @@ -170,11 +187,18 @@ func ResourceOutscaleAccessKeyUpdate(d *schema.ResourceData, meta interface{}) e if err := checkDateFormat(newExpirDate); err != nil { return err } - req.ExpirationDate = &newExpirDate + req.SetExpirationDate(newExpirDate) + } else { + if !req.HasUserName() { + if userName := d.Get("user_name").(string); userName != "" { + req.SetUserName(userName) + } + } + } + if req.State == "" { + req.SetState(state) } - req.State = state } - err := resource.Retry(2*time.Minute, func() *resource.RetryError { _, httpResp, err := conn.AccessKeyApi.UpdateAccessKey(context.Background()).UpdateAccessKeyRequest(req).Execute() if err != nil { @@ -194,9 +218,13 @@ func ResourceOutscaleAccessKeyDelete(d *schema.ResourceData, meta interface{}) e req := oscgo.DeleteAccessKeyRequest{ AccessKeyId: d.Id(), } - - var err error - err = resource.Retry(5*time.Minute, func() *resource.RetryError { + if userName := d.Get("user_name").(string); userName != "" { + req.SetUserName(userName) + if err := inactiveAccessKey(d, conn, "INACTIVE"); err != nil { + return err + } + } + err := resource.Retry(5*time.Minute, func() *resource.RetryError { _, httpResp, err := conn.AccessKeyApi.DeleteAccessKey(context.Background()).DeleteAccessKeyRequest(req).Execute() if err != nil { return utils.CheckThrottling(httpResp, err) @@ -204,17 +232,20 @@ func ResourceOutscaleAccessKeyDelete(d *schema.ResourceData, meta interface{}) e return nil }) if err != nil { - return fmt.Errorf("Error deleting Outscale Access Key %s: %s", d.Id(), err) + return fmt.Errorf(" Error deleting Outscale Access Key %s: %s", d.Id(), err) } return nil } -func updateAccessKey(conn *oscgo.APIClient, id, state string) error { +func inactiveAccessKey(d *schema.ResourceData, conn *oscgo.APIClient, state string) error { req := oscgo.UpdateAccessKeyRequest{ - AccessKeyId: id, + AccessKeyId: d.Id(), State: state, } + if userName := d.Get("user_name").(string); userName != "" { + req.SetUserName(userName) + } err := resource.Retry(5*time.Minute, func() *resource.RetryError { _, httpResp, err := conn.AccessKeyApi.UpdateAccessKey(context.Background()).UpdateAccessKeyRequest(req).Execute() if err != nil { @@ -222,7 +253,6 @@ func updateAccessKey(conn *oscgo.APIClient, id, state string) error { } return nil }) - if err != nil { return err } @@ -235,7 +265,7 @@ func checkDateFormat(dateFormat string) error { currentDate := time.Now() if settingDate, err = datetime.Parse(dateFormat, time.UTC); err != nil { - return fmt.Errorf("Expiration Date should be 'ISO 8601' format ('2017-06-14' or '2017-06-14T00:00:00Z, ...) %s", err) + return fmt.Errorf(" Expiration Date should be 'ISO 8601' format ('2017-06-14' or '2017-06-14T00:00:00Z, ...) %s", err) } if currentDate.After(settingDate) { return fmt.Errorf(" Expiration date: '%s' should be after current date '%s'", settingDate, currentDate) diff --git a/outscale/resource_outscale_user.go b/outscale/resource_outscale_user.go new file mode 100644 index 000000000..5140af2ea --- /dev/null +++ b/outscale/resource_outscale_user.go @@ -0,0 +1,364 @@ +package outscale + +import ( + "context" + "fmt" + "log" + "strings" + "time" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + oscgo "github.com/outscale/osc-sdk-go/v2" + "github.com/outscale/terraform-provider-outscale/utils" +) + +func ResourceOutscaleUser() *schema.Resource { + return &schema.Resource{ + Create: ResourceOutscaleUserCreate, + Read: ResourceOutscaleUserRead, + Update: ResourceOutscaleUserUpdate, + Delete: ResourceOutscaleUserDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + + Schema: map[string]*schema.Schema{ + "user_name": { + Type: schema.TypeString, + Required: true, + }, + "path": { + Type: schema.TypeString, + Optional: true, + Default: "/", + ValidateFunc: func(val interface{}, key string) (warns []string, errs []error) { + pathVal := val.(string) + if err := utils.CheckPath(pathVal); err != nil { + errs = append(errs, fmt.Errorf("%v, got:%v", err, pathVal)) + } + return + }, + }, + "user_email": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "user_id": { + Type: schema.TypeString, + Computed: true, + }, + "creation_date": { + Type: schema.TypeString, + Computed: true, + }, + "last_modification_date": { + Type: schema.TypeString, + Computed: true, + }, + "policy": { + Type: schema.TypeSet, + Optional: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "policy_orn": { + Type: schema.TypeString, + Required: true, + }, + "default_version_id": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "policy_name": { + Type: schema.TypeString, + Computed: true, + }, + "policy_id": { + Type: schema.TypeString, + Computed: true, + }, + "creation_date": { + Type: schema.TypeString, + Computed: true, + }, + "last_modification_date": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + }, + } +} + +func ResourceOutscaleUserCreate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*OutscaleClient).OSCAPI + req := oscgo.NewCreateUserRequest(d.Get("user_name").(string)) + req.SetPath(d.Get("path").(string)) + if email := d.Get("user_email").(string); email != "" { + req.SetUserEmail(email) + } + + var resp oscgo.CreateUserResponse + err := resource.Retry(2*time.Minute, func() *resource.RetryError { + rp, httpResp, err := conn.UserApi.CreateUser(context.Background()).CreateUserRequest(*req).Execute() + if err != nil { + return utils.CheckThrottling(httpResp, err) + } + resp = rp + return nil + }) + if err != nil { + return err + } + d.SetId(*resp.GetUser().UserId) + if policiesToAdd, ok := d.GetOk("policy"); ok { + reqAddPolicy := oscgo.LinkPolicyRequest{} + + for _, v := range policiesToAdd.(*schema.Set).List() { + policy := v.(map[string]interface{}) + reqAddPolicy.SetUserName(d.Get("user_name").(string)) + reqAddPolicy.SetPolicyOrn(policy["policy_orn"].(string)) + + err := resource.Retry(2*time.Minute, func() *resource.RetryError { + _, httpResp, err := conn.PolicyApi.LinkPolicy(context.Background()).LinkPolicyRequest(reqAddPolicy).Execute() + if err != nil { + return utils.CheckThrottling(httpResp, err) + } + return nil + }) + if err != nil { + return err + } + if versionId := policy["default_version_id"].(string); versionId != "" { + if err := setDefaultPolicyVersion(conn, policy["policy_orn"].(string), versionId); err != nil { + return err + } + } + } + } + + return ResourceOutscaleUserRead(d, meta) +} + +func ResourceOutscaleUserRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*OutscaleClient).OSCAPI + req := oscgo.ReadUsersRequest{ + Filters: &oscgo.FiltersUsers{UserIds: &[]string{d.Id()}}, + } + + var resp oscgo.ReadUsersResponse + err := resource.Retry(1*time.Minute, func() *resource.RetryError { + rp, httpResp, err := conn.UserApi.ReadUsers(context.Background()).ReadUsersRequest(req).Execute() + if err != nil { + return utils.CheckThrottling(httpResp, err) + } + resp = rp + return nil + }) + if err != nil { + return err + } + users := resp.GetUsers() + if len(users) == 0 { + d.SetId("") + return nil + } + linkReq := oscgo.NewReadLinkedPoliciesRequest(users[0].GetUserName()) + var linkResp oscgo.ReadLinkedPoliciesResponse + err = resource.Retry(2*time.Minute, func() *resource.RetryError { + rp, httpResp, err := conn.PolicyApi.ReadLinkedPolicies(context.Background()).ReadLinkedPoliciesRequest(*linkReq).Execute() + if err != nil { + return utils.CheckThrottling(httpResp, err) + } + linkResp = rp + return nil + }) + if err != nil { + return err + } + + if err := d.Set("user_name", users[0].GetUserName()); err != nil { + return err + } + if err := d.Set("user_id", users[0].GetUserId()); err != nil { + return err + } + if err := d.Set("path", users[0].GetPath()); err != nil { + return err + } + if err := d.Set("user_email", users[0].GetUserEmail()); err != nil { + return err + } + if err := d.Set("creation_date", users[0].GetCreationDate()); err != nil { + return err + } + if err := d.Set("last_modification_date", users[0].GetLastModificationDate()); err != nil { + return err + } + + uPolicies := linkResp.GetPolicies() + policies := make([]map[string]interface{}, len(uPolicies)) + if len(uPolicies) > 0 { + for i, v := range uPolicies { + policy := make(map[string]interface{}) + policy["policy_id"] = v.GetPolicyId() + policy["policy_name"] = v.GetPolicyName() + policy["policy_orn"] = v.GetOrn() + policy["creation_date"] = v.GetCreationDate() + policy["last_modification_date"] = v.GetLastModificationDate() + versionId, err := getPolicyVersion(conn, v.GetOrn()) + if err != nil { + return err + } + policy["default_version_id"] = versionId + + policies[i] = policy + } + } + if err := d.Set("policy", policies); err != nil { + return err + } + return nil +} + +func ResourceOutscaleUserUpdate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*OutscaleClient).OSCAPI + req := oscgo.UpdateUserRequest{UserName: d.Get("user_name").(string)} + isUpdateUser := false + if d.HasChange("user_name") { + oldN, newN := d.GetChange("user_name") + if oldName := oldN.(string); oldName != "" { + req.SetUserName(oldName) + isUpdateUser = true + } + if newName := newN.(string); newName != "" && oldN.(string) != newN.(string) { + req.SetNewUserName(newName) + isUpdateUser = true + } + } + if d.HasChange("path") { + req.SetNewPath(d.Get("path").(string)) + if req.GetUserName() == "" { + req.SetUserName(d.Get("user_name").(string)) + } + isUpdateUser = true + } + if d.HasChange("user_email") { + _, newM := d.GetChange("user_email") + req.SetNewUserEmail(newM.(string)) + isUpdateUser = true + } + if d.HasChange("policy") { + oldPolicies, newPolicies := d.GetChange("policy") + inter := oldPolicies.(*schema.Set).Intersection(newPolicies.(*schema.Set)) + toCreate := newPolicies.(*schema.Set).Difference(inter) + toRemove := oldPolicies.(*schema.Set).Difference(inter) + + if len(toRemove.List()) > 0 { + unlinkReq := oscgo.UnlinkPolicyRequest{} + oldN, _ := d.GetChange("user_name") + unlinkReq.SetUserName(oldN.(string)) + + for _, v := range toRemove.List() { + policy := v.(map[string]interface{}) + unlinkReq.SetPolicyOrn(policy["policy_orn"].(string)) + err := resource.Retry(2*time.Minute, func() *resource.RetryError { + _, httpResp, err := conn.PolicyApi.UnlinkPolicy(context.Background()).UnlinkPolicyRequest(unlinkReq).Execute() + if err != nil { + log.Println("[INFO]: The policy has already been removed") + if strings.Contains(fmt.Sprint(httpResp.Body), utils.LinkedPolicyNotFound) { + return nil + } + return utils.CheckThrottling(httpResp, err) + } + return nil + }) + if err != nil { + return err + } + } + } + if len(toCreate.List()) > 0 { + linkReq := oscgo.LinkPolicyRequest{} + oldN, _ := d.GetChange("user_name") + linkReq.SetUserName(oldN.(string)) + + for _, v := range toCreate.List() { + policy := v.(map[string]interface{}) + linkReq.SetPolicyOrn(policy["policy_orn"].(string)) + + err := resource.Retry(2*time.Minute, func() *resource.RetryError { + _, httpResp, err := conn.PolicyApi.LinkPolicy(context.Background()).LinkPolicyRequest(linkReq).Execute() + if err != nil { + return utils.CheckThrottling(httpResp, err) + } + return nil + }) + if err != nil { + return err + } + if versionId := policy["default_version_id"].(string); versionId != "" { + if err := setDefaultPolicyVersion(conn, policy["policy_orn"].(string), versionId); err != nil { + return err + } + } + } + } + } + if isUpdateUser { + err := resource.Retry(2*time.Minute, func() *resource.RetryError { + _, httpResp, err := conn.UserApi.UpdateUser(context.Background()).UpdateUserRequest(req).Execute() + if err != nil { + return utils.CheckThrottling(httpResp, err) + } + return nil + }) + if err != nil { + return err + } + } + return ResourceOutscaleUserRead(d, meta) +} + +func ResourceOutscaleUserDelete(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*OutscaleClient).OSCAPI + if _, ok := d.GetOk("policy"); ok { + policies := d.Get("policy") + for _, v := range policies.(*schema.Set).List() { + unlinkReq := oscgo.UnlinkPolicyRequest{} + unlinkReq.SetUserName(d.Get("user_name").(string)) + policy := v.(map[string]interface{}) + unlinkReq.SetPolicyOrn(policy["policy_orn"].(string)) + err := resource.Retry(2*time.Minute, func() *resource.RetryError { + _, httpResp, err := conn.PolicyApi.UnlinkPolicy(context.Background()).UnlinkPolicyRequest(unlinkReq).Execute() + if err != nil { + return utils.CheckThrottling(httpResp, err) + } + return nil + }) + if err != nil { + return err + } + } + } + + req := oscgo.DeleteUserRequest{ + UserName: d.Get("user_name").(string), + } + err := resource.Retry(5*time.Minute, func() *resource.RetryError { + _, httpResp, err := conn.UserApi.DeleteUser(context.Background()).DeleteUserRequest(req).Execute() + if err != nil { + return utils.CheckThrottling(httpResp, err) + } + return nil + }) + if err != nil { + return fmt.Errorf("error deleting Outscale user %s: %s", d.Id(), err) + } + + return nil +} diff --git a/outscale/resource_outscale_user_test.go b/outscale/resource_outscale_user_test.go new file mode 100644 index 000000000..f1fe7ce30 --- /dev/null +++ b/outscale/resource_outscale_user_test.go @@ -0,0 +1,78 @@ +package outscale + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccOthers_User_basic(t *testing.T) { + t.Parallel() + resourceName := "outscale_user.basic_user" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccOutscaleUserBasicConfig, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet(resourceName, "user_name"), + resource.TestCheckResourceAttr(resourceName, "path", "/"), + ), + }, + }, + }) +} + +func TestAccOthers_User_update(t *testing.T) { + t.Parallel() + resourceName := "outscale_user.update_user" + name := "TestACC_user1" + newName := "TestACC_user2" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccOutscaleUserUpdatedConfig(name), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet(resourceName, "user_name"), + resource.TestCheckResourceAttr(resourceName, "path", "/"), + resource.TestCheckResourceAttr(resourceName, "user_name", name), + ), + }, + { + Config: testAccOutscaleUserUpdatedConfig(newName), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet(resourceName, "path"), + resource.TestCheckResourceAttrSet(resourceName, "user_name"), + resource.TestCheckResourceAttr(resourceName, "path", "/"), + resource.TestCheckResourceAttr(resourceName, "user_name", newName), + ), + }, + }, + }) +} + +const testAccOutscaleUserBasicConfig = ` + resource "outscale_access_key" "access_key01" { + state = "ACTIVE" + user_name = outscale_user.basic_user.user_name + depends_on = [outscale_user.basic_user] + } + resource "outscale_user" "basic_user" { + user_name = "ACC_test1" + path = "/" + }` + +func testAccOutscaleUserUpdatedConfig(name string) string { + return fmt.Sprintf(` + resource "outscale_user" "update_user" { + user_name = "%s" + path = "/" + } + `, name) +} diff --git a/tests/qa_provider_oapi/data/access_key/TF-55_access_key_datasource_attributes_ok/step1.access_key_datasource_attributes_ok.ref b/tests/qa_provider_oapi/data/access_key/TF-55_access_key_datasource_attributes_ok/step1.access_key_datasource_attributes_ok.ref index f46d1c9e9..e956067bd 100644 --- a/tests/qa_provider_oapi/data/access_key/TF-55_access_key_datasource_attributes_ok/step1.access_key_datasource_attributes_ok.ref +++ b/tests/qa_provider_oapi/data/access_key/TF-55_access_key_datasource_attributes_ok/step1.access_key_datasource_attributes_ok.ref @@ -21,7 +21,8 @@ "id": "##id-0##", "last_modification_date": "########", "request_id": "########", - "state": "ACTIVE" + "state": "ACTIVE", + "user_name": null }, "sensitive_attributes": [] } @@ -43,7 +44,8 @@ "last_modification_date": "########", "request_id": "########", "secret_key": "########", - "state": "ACTIVE" + "state": "ACTIVE", + "user_name": null }, "sensitive_attributes": [], "private": "bnVsbA==" diff --git a/tests/qa_provider_oapi/data/access_key/TF-55_access_key_datasource_attributes_ok/step2.access_key_datasource_attributes_ok.ref b/tests/qa_provider_oapi/data/access_key/TF-55_access_key_datasource_attributes_ok/step2.access_key_datasource_attributes_ok.ref index 6a4f2eb73..2d84a5c4e 100644 --- a/tests/qa_provider_oapi/data/access_key/TF-55_access_key_datasource_attributes_ok/step2.access_key_datasource_attributes_ok.ref +++ b/tests/qa_provider_oapi/data/access_key/TF-55_access_key_datasource_attributes_ok/step2.access_key_datasource_attributes_ok.ref @@ -21,7 +21,8 @@ "id": "##id-0##", "last_modification_date": "########", "request_id": "########", - "state": "INACTIVE" + "state": "INACTIVE", + "user_name": null }, "sensitive_attributes": [] } @@ -43,7 +44,8 @@ "last_modification_date": "########", "request_id": "########", "secret_key": "########", - "state": "INACTIVE" + "state": "INACTIVE", + "user_name": null }, "sensitive_attributes": [], "private": "bnVsbA==" diff --git a/tests/qa_provider_oapi/data/access_key/TF-55_access_key_datasource_attributes_ok/step3.access_key_datasource_attributes_ok.ref b/tests/qa_provider_oapi/data/access_key/TF-55_access_key_datasource_attributes_ok/step3.access_key_datasource_attributes_ok.ref index 6a4f2eb73..2d84a5c4e 100644 --- a/tests/qa_provider_oapi/data/access_key/TF-55_access_key_datasource_attributes_ok/step3.access_key_datasource_attributes_ok.ref +++ b/tests/qa_provider_oapi/data/access_key/TF-55_access_key_datasource_attributes_ok/step3.access_key_datasource_attributes_ok.ref @@ -21,7 +21,8 @@ "id": "##id-0##", "last_modification_date": "########", "request_id": "########", - "state": "INACTIVE" + "state": "INACTIVE", + "user_name": null }, "sensitive_attributes": [] } @@ -43,7 +44,8 @@ "last_modification_date": "########", "request_id": "########", "secret_key": "########", - "state": "INACTIVE" + "state": "INACTIVE", + "user_name": null }, "sensitive_attributes": [], "private": "bnVsbA==" diff --git a/tests/qa_provider_oapi/data/access_key/TF-56_access_key_resource_attributes_ok/step1.access_key_resource_attributes_ok.ref b/tests/qa_provider_oapi/data/access_key/TF-56_access_key_resource_attributes_ok/step1.access_key_resource_attributes_ok.ref index b972d1fac..82100b0cb 100644 --- a/tests/qa_provider_oapi/data/access_key/TF-56_access_key_resource_attributes_ok/step1.access_key_resource_attributes_ok.ref +++ b/tests/qa_provider_oapi/data/access_key/TF-56_access_key_resource_attributes_ok/step1.access_key_resource_attributes_ok.ref @@ -21,7 +21,8 @@ "last_modification_date": "########", "request_id": "########", "secret_key": "########", - "state": "ACTIVE" + "state": "ACTIVE", + "user_name": null }, "sensitive_attributes": [], "private": "bnVsbA==" diff --git a/tests/qa_provider_oapi/data/access_key/TF-56_access_key_resource_attributes_ok/step2.access_key_resource_attributes_ok.ref b/tests/qa_provider_oapi/data/access_key/TF-56_access_key_resource_attributes_ok/step2.access_key_resource_attributes_ok.ref index 46c8633de..51caba8eb 100644 --- a/tests/qa_provider_oapi/data/access_key/TF-56_access_key_resource_attributes_ok/step2.access_key_resource_attributes_ok.ref +++ b/tests/qa_provider_oapi/data/access_key/TF-56_access_key_resource_attributes_ok/step2.access_key_resource_attributes_ok.ref @@ -21,7 +21,8 @@ "last_modification_date": "########", "request_id": "########", "secret_key": "########", - "state": "INACTIVE" + "state": "INACTIVE", + "user_name": null }, "sensitive_attributes": [], "private": "bnVsbA==" diff --git a/tests/qa_provider_oapi/data/access_key/TF-56_access_key_resource_attributes_ok/step3.access_key_resource_attributes_ok.ref b/tests/qa_provider_oapi/data/access_key/TF-56_access_key_resource_attributes_ok/step3.access_key_resource_attributes_ok.ref index b972d1fac..82100b0cb 100644 --- a/tests/qa_provider_oapi/data/access_key/TF-56_access_key_resource_attributes_ok/step3.access_key_resource_attributes_ok.ref +++ b/tests/qa_provider_oapi/data/access_key/TF-56_access_key_resource_attributes_ok/step3.access_key_resource_attributes_ok.ref @@ -21,7 +21,8 @@ "last_modification_date": "########", "request_id": "########", "secret_key": "########", - "state": "ACTIVE" + "state": "ACTIVE", + "user_name": null }, "sensitive_attributes": [], "private": "bnVsbA==" diff --git a/tests/qa_provider_oapi/data/access_keys/TF-57_access_keys_datasource_attributes_ok/step1.access_keys_datasource_attributes_ok.ref b/tests/qa_provider_oapi/data/access_keys/TF-57_access_keys_datasource_attributes_ok/step1.access_keys_datasource_attributes_ok.ref index 08e6df7cb..47ea1f179 100644 --- a/tests/qa_provider_oapi/data/access_keys/TF-57_access_keys_datasource_attributes_ok/step1.access_keys_datasource_attributes_ok.ref +++ b/tests/qa_provider_oapi/data/access_keys/TF-57_access_keys_datasource_attributes_ok/step1.access_keys_datasource_attributes_ok.ref @@ -21,7 +21,8 @@ "last_modification_date": "########", "request_id": "########", "secret_key": "########", - "state": "ACTIVE" + "state": "ACTIVE", + "user_name": null }, "sensitive_attributes": [], "private": "bnVsbA==" diff --git a/tests/qa_provider_oapi/data/access_keys/TF-57_access_keys_datasource_attributes_ok/step2.access_keys_datasource_attributes_ok.ref b/tests/qa_provider_oapi/data/access_keys/TF-57_access_keys_datasource_attributes_ok/step2.access_keys_datasource_attributes_ok.ref index 66786c985..8495fc2d0 100644 --- a/tests/qa_provider_oapi/data/access_keys/TF-57_access_keys_datasource_attributes_ok/step2.access_keys_datasource_attributes_ok.ref +++ b/tests/qa_provider_oapi/data/access_keys/TF-57_access_keys_datasource_attributes_ok/step2.access_keys_datasource_attributes_ok.ref @@ -34,7 +34,8 @@ "filter": "########", "id": "##id-2##", "request_id": "########", - "states": null + "states": null, + "user_name": null }, "sensitive_attributes": [] } @@ -56,7 +57,8 @@ "last_modification_date": "########", "request_id": "########", "secret_key": "########", - "state": "ACTIVE" + "state": "ACTIVE", + "user_name": null }, "sensitive_attributes": [], "private": "bnVsbA==" @@ -79,7 +81,8 @@ "last_modification_date": "########", "request_id": "########", "secret_key": "########", - "state": "ACTIVE" + "state": "ACTIVE", + "user_name": null }, "sensitive_attributes": [], "private": "bnVsbA==" diff --git a/tests/qa_provider_oapi/data/user/TF-01_user_resource_attributes_ok/step1.user_resource_attributes_ok.ref b/tests/qa_provider_oapi/data/user/TF-01_user_resource_attributes_ok/step1.user_resource_attributes_ok.ref new file mode 100644 index 000000000..34b81dc36 --- /dev/null +++ b/tests/qa_provider_oapi/data/user/TF-01_user_resource_attributes_ok/step1.user_resource_attributes_ok.ref @@ -0,0 +1,33 @@ +{ + "version": "########", + "terraform_version": "########", + "serial": "########", + "lineage": "########", + "outputs": {}, + "resources": [ + { + "mode": "managed", + "type": "outscale_user", + "name": "userInteg", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "creation_date": "########", + "id": "##id-0##", + "last_modification_date": "########", + "path": "/", + "policy": [], + "user_email": "customer-tooling@outscale.com", + "user_id": "##id-0##", + "user_name": "test_integ" + }, + "sensitive_attributes": [], + "private": "bnVsbA==" + } + ] + } + ], + "check_results": "########" +} \ No newline at end of file diff --git a/tests/qa_provider_oapi/data/user/TF-01_user_resource_attributes_ok/step1.user_resource_attributes_ok.tf b/tests/qa_provider_oapi/data/user/TF-01_user_resource_attributes_ok/step1.user_resource_attributes_ok.tf new file mode 100644 index 000000000..09b10093f --- /dev/null +++ b/tests/qa_provider_oapi/data/user/TF-01_user_resource_attributes_ok/step1.user_resource_attributes_ok.tf @@ -0,0 +1,4 @@ +resource "outscale_user" "userInteg" { + user_name = "test_integ" + path = "/" +} diff --git a/tests/qa_provider_oapi/data/user/TF-01_user_resource_attributes_ok/step2.user_resource_attributes_ok.ref b/tests/qa_provider_oapi/data/user/TF-01_user_resource_attributes_ok/step2.user_resource_attributes_ok.ref new file mode 100644 index 000000000..b968851c0 --- /dev/null +++ b/tests/qa_provider_oapi/data/user/TF-01_user_resource_attributes_ok/step2.user_resource_attributes_ok.ref @@ -0,0 +1,72 @@ +{ + "version": "########", + "terraform_version": "########", + "serial": "########", + "lineage": "########", + "outputs": {}, + "resources": [ + { + "mode": "managed", + "type": "outscale_policy", + "name": "policy_user01", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "creation_date": "########", + "description": "Example of description", + "document": "{\"Statement\": [ {\"Effect\": \"Allow\", \"Action\": [\"*\"], \"Resource\": [\"*\"]} ]}", + "id": "##id-0##", + "is_linkable": true, + "last_modification_date": "########", + "orn": "########", + "path": "/okht/", + "policy_default_version_id": "##id-1##", + "policy_id": "##id-2##", + "policy_name": "okht-user-policy", + "resources_count": 0 + }, + "sensitive_attributes": [], + "private": "bnVsbA==" + } + ] + }, + { + "mode": "managed", + "type": "outscale_user", + "name": "userInteg", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "creation_date": "########", + "id": "##id-3##", + "last_modification_date": "########", + "path": "/Integ/", + "policy": [ + { + "creation_date": "########", + "default_version_id": "##id-1##", + "last_modification_date": "########", + "policy_id": "##id-2##", + "policy_name": "okht-user-policy", + "policy_orn": "orn:ows:idauth::339215505907:policy/okht/okht-user-policy" + } + ], + "user_email": "customer-tooling@outscale.com", + "user_id": "##id-3##", + "user_name": "test_integ_update" + }, + "sensitive_attributes": [], + "private": "bnVsbA==", + "dependencies": [ + "outscale_policy.policy_user01" + ] + } + ] + } + ], + "check_results": "########" +} \ No newline at end of file diff --git a/tests/qa_provider_oapi/data/user/TF-01_user_resource_attributes_ok/step2.user_resource_attributes_ok.tf b/tests/qa_provider_oapi/data/user/TF-01_user_resource_attributes_ok/step2.user_resource_attributes_ok.tf new file mode 100644 index 000000000..796188299 --- /dev/null +++ b/tests/qa_provider_oapi/data/user/TF-01_user_resource_attributes_ok/step2.user_resource_attributes_ok.tf @@ -0,0 +1,14 @@ +resource "outscale_policy" "policy_user01" { + description = "Example of description" + document = "{\"Statement\": [ {\"Effect\": \"Allow\", \"Action\": [\"*\"], \"Resource\": [\"*\"]} ]}" + path = "/okht/" + policy_name = "okht-user-policy" +} + +resource "outscale_user" "userInteg" { + user_name = "test_integ_update" + path = "/Integ/" + policy { + policy_orn = outscale_policy.policy_user01.orn + } +} From b97fb0e499c5399fbab288c2d6c3fc8f5c2112f0 Mon Sep 17 00:00:00 2001 From: Thiery Ouattara Date: Wed, 11 Dec 2024 16:24:19 +0000 Subject: [PATCH 3/9] Add EIM user_group resource and datasources --- outscale/data_source_outscale_user_group.go | 141 +++++ .../data_source_outscale_user_group_test.go | 36 ++ outscale/data_source_outscale_user_groups.go | 117 ++++ .../data_source_outscale_user_groups_test.go | 38 ++ outscale/resource_outscale_user_group.go | 579 ++++++++++++++++++ outscale/resource_outscale_user_group_test.go | 132 ++++ ...1.user_group_datasources_attributes_ok.ref | 161 +++++ ...p1.user_group_datasources_attributes_ok.tf | 41 ++ 8 files changed, 1245 insertions(+) create mode 100644 outscale/data_source_outscale_user_group.go create mode 100644 outscale/data_source_outscale_user_group_test.go create mode 100644 outscale/data_source_outscale_user_groups.go create mode 100644 outscale/data_source_outscale_user_groups_test.go create mode 100644 outscale/resource_outscale_user_group.go create mode 100644 outscale/resource_outscale_user_group_test.go create mode 100644 tests/qa_provider_oapi/data/user_group/TF-03_user_group_datasources_attributes_ok/step1.user_group_datasources_attributes_ok.ref create mode 100644 tests/qa_provider_oapi/data/user_group/TF-03_user_group_datasources_attributes_ok/step1.user_group_datasources_attributes_ok.tf diff --git a/outscale/data_source_outscale_user_group.go b/outscale/data_source_outscale_user_group.go new file mode 100644 index 000000000..d83242dc5 --- /dev/null +++ b/outscale/data_source_outscale_user_group.go @@ -0,0 +1,141 @@ +package outscale + +import ( + "context" + "fmt" + "time" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + oscgo "github.com/outscale/osc-sdk-go/v2" + "github.com/outscale/terraform-provider-outscale/utils" +) + +func DataSourceUserGroup() *schema.Resource { + return &schema.Resource{ + Read: DataSourceUserGroupRead, + Schema: map[string]*schema.Schema{ + "user_group_name": { + Type: schema.TypeString, + Required: true, + }, + "path": { + Type: schema.TypeString, + Optional: true, + }, + "user_group_id": { + Type: schema.TypeString, + Computed: true, + }, + "orn": { + Type: schema.TypeString, + Computed: true, + }, + "creation_date": { + Type: schema.TypeString, + Computed: true, + }, + "last_modification_date": { + Type: schema.TypeString, + Computed: true, + }, + "user": { + Type: schema.TypeSet, + Optional: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "user_name": { + Type: schema.TypeString, + Computed: true, + }, + "user_email": { + Type: schema.TypeString, + Computed: true, + }, + "path": { + Type: schema.TypeString, + Computed: true, + }, + "user_id": { + Type: schema.TypeString, + Computed: true, + }, + "creation_date": { + Type: schema.TypeString, + Computed: true, + }, + "last_modification_date": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + }, + } +} + +func DataSourceUserGroupRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*OutscaleClient).OSCAPI + req := oscgo.NewReadUserGroupRequest(d.Get("user_group_name").(string)) + if path := d.Get("path").(string); path != "" { + req.SetPath(path) + } + var resp oscgo.ReadUserGroupResponse + err := resource.Retry(2*time.Minute, func() *resource.RetryError { + rp, httpResp, err := conn.UserGroupApi.ReadUserGroup(context.Background()).ReadUserGroupRequest(*req).Execute() + if err != nil { + return utils.CheckThrottling(httpResp, err) + } + resp = rp + return nil + }) + + if err != nil { + return err + } + + if _, ok := resp.GetUserGroupOk(); !ok { + return fmt.Errorf("Unable to find user group") + } + d.SetId(resource.UniqueId()) + group := resp.GetUserGroup() + users := resp.GetUsers() + + if err := d.Set("user_group_name", group.GetName()); err != nil { + return err + } + if err := d.Set("user_group_id", group.GetUserGroupId()); err != nil { + return err + } + if err := d.Set("orn", group.GetOrn()); err != nil { + return err + } + if err := d.Set("path", group.GetPath()); err != nil { + return err + } + if err := d.Set("creation_date", group.GetCreationDate()); err != nil { + return err + } + if err := d.Set("last_modification_date", group.GetLastModificationDate()); err != nil { + return err + } + if len(users) > 0 { + userState := make([]map[string]interface{}, len(users)) + + for i, v := range users { + user := make(map[string]interface{}) + user["user_name"] = v.GetUserName() + user["user_id"] = v.GetUserId() + user["path"] = v.GetPath() + user["user_email"] = v.GetUserEmail() + user["creation_date"] = v.GetCreationDate() + user["last_modification_date"] = v.GetLastModificationDate() + userState[i] = user + } + if err := d.Set("user", userState); err != nil { + return err + } + } + return nil +} diff --git a/outscale/data_source_outscale_user_group_test.go b/outscale/data_source_outscale_user_group_test.go new file mode 100644 index 000000000..ae86e77a1 --- /dev/null +++ b/outscale/data_source_outscale_user_group_test.go @@ -0,0 +1,36 @@ +package outscale + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccOthers_data_user_group_basic(t *testing.T) { + t.Parallel() + resourceName := "data.outscale_user_group.basicUTest" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataUserGroupBasicConfig, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet(resourceName, "user_group_id"), + resource.TestCheckResourceAttrSet(resourceName, "user_group_name"), + ), + }, + }, + }) +} + +const testAccDataUserGroupBasicConfig = ` + resource "outscale_user_group" "uGData" { + user_group_name = "TestACC_udata" + path = "/" + } + data "outscale_user_group" "basicUTest" { + user_group_name = outscale_user_group.uGData.user_group_name + } +` diff --git a/outscale/data_source_outscale_user_groups.go b/outscale/data_source_outscale_user_groups.go new file mode 100644 index 000000000..741a5df13 --- /dev/null +++ b/outscale/data_source_outscale_user_groups.go @@ -0,0 +1,117 @@ +package outscale + +import ( + "context" + "fmt" + "log" + "time" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + oscgo "github.com/outscale/osc-sdk-go/v2" + "github.com/outscale/terraform-provider-outscale/utils" +) + +func DataSourceUserGroups() *schema.Resource { + return &schema.Resource{ + Read: DataSourceUserGroupsRead, + Schema: map[string]*schema.Schema{ + "filter": dataSourceFiltersSchema(), + "user_groups": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "user_group_name": { + Type: schema.TypeString, + Computed: true, + }, + "path": { + Type: schema.TypeString, + Computed: true, + }, + "user_group_id": { + Type: schema.TypeString, + Computed: true, + }, + "orn": { + Type: schema.TypeString, + Computed: true, + }, + "creation_date": { + Type: schema.TypeString, + Computed: true, + }, + "last_modification_date": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + }, + } +} + +func DataSourceUserGroupsRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*OutscaleClient).OSCAPI + req := oscgo.ReadUserGroupsRequest{} + filters, filtersOk := d.GetOk("filter") + if filtersOk { + filterReq := buildUserGroupsFilters(filters.(*schema.Set)) + req.SetFilters(*filterReq) + } + var resp oscgo.ReadUserGroupsResponse + err := resource.Retry(2*time.Minute, func() *resource.RetryError { + rp, httpResp, err := conn.UserGroupApi.ReadUserGroups(context.Background()).ReadUserGroupsRequest(req).Execute() + if err != nil { + return utils.CheckThrottling(httpResp, err) + } + resp = rp + return nil + }) + + if err != nil { + return err + } + + if _, ok := resp.GetUserGroupsOk(); !ok { + return fmt.Errorf("Unable to find user groups") + } + d.SetId(resource.UniqueId()) + userGps := resp.GetUserGroups() + userGroups := make([]map[string]interface{}, len(userGps)) + + for i, v := range userGps { + userGroup := make(map[string]interface{}) + userGroup["user_group_name"] = v.GetName() + userGroup["user_group_id"] = v.GetUserGroupId() + userGroup["path"] = v.GetPath() + userGroup["orn"] = v.GetOrn() + userGroup["creation_date"] = v.GetCreationDate() + userGroup["last_modification_date"] = v.GetLastModificationDate() + userGroups[i] = userGroup + } + return d.Set("user_groups", userGroups) +} + +func buildUserGroupsFilters(set *schema.Set) *oscgo.FiltersUserGroup { + var filters oscgo.FiltersUserGroup + for _, v := range set.List() { + m := v.(map[string]interface{}) + var filterValues []string + for _, e := range m["values"].([]interface{}) { + filterValues = append(filterValues, e.(string)) + } + + switch name := m["name"].(string); name { + case "path_prefix": + filters.SetPathPrefix(filterValues[0]) + case "user_group_ids": + filters.SetUserGroupIds(filterValues) + default: + log.Printf("[Debug] Unknown Filter Name: %s.", name) + } + } + return &filters +} diff --git a/outscale/data_source_outscale_user_groups_test.go b/outscale/data_source_outscale_user_groups_test.go new file mode 100644 index 000000000..893868b1e --- /dev/null +++ b/outscale/data_source_outscale_user_groups_test.go @@ -0,0 +1,38 @@ +package outscale + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccOthers_user_groups_basic(t *testing.T) { + t.Parallel() + resourceName := "data.outscale_user_groups.basicUGTest" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataUserGroupsBasicConfig, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet(resourceName, "user_groups.#"), + ), + }, + }, + }) +} + +const testAccDataUserGroupsBasicConfig = ` + resource "outscale_user_group" "uGroupData" { + user_group_name = "TestACC_uGdata" + path = "/" + } + data "outscale_user_groups" "basicUGTest" { + filter { + name = "user_group_ids" + values = [outscale_user_group.uGroupData.user_group_id] + } + } +` diff --git a/outscale/resource_outscale_user_group.go b/outscale/resource_outscale_user_group.go new file mode 100644 index 000000000..94ab73559 --- /dev/null +++ b/outscale/resource_outscale_user_group.go @@ -0,0 +1,579 @@ +package outscale + +import ( + "context" + "fmt" + "log" + "net/http" + "strings" + "time" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + oscgo "github.com/outscale/osc-sdk-go/v2" + "github.com/outscale/terraform-provider-outscale/utils" +) + +func ResourceUserGroup() *schema.Resource { + return &schema.Resource{ + Create: ResourceUserGroupCreate, + Read: ResourceUserGroupRead, + Update: ResourceUserGroupUpdate, + Delete: ResourceUserGroupDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + + Schema: map[string]*schema.Schema{ + "user_group_name": { + Type: schema.TypeString, + Required: true, + }, + "path": { + Type: schema.TypeString, + Optional: true, + Default: "/", + ValidateFunc: func(val interface{}, key string) (warns []string, errs []error) { + pathVal := val.(string) + if err := utils.CheckPath(pathVal); err != nil { + errs = append(errs, fmt.Errorf("%v, got:%v", err, pathVal)) + } + return + }, + }, + "user_group_id": { + Type: schema.TypeString, + Computed: true, + }, + "orn": { + Type: schema.TypeString, + Computed: true, + }, + "creation_date": { + Type: schema.TypeString, + Computed: true, + }, + "last_modification_date": { + Type: schema.TypeString, + Computed: true, + }, + "policy": { + Type: schema.TypeSet, + Optional: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "policy_orn": { + Type: schema.TypeString, + Required: true, + }, + "default_version_id": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "policy_name": { + Type: schema.TypeString, + Computed: true, + }, + "policy_id": { + Type: schema.TypeString, + Computed: true, + }, + "creation_date": { + Type: schema.TypeString, + Computed: true, + }, + "last_modification_date": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "user": { + Type: schema.TypeSet, + Optional: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "user_name": { + Type: schema.TypeString, + Required: true, + }, + "path": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateFunc: func(val interface{}, key string) (warns []string, errs []error) { + pathVal := val.(string) + if err := utils.CheckPath(pathVal); err != nil { + errs = append(errs, fmt.Errorf("%v, got:%v", err, pathVal)) + } + return + }, + }, + "user_id": { + Type: schema.TypeString, + Computed: true, + }, + "creation_date": { + Type: schema.TypeString, + Computed: true, + }, + "last_modification_date": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + }, + } +} + +func ResourceUserGroupCreate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*OutscaleClient).OSCAPI + + req := oscgo.NewCreateUserGroupRequest(d.Get("user_group_name").(string)) + groupPath := d.Get("path").(string) + req.SetPath(groupPath) + + var resp oscgo.CreateUserGroupResponse + err := resource.Retry(2*time.Minute, func() *resource.RetryError { + rp, httpResp, err := conn.UserGroupApi.CreateUserGroup(context.Background()).CreateUserGroupRequest(*req).Execute() + if err != nil { + return utils.CheckThrottling(httpResp, err) + } + resp = rp + return nil + }) + if err != nil { + return err + } + + d.SetId(*resp.GetUserGroup().UserGroupId) + if usersToAdd, ok := d.GetOk("user"); ok { + reqUserAdd := oscgo.AddUserToUserGroupRequest{} + reqUserAdd.SetUserGroupName(d.Get("user_group_name").(string)) + reqUserAdd.SetUserGroupPath(groupPath) + + for _, v := range usersToAdd.(*schema.Set).List() { + user := v.(map[string]interface{}) + if userName := user["user_name"].(string); userName != "" { + reqUserAdd.SetUserName(userName) + } + + if path := user["path"].(string); path != "" { + reqUserAdd.SetUserPath(path) + } + reqUserAdd.SetUserGroupPath(groupPath) + err := resource.Retry(1*time.Minute, func() *resource.RetryError { + _, httpResp, err := conn.UserGroupApi.AddUserToUserGroup(context.Background()).AddUserToUserGroupRequest(reqUserAdd).Execute() + if err != nil { + return utils.CheckThrottling(httpResp, err) + } + return nil + }) + if err != nil { + return err + } + + } + + } + if policiesToAdd, ok := d.GetOk("policy"); ok { + reqAddPolicy := oscgo.LinkManagedPolicyToUserGroupRequest{} + + for _, v := range policiesToAdd.(*schema.Set).List() { + policy := v.(map[string]interface{}) + + reqAddPolicy.SetUserGroupName(d.Get("user_group_name").(string)) + reqAddPolicy.SetPolicyOrn(policy["policy_orn"].(string)) + err := resource.Retry(1*time.Minute, func() *resource.RetryError { + _, httpResp, err := conn.PolicyApi.LinkManagedPolicyToUserGroup(context.Background()).LinkManagedPolicyToUserGroupRequest(reqAddPolicy).Execute() + if err != nil { + return utils.CheckThrottling(httpResp, err) + } + return nil + }) + if err != nil { + return err + } + if versionId := policy["default_version_id"].(string); versionId != "" { + if err := setDefaultPolicyVersion(conn, policy["policy_orn"].(string), versionId); err != nil { + return err + } + } + } + } + return ResourceUserGroupRead(d, meta) +} + +func ResourceUserGroupRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*OutscaleClient).OSCAPI + filter := oscgo.FiltersUserGroup{ + UserGroupIds: &[]string{d.Id()}, + } + req := oscgo.ReadUserGroupsRequest{} + req.SetFilters(filter) + var statusCode int + var resp oscgo.ReadUserGroupsResponse + err := resource.Retry(1*time.Minute, func() *resource.RetryError { + rp, httpResp, err := conn.UserGroupApi.ReadUserGroups(context.Background()).ReadUserGroupsRequest(req).Execute() + if err != nil { + return utils.CheckThrottling(httpResp, err) + } + resp = rp + statusCode = httpResp.StatusCode + return nil + }) + if err != nil { + if statusCode == http.StatusNotFound { + d.SetId("") + return nil + } + return err + } + + if _, ok := resp.GetUserGroupsOk(); !ok { + d.SetId("") + return nil + } + userGroup := resp.GetUserGroups()[0] + reqUser := oscgo.NewReadUserGroupRequest(userGroup.GetName()) + + var groupUsers []oscgo.User + err = resource.Retry(1*time.Minute, func() *resource.RetryError { + rp, httpResp, err := conn.UserGroupApi.ReadUserGroup(context.Background()).ReadUserGroupRequest(*reqUser).Execute() + if err != nil { + return utils.CheckThrottling(httpResp, err) + } + groupUsers = rp.GetUsers() + statusCode = httpResp.StatusCode + return nil + }) + if err != nil { + return err + } + + linkReq := oscgo.NewReadManagedPoliciesLinkedToUserGroupRequest(userGroup.GetName()) + var linkResp oscgo.ReadManagedPoliciesLinkedToUserGroupResponse + err = resource.Retry(1*time.Minute, func() *resource.RetryError { + rp, httpResp, err := conn.PolicyApi.ReadManagedPoliciesLinkedToUserGroup(context.Background()).ReadManagedPoliciesLinkedToUserGroupRequest(*linkReq).Execute() + if err != nil { + return utils.CheckThrottling(httpResp, err) + } + linkResp = rp + return nil + }) + if err != nil { + return err + } + + if err := d.Set("user_group_name", userGroup.GetName()); err != nil { + return err + } + if err := d.Set("path", userGroup.GetPath()); err != nil { + return err + } + if err := d.Set("user_group_id", userGroup.GetUserGroupId()); err != nil { + return err + } + if err := d.Set("orn", userGroup.GetOrn()); err != nil { + return err + } + if err := d.Set("creation_date", (userGroup.GetCreationDate())); err != nil { + return err + } + if err := d.Set("last_modification_date", (userGroup.GetLastModificationDate())); err != nil { + return err + } + + users := make([]map[string]interface{}, len(groupUsers)) + if len(groupUsers) > 0 { + for i, v := range groupUsers { + user := make(map[string]interface{}) + user["user_id"] = v.GetUserId() + user["user_name"] = v.GetUserName() + user["path"] = v.GetPath() + user["creation_date"] = v.GetCreationDate() + user["last_modification_date"] = v.GetLastModificationDate() + users[i] = user + } + } + if err := d.Set("user", users); err != nil { + return err + } + + gPolicies := linkResp.GetPolicies() + policies := make([]map[string]interface{}, len(gPolicies)) + if len(gPolicies) > 0 { + for i, v := range gPolicies { + policy := make(map[string]interface{}) + policy["policy_id"] = v.GetPolicyId() + policy["policy_name"] = v.GetPolicyName() + policy["policy_orn"] = v.GetOrn() + policy["creation_date"] = v.GetCreationDate() + policy["last_modification_date"] = v.GetLastModificationDate() + versionId, err := getPolicyVersion(conn, v.GetOrn()) + if err != nil { + return err + } + policy["default_version_id"] = versionId + policies[i] = policy + } + } + if err := d.Set("policy", policies); err != nil { + return err + } + return nil +} + +func ResourceUserGroupUpdate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*OutscaleClient).OSCAPI + req := oscgo.UpdateUserGroupRequest{} + isUpdateGroup := false + if d.HasChange("user_group_name") { + oldName, newName := d.GetChange("user_group_name") + req.SetUserGroupName(oldName.(string)) + req.SetNewUserGroupName(newName.(string)) + isUpdateGroup = true + } + if d.HasChange("path") { + oldPath, newPath := d.GetChange("path") + oldName, _ := d.GetChange("user_group_name") + req.SetPath(oldPath.(string)) + req.SetNewPath(newPath.(string)) + req.SetUserGroupName(oldName.(string)) + isUpdateGroup = true + } + if d.HasChange("user") { + oldUsers, newUsers := d.GetChange("user") + inter := oldUsers.(*schema.Set).Intersection(newUsers.(*schema.Set)) + toCreate := newUsers.(*schema.Set).Difference(inter) + toRemove := oldUsers.(*schema.Set).Difference(inter) + + if len(toRemove.List()) > 0 { + rmUserReq := oscgo.RemoveUserFromUserGroupRequest{} + oldN, _ := d.GetChange("user_group_name") + rmUserReq.SetUserGroupName(oldN.(string)) + oldP, _ := d.GetChange("path") + rmUserReq.SetUserGroupPath(oldP.(string)) + _, checkUpdate, _, err := getUsersLinkedToGroup(conn, toCreate.List(), oldN.(string)) + if err != nil { + return err + } + for _, v := range toRemove.List() { + user := v.(map[string]interface{}) + if len(checkUpdate) != 0 { + if checkUpdate[user["user_id"].(string)] { + continue + } + } + if userName := user["user_name"].(string); userName != "" { + rmUserReq.SetUserName(userName) + } + if path := user["path"].(string); path != "" { + rmUserReq.SetUserPath(path) + } + err = resource.Retry(2*time.Minute, func() *resource.RetryError { + _, httpResp, err := conn.UserGroupApi.RemoveUserFromUserGroup(context.Background()).RemoveUserFromUserGroupRequest(rmUserReq).Execute() + if err != nil { + return utils.CheckThrottling(httpResp, err) + } + return nil + }) + if err != nil { + return err + } + } + } + if len(toCreate.List()) > 0 { + addUserReq := oscgo.AddUserToUserGroupRequest{} + oldN, _ := d.GetChange("user_group_name") + addUserReq.SetUserGroupName(oldN.(string)) + oldP, _ := d.GetChange("path") + addUserReq.SetUserGroupPath(oldP.(string)) + _, _, checkUpdate, err := getUsersLinkedToGroup(conn, toCreate.List(), oldN.(string)) + if err != nil { + return err + } + for _, v := range toCreate.List() { + user := v.(map[string]interface{}) + if len(checkUpdate) != 0 { + if checkUpdate[user["user_name"].(string)] { + continue + } + } + if userName := user["user_name"].(string); userName != "" { + addUserReq.SetUserName(userName) + } + if path := user["path"].(string); path != "" { + addUserReq.SetUserPath(path) + } + err := resource.Retry(2*time.Minute, func() *resource.RetryError { + _, httpResp, err := conn.UserGroupApi.AddUserToUserGroup(context.Background()).AddUserToUserGroupRequest(addUserReq).Execute() + if err != nil { + return utils.CheckThrottling(httpResp, err) + } + return nil + }) + if err != nil { + return err + } + + } + } + } + + if d.HasChange("policy") { + oldPolicies, newPolicies := d.GetChange("policy") + inter := oldPolicies.(*schema.Set).Intersection(newPolicies.(*schema.Set)) + toCreate := newPolicies.(*schema.Set).Difference(inter) + toRemove := oldPolicies.(*schema.Set).Difference(inter) + + if len(toRemove.List()) > 0 { + unlinkReq := oscgo.UnlinkManagedPolicyFromUserGroupRequest{} + oldN, _ := d.GetChange("user_group_name") + unlinkReq.SetUserGroupName(oldN.(string)) + for _, v := range toRemove.List() { + policy := v.(map[string]interface{}) + unlinkReq.SetPolicyOrn(policy["policy_orn"].(string)) + err := resource.Retry(2*time.Minute, func() *resource.RetryError { + _, httpResp, err := conn.PolicyApi.UnlinkManagedPolicyFromUserGroup(context.Background()).UnlinkManagedPolicyFromUserGroupRequest(unlinkReq).Execute() + if err != nil { + log.Println("[INFO]: The policy has already been removed") + if strings.Contains(fmt.Sprint(httpResp.Body), utils.LinkedPolicyNotFound) { + return nil + } + return utils.CheckThrottling(httpResp, err) + } + return nil + }) + if err != nil { + return err + } + } + } + if len(toCreate.List()) > 0 { + linkReq := oscgo.LinkManagedPolicyToUserGroupRequest{} + oldN, _ := d.GetChange("user_group_name") + linkReq.SetUserGroupName(oldN.(string)) + + for _, v := range toCreate.List() { + policy := v.(map[string]interface{}) + linkReq.SetPolicyOrn(policy["policy_orn"].(string)) + err := resource.Retry(2*time.Minute, func() *resource.RetryError { + _, httpResp, err := conn.PolicyApi.LinkManagedPolicyToUserGroup(context.Background()).LinkManagedPolicyToUserGroupRequest(linkReq).Execute() + if err != nil { + return utils.CheckThrottling(httpResp, err) + } + return nil + }) + if err != nil { + return err + } + if versionId := policy["default_version_id"].(string); versionId != "" { + if err := setDefaultPolicyVersion(conn, policy["policy_orn"].(string), versionId); err != nil { + return err + } + } + } + } + } + if isUpdateGroup { + err := resource.Retry(2*time.Minute, func() *resource.RetryError { + _, httpResp, err := conn.UserGroupApi.UpdateUserGroup(context.Background()).UpdateUserGroupRequest(req).Execute() + if err != nil { + return utils.CheckThrottling(httpResp, err) + } + return nil + }) + if err != nil { + return err + } + } + return ResourceUserGroupRead(d, meta) +} + +func ResourceUserGroupDelete(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*OutscaleClient).OSCAPI + forceDeletion := true + req := oscgo.DeleteUserGroupRequest{ + UserGroupName: d.Get("user_group_name").(string), + Force: &forceDeletion, + } + + err := resource.Retry(3*time.Minute, func() *resource.RetryError { + _, httpResp, err := conn.UserGroupApi.DeleteUserGroup(context.Background()).DeleteUserGroupRequest(req).Execute() + if err != nil { + return utils.CheckThrottling(httpResp, err) + } + return nil + }) + if err != nil { + return fmt.Errorf("error deleting Outscale User Group %s: %s", d.Id(), err) + } + + return nil +} + +func getPolicyVersion(conn *oscgo.APIClient, policyOrn string) (string, error) { + version_id := "" + err := resource.Retry(3*time.Minute, func() *resource.RetryError { + resp, httpResp, err := conn.PolicyApi.ReadPolicy(context.Background()).ReadPolicyRequest( + oscgo.ReadPolicyRequest{PolicyOrn: policyOrn}).Execute() + if err != nil { + return utils.CheckThrottling(httpResp, err) + } + policy := resp.GetPolicy() + version_id = policy.GetPolicyDefaultVersionId() + return nil + }) + if err != nil { + return version_id, err + } + return version_id, err +} + +func setDefaultPolicyVersion(conn *oscgo.APIClient, policyOrn, version string) error { + err := resource.Retry(1*time.Minute, func() *resource.RetryError { + _, httpResp, err := conn.PolicyApi.SetDefaultPolicyVersion(context.Background()).SetDefaultPolicyVersionRequest( + oscgo.SetDefaultPolicyVersionRequest{ + PolicyOrn: policyOrn, + VersionId: version, + }).Execute() + if err != nil { + return utils.CheckThrottling(httpResp, err) + } + return nil + }) + return err +} + +func getUsersLinkedToGroup(conn *oscgo.APIClient, toCreate []interface{}, groupName string) ([]oscgo.User, map[string]bool, map[string]bool, error) { + reqUser := oscgo.NewReadUserGroupRequest(groupName) + + var users []oscgo.User + err := resource.Retry(1*time.Minute, func() *resource.RetryError { + rp, httpResp, err := conn.UserGroupApi.ReadUserGroup(context.Background()).ReadUserGroupRequest(*reqUser).Execute() + if err != nil { + return utils.CheckThrottling(httpResp, err) + } + users = rp.GetUsers() + return nil + }) + checkIds := make(map[string]bool) + checkName := make(map[string]bool) + for _, user := range users { + if len(toCreate) > 0 { + for _, v := range toCreate { + userTo := v.(map[string]interface{}) + if userTo["user_name"] == user.GetUserName() { + checkIds[user.GetUserId()] = true + checkName[user.GetUserName()] = true + } + } + } + } + return users, checkIds, checkName, err +} diff --git a/outscale/resource_outscale_user_group_test.go b/outscale/resource_outscale_user_group_test.go new file mode 100644 index 000000000..6953e773a --- /dev/null +++ b/outscale/resource_outscale_user_group_test.go @@ -0,0 +1,132 @@ +package outscale + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccOthers_user_group_basic(t *testing.T) { + t.Parallel() + resourceName := "outscale_user_group.basic_group" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccUserGroupBasicConfig, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet(resourceName, "user_group_name"), + resource.TestCheckResourceAttr(resourceName, "path", "/"), + ), + }, + }, + }) +} +func TestAccOthers_userGroup_with_user(t *testing.T) { + t.Parallel() + resourceName := "outscale_user_group.userGroupAcc" + groupName := "groupWithUsers" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccUserGroupWithUsers(groupName), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet(resourceName, "user_group_name"), + resource.TestCheckResourceAttr(resourceName, "path", "/"), + resource.TestCheckResourceAttr(resourceName, "user_group_name", groupName), + ), + }, + }, + }) +} + +func TestAccOthers_userGroup_update(t *testing.T) { + t.Parallel() + resourceName := "outscale_user_group.userGroupTAcc1" + groupName := "Gp1UpUser" + userName := "userGp1" + newGpName := "Gp2UpUsers" + newUsName := "userGp2" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccUserGroupUpadate(groupName, userName), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet(resourceName, "user_group_name"), + resource.TestCheckResourceAttr(resourceName, "path", "/"), + resource.TestCheckResourceAttr(resourceName, "user_group_name", groupName), + ), + }, + { + Config: testAccUserGroupUpadate(newGpName, newUsName), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet(resourceName, "user_group_name"), + resource.TestCheckResourceAttrSet(resourceName, "user.#"), + resource.TestCheckResourceAttr(resourceName, "path", "/"), + resource.TestCheckResourceAttr(resourceName, "user_group_name", newGpName), + ), + }, + }, + }) +} + +const testAccUserGroupBasicConfig = ` + resource "outscale_user_group" "basic_group" { + user_group_name = "TestACC_group1" + path = "/" + }` + +func testAccUserGroupWithUsers(name string) string { + return fmt.Sprintf(` + resource "outscale_user" "userToAdd1" { + user_name = "userForGp1" + path = "/" + } + resource "outscale_user" "userToAdd2" { + user_name = "userForGp2" + path = "/TestPath/" + } + + resource "outscale_user_group" "userGroupAcc" { + user_group_name = "%s" + path = "/" + user { + user_name = outscale_user.userToAdd1.user_name + } + user { + user_name = outscale_user.userToAdd2.user_name + path = "/TestPath/" + } + } + `, name) +} + +func testAccUserGroupUpadate(name, userName string) string { + return fmt.Sprintf(` + resource "outscale_user" "userUpToAdd01" { + user_name = "userGp1" + path = "/" + } + resource "outscale_user" "userUpToAdd02" { + user_name = "userGp2" + path = "/TestPath/" + } + resource "outscale_user_group" "userGroupTAcc1" { + user_group_name = "%s" + path = "/" + user { + user_name = "%s" + } + depends_on = [outscale_user.userUpToAdd01] + } + `, name, userName) +} diff --git a/tests/qa_provider_oapi/data/user_group/TF-03_user_group_datasources_attributes_ok/step1.user_group_datasources_attributes_ok.ref b/tests/qa_provider_oapi/data/user_group/TF-03_user_group_datasources_attributes_ok/step1.user_group_datasources_attributes_ok.ref new file mode 100644 index 000000000..f0121e8cc --- /dev/null +++ b/tests/qa_provider_oapi/data/user_group/TF-03_user_group_datasources_attributes_ok/step1.user_group_datasources_attributes_ok.ref @@ -0,0 +1,161 @@ +{ + "version": "########", + "terraform_version": "########", + "serial": "########", + "lineage": "########", + "outputs": {}, + "resources": [ + { + "mode": "data", + "type": "outscale_user_groups", + "name": "testgrpData", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "filter": "########", + "id": "##id-0##", + "user_groups": [ + { + "creation_date": "########", + "last_modification_date": "########", + "orn": "########", + "path": "/TestdataUG/", + "user_group_id": "##id-1##", + "user_group_name": "testDataugInteg" + } + ] + }, + "sensitive_attributes": [] + } + ] + }, + { + "mode": "managed", + "type": "outscale_policy", + "name": "policy_userGroup01", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "creation_date": "########", + "description": "Example of description", + "document": "{\"Statement\": [ {\"Effect\": \"Allow\", \"Action\": [\"*\"], \"Resource\": [\"*\"]} ]}", + "id": "##id-2##", + "is_linkable": true, + "last_modification_date": "########", + "orn": "########", + "path": "/okht/", + "policy_default_version_id": "##id-3##", + "policy_id": "##id-4##", + "policy_name": "group-policy", + "resources_count": 0 + }, + "sensitive_attributes": [], + "private": "bnVsbA==" + } + ] + }, + { + "mode": "managed", + "type": "outscale_policy", + "name": "policy_userTest", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "creation_date": "########", + "description": "Example of description", + "document": "{\"Statement\": [ {\"Effect\": \"Allow\", \"Action\": [\"*\"], \"Resource\": [\"*\"]} ]}", + "id": "##id-5##", + "is_linkable": true, + "last_modification_date": "########", + "orn": "########", + "path": "/", + "policy_default_version_id": "##id-3##", + "policy_id": "##id-6##", + "policy_name": "user-policy", + "resources_count": 0 + }, + "sensitive_attributes": [], + "private": "bnVsbA==" + } + ] + }, + { + "mode": "managed", + "type": "outscale_user", + "name": "userTest", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "creation_date": "########", + "id": "##id-7##", + "last_modification_date": "########", + "path": "/IntegGroup/", + "policy": [ + { + "creation_date": "########", + "default_version_id": "##id-3##", + "last_modification_date": "########", + "policy_id": "##id-6##", + "policy_name": "user-policy", + "policy_orn": "orn:ows:idauth::339215505907:policy/user-policy" + } + ], + "user_email": "customer-tooling@outscale.com", + "user_id": "##id-7##", + "user_name": "group_user" + }, + "sensitive_attributes": [], + "private": "bnVsbA==", + "dependencies": [ + "outscale_policy.policy_userTest" + ] + } + ] + }, + { + "mode": "managed", + "type": "outscale_user_group", + "name": "dataUserGroupInteg", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "creation_date": "########", + "id": "##id-1##", + "last_modification_date": "########", + "orn": "########", + "path": "/TestdataUG/", + "policy": [ + { + "creation_date": "########", + "default_version_id": "##id-3##", + "last_modification_date": "########", + "policy_id": "##id-4##", + "policy_name": "group-policy", + "policy_orn": "orn:ows:idauth::339215505907:policy/okht/group-policy" + } + ], + "user": [], + "user_group_id": "##id-1##", + "user_group_name": "testDataugInteg" + }, + "sensitive_attributes": [], + "private": "bnVsbA==", + "dependencies": [ + "outscale_policy.policy_userGroup01" + ] + } + ] + } + ], + "check_results": "########" +} \ No newline at end of file diff --git a/tests/qa_provider_oapi/data/user_group/TF-03_user_group_datasources_attributes_ok/step1.user_group_datasources_attributes_ok.tf b/tests/qa_provider_oapi/data/user_group/TF-03_user_group_datasources_attributes_ok/step1.user_group_datasources_attributes_ok.tf new file mode 100644 index 000000000..9797f5b07 --- /dev/null +++ b/tests/qa_provider_oapi/data/user_group/TF-03_user_group_datasources_attributes_ok/step1.user_group_datasources_attributes_ok.tf @@ -0,0 +1,41 @@ +resource "outscale_policy" "policy_userGroup01" { + description = "Example of description" + document = "{\"Statement\": [ {\"Effect\": \"Allow\", \"Action\": [\"*\"], \"Resource\": [\"*\"]} ]}" + path = "/okht/" + policy_name = "group-policy" +} + +resource "outscale_policy" "policy_userTest" { + description = "Example of description" + document = "{\"Statement\": [ {\"Effect\": \"Allow\", \"Action\": [\"*\"], \"Resource\": [\"*\"]} ]}" + path = "/" + policy_name = "user-policy" +} + +resource "outscale_user" "userTest" { + user_name = "group_user" + path = "/IntegGroup/" + policy { + policy_orn = outscale_policy.policy_userTest.orn + } +} + +resource "outscale_user_group" "dataUserGroupInteg" { + user_group_name = "testDataugInteg" + path = "/TestdataUG/" + policy { + policy_orn = outscale_policy.policy_userGroup01.orn + } +} + +data "outscale_user_groups" "testgrpData" { + filter { + name = "user_group_ids" + values = [outscale_user_group.dataUserGroupInteg.user_group_id] + } + filter { + name = "path_prefix" + values = ["/TestdataUG/"] + } +} + From 9b182e1f878b02183dfde2ababef5eb070ec810c Mon Sep 17 00:00:00 2001 From: Thiery Ouattara Date: Wed, 11 Dec 2024 16:30:22 +0000 Subject: [PATCH 4/9] Add EIM policy/policy_version resource and datasources --- outscale/data_source_outscale_policies.go | 142 ++++++++++ outscale/data_source_outscale_policy.go | 124 ++++++++ outscale/data_source_outscale_policy_test.go | 37 +++ outscale/resource_outscale_policy.go | 267 ++++++++++++++++++ outscale/resource_outscale_policy_test.go | 33 +++ outscale/resource_outscale_policy_version.go | 189 +++++++++++++ .../resource_outscale_policy_version_test.go | 39 +++ 7 files changed, 831 insertions(+) create mode 100644 outscale/data_source_outscale_policies.go create mode 100644 outscale/data_source_outscale_policy.go create mode 100644 outscale/data_source_outscale_policy_test.go create mode 100644 outscale/resource_outscale_policy.go create mode 100644 outscale/resource_outscale_policy_test.go create mode 100644 outscale/resource_outscale_policy_version.go create mode 100644 outscale/resource_outscale_policy_version_test.go diff --git a/outscale/data_source_outscale_policies.go b/outscale/data_source_outscale_policies.go new file mode 100644 index 000000000..5cc18767d --- /dev/null +++ b/outscale/data_source_outscale_policies.go @@ -0,0 +1,142 @@ +package outscale + +import ( + "context" + "fmt" + "log" + "time" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + oscgo "github.com/outscale/osc-sdk-go/v2" + "github.com/outscale/terraform-provider-outscale/utils" + "github.com/spf13/cast" +) + +func DataSourcePolicies() *schema.Resource { + return &schema.Resource{ + Read: DataSourcePoliciesRead, + Schema: map[string]*schema.Schema{ + "filter": dataSourceFiltersSchema(), + "policies": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + + "policy_name": { + Type: schema.TypeString, + Required: true, + }, + "description": { + Type: schema.TypeString, + Computed: true, + }, + "path": { + Type: schema.TypeString, + Computed: true, + }, + "policy_id": { + Type: schema.TypeString, + Computed: true, + }, + "resources_count": { + Type: schema.TypeInt, + Computed: true, + }, + "policy_default_version_id": { + Type: schema.TypeString, + Computed: true, + }, + "is_linkable": { + Type: schema.TypeBool, + Computed: true, + }, + "orn": { + Type: schema.TypeString, + Computed: true, + }, + "creation_date": { + Type: schema.TypeString, + Computed: true, + }, + "last_modification_date": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + }, + } +} + +func DataSourcePoliciesRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*OutscaleClient).OSCAPI + + filters, filtersOk := d.GetOk("filter") + req := oscgo.NewReadPoliciesRequest() + if filtersOk { + filterReq := buildPoliciesFilters(filters.(*schema.Set)) + req.SetFilters(*filterReq) + } + var resp oscgo.ReadPoliciesResponse + err := resource.Retry(2*time.Minute, func() *resource.RetryError { + rp, httpResp, err := conn.PolicyApi.ReadPolicies(context.Background()).ReadPoliciesRequest(*req).Execute() + if err != nil { + return utils.CheckThrottling(httpResp, err) + } + resp = rp + return nil + }) + + if err != nil { + return err + } + policyResp := resp.GetPolicies() + if len(policyResp) == 0 { + return fmt.Errorf("Unable to find Policies with fileters: %v", filters.(*schema.Set)) + } + d.SetId(resource.UniqueId()) + + policies := make([]map[string]interface{}, len(policyResp)) + + for i, v := range policyResp { + policy := make(map[string]interface{}) + policy["policy_name"] = v.GetPolicyName() + policy["policy_id"] = v.GetPolicyId() + policy["path"] = v.GetPath() + policy["orn"] = v.GetOrn() + policy["resources_count"] = v.GetResourcesCount() + policy["is_linkable"] = v.GetIsLinkable() + policy["policy_default_version_id"] = v.GetPolicyDefaultVersionId() + policy["description"] = v.GetDescription() + policy["creation_date"] = v.GetCreationDate() + policy["last_modification_date"] = v.GetLastModificationDate() + policies[i] = policy + } + return d.Set("policies", policies) +} + +func buildPoliciesFilters(set *schema.Set) *oscgo.ReadPoliciesFilters { + var filters oscgo.ReadPoliciesFilters + for _, v := range set.List() { + m := v.(map[string]interface{}) + var filterValues []string + for _, e := range m["values"].([]interface{}) { + filterValues = append(filterValues, e.(string)) + } + + switch name := m["name"].(string); name { + case "only_linked": + filters.SetOnlyLinked(cast.ToBool(filterValues[0])) + case "path_prefix": + filters.SetPathPrefix(filterValues[0]) + case "scope": + filters.SetScope(filterValues[0]) + default: + log.Printf("[Debug] Unknown Filter Name: %s.", name) + } + } + return &filters +} diff --git a/outscale/data_source_outscale_policy.go b/outscale/data_source_outscale_policy.go new file mode 100644 index 000000000..7863db868 --- /dev/null +++ b/outscale/data_source_outscale_policy.go @@ -0,0 +1,124 @@ +package outscale + +import ( + "context" + "time" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + oscgo "github.com/outscale/osc-sdk-go/v2" + "github.com/outscale/terraform-provider-outscale/utils" +) + +func DataSourcePolicy() *schema.Resource { + return &schema.Resource{ + Read: DataSourcePolicyRead, + Schema: map[string]*schema.Schema{ + "policy_orn": { + Type: schema.TypeString, + Required: true, + }, + "policy_name": { + Type: schema.TypeString, + Computed: true, + }, + "description": { + Type: schema.TypeString, + Computed: true, + }, + "document": { + Type: schema.TypeString, + Computed: true, + }, + "path": { + Type: schema.TypeString, + Computed: true, + }, + "policy_id": { + Type: schema.TypeString, + Computed: true, + }, + "resources_count": { + Type: schema.TypeInt, + Computed: true, + }, + "policy_default_version_id": { + Type: schema.TypeString, + Computed: true, + }, + "is_linkable": { + Type: schema.TypeBool, + Computed: true, + }, + "orn": { + Type: schema.TypeString, + Computed: true, + }, + "creation_date": { + Type: schema.TypeString, + Computed: true, + }, + "last_modification_date": { + Type: schema.TypeString, + Computed: true, + }, + }, + } +} + +func DataSourcePolicyRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*OutscaleClient).OSCAPI + req := oscgo.NewReadPolicyRequest(d.Get("policy_orn").(string)) + + var resp oscgo.ReadPolicyResponse + err := resource.Retry(2*time.Minute, func() *resource.RetryError { + rp, httpResp, err := conn.PolicyApi.ReadPolicy(context.Background()).ReadPolicyRequest(*req).Execute() + if err != nil { + return utils.CheckThrottling(httpResp, err) + } + resp = rp + return nil + }) + + if err != nil { + return err + } + + if _, ok := resp.GetPolicyOk(); !ok { + d.SetId("") + return nil + } + policy := resp.GetPolicy() + d.SetId(resource.UniqueId()) + if err := d.Set("policy_name", policy.GetPolicyName()); err != nil { + return err + } + if err := d.Set("policy_id", policy.GetPolicyId()); err != nil { + return err + } + if err := d.Set("path", policy.GetPath()); err != nil { + return err + } + if err := d.Set("orn", policy.GetOrn()); err != nil { + return err + } + if err := d.Set("resources_count", policy.GetResourcesCount()); err != nil { + return err + } + if err := d.Set("is_linkable", policy.GetIsLinkable()); err != nil { + return err + } + if err := d.Set("policy_default_version_id", policy.GetPolicyDefaultVersionId()); err != nil { + return err + } + if err := d.Set("description", policy.GetDescription()); err != nil { + return err + } + if err := d.Set("creation_date", (policy.GetCreationDate())); err != nil { + return err + } + if err := d.Set("last_modification_date", (policy.GetLastModificationDate())); err != nil { + return err + } + return nil +} diff --git a/outscale/data_source_outscale_policy_test.go b/outscale/data_source_outscale_policy_test.go new file mode 100644 index 000000000..b7e53f011 --- /dev/null +++ b/outscale/data_source_outscale_policy_test.go @@ -0,0 +1,37 @@ +package outscale + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccOthers_data_policy_basic(t *testing.T) { + t.Parallel() + resourceName := "data.outscale_policy.data_test" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccPolicyDataConfig, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet(resourceName, "policy_name"), + resource.TestCheckResourceAttr(resourceName, "path", "/"), + ), + }, + }, + }) +} + +const testAccPolicyDataConfig = ` + resource "outscale_policy" "data_policy" { + policy_name = "TestACC_resoucePolicy" + document = "{\"Statement\": [ {\"Effect\": \"Allow\", \"Action\": [\"*\"], \"Resource\": [\"*\"]} ]}" + path = "/" + } + data "outscale_policy" "data_test" { + policy_orn = outscale_policy.data_policy.orn + } +` diff --git a/outscale/resource_outscale_policy.go b/outscale/resource_outscale_policy.go new file mode 100644 index 000000000..9c516cdb4 --- /dev/null +++ b/outscale/resource_outscale_policy.go @@ -0,0 +1,267 @@ +package outscale + +import ( + "context" + "fmt" + "time" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + oscgo "github.com/outscale/osc-sdk-go/v2" + "github.com/outscale/terraform-provider-outscale/utils" +) + +func ResourceOutscalePolicy() *schema.Resource { + return &schema.Resource{ + Create: ResourceOutscalePolicyCreate, + Read: ResourceOutscalePolicyRead, + Delete: ResourceOutscalePolicyDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + + Schema: map[string]*schema.Schema{ + "policy_name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + "description": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, + "document": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + "path": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "policy_id": { + Type: schema.TypeString, + Computed: true, + }, + "resources_count": { + Type: schema.TypeInt, + Computed: true, + }, + "policy_default_version_id": { + Type: schema.TypeString, + Computed: true, + }, + "is_linkable": { + Type: schema.TypeBool, + Computed: true, + }, + "orn": { + Type: schema.TypeString, + Computed: true, + }, + "creation_date": { + Type: schema.TypeString, + Computed: true, + }, + "last_modification_date": { + Type: schema.TypeString, + Computed: true, + }, + }, + } +} + +func ResourceOutscalePolicyCreate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*OutscaleClient).OSCAPI + polDocument := d.Get("document").(string) + req := oscgo.NewCreatePolicyRequest(polDocument, d.Get("policy_name").(string)) + if polPath := d.Get("path").(string); polPath != "" { + req.SetPath(polPath) + } + if polDescription := d.Get("description").(string); polDescription != "" { + req.SetDescription(polDescription) + } + + var resp oscgo.CreatePolicyResponse + err := resource.Retry(2*time.Minute, func() *resource.RetryError { + rp, httpResp, err := conn.PolicyApi.CreatePolicy(context.Background()).CreatePolicyRequest(*req).Execute() + if err != nil { + return utils.CheckThrottling(httpResp, err) + } + resp = rp + return nil + }) + if err != nil { + return err + } + + d.SetId(*resp.GetPolicy().Orn) + return ResourceOutscalePolicyRead(d, meta) +} + +func ResourceOutscalePolicyRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*OutscaleClient).OSCAPI + req := oscgo.NewReadPolicyRequest(d.Id()) + + var resp oscgo.ReadPolicyResponse + err := resource.Retry(2*time.Minute, func() *resource.RetryError { + rp, httpResp, err := conn.PolicyApi.ReadPolicy(context.Background()).ReadPolicyRequest(*req).Execute() + if err != nil { + return utils.CheckThrottling(httpResp, err) + } + resp = rp + return nil + }) + + if err != nil { + return err + } + + if _, ok := resp.GetPolicyOk(); !ok { + d.SetId("") + return nil + } + policy := resp.GetPolicy() + policyDocument, err := getPolicyDocument(conn, policy.GetOrn(), policy.GetPolicyDefaultVersionId()) + if err != nil { + return err + } + if err := d.Set("policy_name", policy.GetPolicyName()); err != nil { + return err + } + if err := d.Set("policy_id", policy.GetPolicyId()); err != nil { + return err + } + if err := d.Set("path", policy.GetPath()); err != nil { + return err + } + if err := d.Set("orn", policy.GetOrn()); err != nil { + return err + } + if err := d.Set("document", policyDocument); err != nil { + return err + } + if err := d.Set("resources_count", policy.GetResourcesCount()); err != nil { + return err + } + if err := d.Set("is_linkable", policy.GetIsLinkable()); err != nil { + return err + } + if err := d.Set("policy_default_version_id", policy.GetPolicyDefaultVersionId()); err != nil { + return err + } + if err := d.Set("description", policy.GetDescription()); err != nil { + return err + } + + if err := d.Set("creation_date", (policy.GetCreationDate())); err != nil { + return err + } + + if err := d.Set("last_modification_date", (policy.GetLastModificationDate())); err != nil { + return err + } + return nil +} + +func ResourceOutscalePolicyDelete(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*OutscaleClient).OSCAPI + policyOrn := d.Get("orn").(string) + if err := unlinkEntitiesToPolicy(conn, policyOrn); err != nil { + return err + } + + req := oscgo.NewDeletePolicyRequest(policyOrn) + err := resource.Retry(2*time.Minute, func() *resource.RetryError { + _, httpResp, err := conn.PolicyApi.DeletePolicy(context.Background()).DeletePolicyRequest(*req).Execute() + if err != nil { + return utils.CheckThrottling(httpResp, err) + } + return nil + }) + if err != nil { + return fmt.Errorf("error deleting Outscale Policy %s: %s", d.Id(), err) + } + return nil +} + +func unlinkEntitiesToPolicy(conn *oscgo.APIClient, policyOrn string) error { + + req := oscgo.ReadEntitiesLinkedToPolicyRequest{PolicyOrn: &policyOrn} + var users, groups []oscgo.MinimalPolicy + err := resource.Retry(2*time.Minute, func() *resource.RetryError { + resp, httpResp, err := conn.PolicyApi.ReadEntitiesLinkedToPolicy(context.Background()).ReadEntitiesLinkedToPolicyRequest(req).Execute() + if err != nil { + return utils.CheckThrottling(httpResp, err) + } + if resp.HasPolicyEntities() { + users = *resp.GetPolicyEntities().Users + groups = *resp.GetPolicyEntities().Groups + } + return nil + }) + if err != nil { + return err + } + if len(users) > 0 { + unlinkReq := oscgo.UnlinkPolicyRequest{} + unlinkReq.SetPolicyOrn(policyOrn) + + for _, user := range users { + unlinkReq.SetUserName(*user.Name) + err := resource.Retry(2*time.Minute, func() *resource.RetryError { + _, httpResp, err := conn.PolicyApi.UnlinkPolicy(context.Background()).UnlinkPolicyRequest(unlinkReq).Execute() + if err != nil { + return utils.CheckThrottling(httpResp, err) + } + return nil + }) + if err != nil { + return err + } + } + } + if len(groups) > 0 { + unlinkReq := oscgo.UnlinkManagedPolicyFromUserGroupRequest{PolicyOrn: policyOrn} + for _, group := range groups { + unlinkReq.SetUserGroupName(*group.Name) + err := resource.Retry(2*time.Minute, func() *resource.RetryError { + _, httpResp, err := conn.PolicyApi.UnlinkManagedPolicyFromUserGroup(context.Background()).UnlinkManagedPolicyFromUserGroupRequest(unlinkReq).Execute() + if err != nil { + return utils.CheckThrottling(httpResp, err) + } + return nil + }) + if err != nil { + return err + } + } + } + + return err +} + +func getPolicyDocument(conn *oscgo.APIClient, policyOrn, policyVersionId string) (string, error) { + + req := oscgo.NewReadPolicyVersionRequest(policyOrn, policyVersionId) + var resp oscgo.ReadPolicyVersionResponse + err := retry.Retry(2*time.Minute, func() *retry.RetryError { + rp, httpResp, err := conn.PolicyApi.ReadPolicyVersion(context.Background()).ReadPolicyVersionRequest(*req).Execute() + if err != nil { + return utils.CheckThrottling(httpResp, err) + } + resp = rp + return nil + }) + if err != nil { + return "", err + } + if _, ok := resp.GetPolicyVersionOk(); !ok { + return "", fmt.Errorf("connot found Policy version: %v", policyVersionId) + } + + return *resp.GetPolicyVersion().Body, err +} diff --git a/outscale/resource_outscale_policy_test.go b/outscale/resource_outscale_policy_test.go new file mode 100644 index 000000000..da22e88ae --- /dev/null +++ b/outscale/resource_outscale_policy_test.go @@ -0,0 +1,33 @@ +package outscale + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccOthers_policy_basic(t *testing.T) { + t.Parallel() + resourceName := "outscale_policy.basic_policy" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccPolicyBasicConfig, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet(resourceName, "policy_name"), + resource.TestCheckResourceAttr(resourceName, "path", "/"), + ), + }, + }, + }) +} + +const testAccPolicyBasicConfig = ` + resource "outscale_policy" "basic_policy" { + policy_name = "TestACC_resoucePolicy" + document = "{\"Statement\": [ {\"Effect\": \"Allow\", \"Action\": [\"*\"], \"Resource\": [\"*\"]} ]}" + path = "/" + }` diff --git a/outscale/resource_outscale_policy_version.go b/outscale/resource_outscale_policy_version.go new file mode 100644 index 000000000..42e82eb4d --- /dev/null +++ b/outscale/resource_outscale_policy_version.go @@ -0,0 +1,189 @@ +package outscale + +import ( + "context" + "fmt" + "time" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + oscgo "github.com/outscale/osc-sdk-go/v2" + "github.com/outscale/terraform-provider-outscale/utils" +) + +func ResourcePolicyVersion() *schema.Resource { + return &schema.Resource{ + Create: ResourcePolicyVersionCreate, + Read: ResourcePolicyVersionRead, + Delete: ResourcePolicyVersionDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + + Schema: map[string]*schema.Schema{ + "policy_orn": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + "document": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + "set_as_default": { + Type: schema.TypeBool, + Optional: true, + Computed: true, + }, + "version_id": { + Type: schema.TypeString, + Computed: true, + }, + "default_version": { + Type: schema.TypeBool, + Computed: true, + }, + "creation_date": { + Type: schema.TypeString, + Computed: true, + }, + "body": { + Type: schema.TypeString, + Computed: true, + }, + }, + } +} + +func ResourcePolicyVersionCreate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*OutscaleClient).OSCAPI + pvDocument := d.Get("document").(string) + req := oscgo.NewCreatePolicyVersionRequest(pvDocument, d.Get("policy_orn").(string)) + + if asDefault, ok := d.GetOk("set_as_default"); ok { + req.SetSetAsDefault(asDefault.(bool)) + } + + var resp oscgo.CreatePolicyVersionResponse + err := resource.Retry(5*time.Minute, func() *resource.RetryError { + rp, httpResp, err := conn.PolicyApi.CreatePolicyVersion(context.Background()).CreatePolicyVersionRequest(*req).Execute() + if err != nil { + return utils.CheckThrottling(httpResp, err) + } + resp = rp + return nil + }) + if err != nil { + return err + } + + d.SetId(resource.UniqueId()) + pVersion := resp.GetPolicyVersion() + if err := d.Set("version_id", pVersion.GetVersionId()); err != nil { + return err + } + + return ResourcePolicyVersionRead(d, meta) +} + +func ResourcePolicyVersionRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*OutscaleClient).OSCAPI + req := oscgo.NewReadPolicyVersionRequest(d.Get("policy_orn").(string), d.Get("version_id").(string)) + + var resp oscgo.ReadPolicyVersionResponse + err := retry.Retry(2*time.Minute, func() *retry.RetryError { + rp, httpResp, err := conn.PolicyApi.ReadPolicyVersion(context.Background()).ReadPolicyVersionRequest(*req).Execute() + if err != nil { + return utils.CheckThrottling(httpResp, err) + } + resp = rp + return nil + }) + + if err != nil { + return err + } + + if _, ok := resp.GetPolicyVersionOk(); !ok { + d.SetId("") + return nil + } + pVersion := resp.GetPolicyVersion() + if err := d.Set("default_version", pVersion.GetDefaultVersion()); err != nil { + return err + } + if err := d.Set("creation_date", (pVersion.GetCreationDate())); err != nil { + return err + } + if err := d.Set("body", pVersion.GetBody()); err != nil { + return err + } + return nil +} + +func ResourcePolicyVersionDelete(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*OutscaleClient).OSCAPI + if d.Get("default_version").(bool) { + resps, err := readPolicyVersions(d, meta) + if err != nil { + return err + } + if _, ok := resps.GetPolicyVersionsOk(); !ok { + d.SetId("") + return nil + } + pVersions := resps.GetPolicyVersions() + if len(pVersions) <= 1 { + return fmt.Errorf("cannot delete the default policy version\n It will be deleted with the policy") + } + for _, version := range pVersions { + if version.GetVersionId() == "v1" { + req := oscgo.NewSetDefaultPolicyVersionRequest(d.Get("policy_orn").(string), version.GetVersionId()) + err = retry.Retry(2*time.Minute, func() *retry.RetryError { + _, httpResp, err := conn.PolicyApi.SetDefaultPolicyVersion(context.Background()).SetDefaultPolicyVersionRequest(*req).Execute() + if err != nil { + return utils.CheckThrottling(httpResp, err) + } + return nil + }) + if err != nil { + return err + } + break + } + } + } + + req := oscgo.NewDeletePolicyVersionRequest(d.Get("policy_orn").(string), d.Get("version_id").(string)) + + err := retry.Retry(2*time.Minute, func() *retry.RetryError { + _, httpResp, err := conn.PolicyApi.DeletePolicyVersion(context.Background()).DeletePolicyVersionRequest(*req).Execute() + if err != nil { + return utils.CheckThrottling(httpResp, err) + } + return nil + }) + if err != nil { + return fmt.Errorf("error deleting Outscale Policy version %s: %s", d.Id(), err) + } + + return nil +} + +func readPolicyVersions(d *schema.ResourceData, meta interface{}) (oscgo.ReadPolicyVersionsResponse, error) { + conn := meta.(*OutscaleClient).OSCAPI + req := oscgo.NewReadPolicyVersionsRequest(d.Get("policy_orn").(string)) + + var resp oscgo.ReadPolicyVersionsResponse + err := retry.Retry(2*time.Minute, func() *retry.RetryError { + rp, httpResp, err := conn.PolicyApi.ReadPolicyVersions(context.Background()).ReadPolicyVersionsRequest(*req).Execute() + if err != nil { + return utils.CheckThrottling(httpResp, err) + } + resp = rp + return nil + }) + return resp, err +} diff --git a/outscale/resource_outscale_policy_version_test.go b/outscale/resource_outscale_policy_version_test.go new file mode 100644 index 000000000..83b72efc3 --- /dev/null +++ b/outscale/resource_outscale_policy_version_test.go @@ -0,0 +1,39 @@ +package outscale + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccOthers_policy_Version_basic(t *testing.T) { + t.Parallel() + resourceName := "outscale_policy_version.policy_version" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccPolicyVersionConfig, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet(resourceName, "creation_date"), + resource.TestCheckResourceAttrSet(resourceName, "body"), + resource.TestCheckResourceAttr(resourceName, "version_id", "v2"), + ), + }, + }, + }) +} + +const testAccPolicyVersionConfig = ` + resource "outscale_policy" "vers_policy" { + policy_name = "TestACC_VersionPolicy" + document = "{\"Statement\": [ {\"Effect\": \"Allow\", \"Action\": [\"*\"], \"Resource\": [\"*\"]} ]}" + path = "/" + } + resource "outscale_policy_version" "policy_version" { + policy_orn = outscale_policy.vers_policy.orn + document = "{\"Statement\": [ {\"Effect\": \"Allow\", \"Action\": [\"*\"], \"Resource\": [\"*\"]} ]}" + } +` From b6bcfb99610b3b641fca68a871878b1664141801 Mon Sep 17 00:00:00 2001 From: Thiery Ouattara Date: Wed, 11 Dec 2024 16:36:28 +0000 Subject: [PATCH 5/9] Add EIM other data_sources --- ...urce_outscale_entities_linked_to_policy.go | 164 ++++++++++++++++++ ...outscale_entities_linked_to_policy_test.go | 64 +++++++ ...source_outscale_policies_linked_to_user.go | 90 ++++++++++ ..._outscale_policies_linked_to_user_group.go | 94 ++++++++++ ...cale_policies_linked_to_user_group_test.go | 50 ++++++ ...e_outscale_policies_linked_to_user_test.go | 54 ++++++ ...ta_source_outscale_user_groups_per_user.go | 102 +++++++++++ ...urce_outscale_user_groups_per_user_test.go | 51 ++++++ 8 files changed, 669 insertions(+) create mode 100644 outscale/data_source_outscale_entities_linked_to_policy.go create mode 100644 outscale/data_source_outscale_entities_linked_to_policy_test.go create mode 100644 outscale/data_source_outscale_policies_linked_to_user.go create mode 100644 outscale/data_source_outscale_policies_linked_to_user_group.go create mode 100644 outscale/data_source_outscale_policies_linked_to_user_group_test.go create mode 100644 outscale/data_source_outscale_policies_linked_to_user_test.go create mode 100644 outscale/data_source_outscale_user_groups_per_user.go create mode 100644 outscale/data_source_outscale_user_groups_per_user_test.go diff --git a/outscale/data_source_outscale_entities_linked_to_policy.go b/outscale/data_source_outscale_entities_linked_to_policy.go new file mode 100644 index 000000000..02967182f --- /dev/null +++ b/outscale/data_source_outscale_entities_linked_to_policy.go @@ -0,0 +1,164 @@ +package outscale + +import ( + "context" + "fmt" + "time" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + oscgo "github.com/outscale/osc-sdk-go/v2" + "github.com/outscale/terraform-provider-outscale/utils" +) + +func DataSourceEntitiesLinkedToPolicy() *schema.Resource { + return &schema.Resource{ + Read: DataSourceEntitiesLinkedToPoliciesRead, + Schema: map[string]*schema.Schema{ + "policy_orn": { + Type: schema.TypeString, + Required: true, + }, + "entities_type": { + Type: schema.TypeSet, + Optional: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "policy_entities": { + Type: schema.TypeSet, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "users": { + Type: schema.TypeSet, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "id": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "orn": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "groups": { + Type: schema.TypeSet, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "id": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "orn": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "accounts": { + Type: schema.TypeSet, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "id": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "orn": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + }, + }, + }, + }, + } +} + +func DataSourceEntitiesLinkedToPoliciesRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*OutscaleClient).OSCAPI + orn := d.Get("policy_orn").(string) + req := oscgo.ReadEntitiesLinkedToPolicyRequest{PolicyOrn: &orn} + if entities := utils.SetToStringSlice(d.Get("entities_type").(*schema.Set)); len(entities) > 0 { + req.SetEntitiesType(entities) + } + + var resp oscgo.ReadEntitiesLinkedToPolicyResponse + err := resource.Retry(2*time.Minute, func() *resource.RetryError { + rp, httpResp, err := conn.PolicyApi.ReadEntitiesLinkedToPolicy(context.Background()).ReadEntitiesLinkedToPolicyRequest(req).Execute() + if err != nil { + return utils.CheckThrottling(httpResp, err) + } + resp = rp + return nil + }) + + if err != nil { + return err + } + entities, ok := resp.GetPolicyEntitiesOk() + if !ok { + return fmt.Errorf("unable to find Entities linked to policy") + } + d.SetId(resource.UniqueId()) + + users := make([]map[string]interface{}, len(entities.GetUsers())) + groups := make([]map[string]interface{}, len(entities.GetGroups())) + accounts := make([]map[string]interface{}, len(entities.GetAccounts())) + if respUsers, ok := entities.GetUsersOk(); ok { + for i, v := range *respUsers { + user := make(map[string]interface{}) + user["id"] = v.GetId() + user["name"] = v.GetName() + user["orn"] = v.GetOrn() + users[i] = user + } + } + if respGroups, ok := entities.GetGroupsOk(); ok { + for i, v := range *respGroups { + group := make(map[string]interface{}) + group["name"] = v.GetName() + group["id"] = v.GetId() + group["orn"] = v.GetOrn() + groups[i] = group + } + } + if respAccounts, ok := entities.GetAccountsOk(); ok { + for i, v := range *respAccounts { + account := make(map[string]interface{}) + account["name"] = v.GetName() + account["id"] = v.GetId() + account["orn"] = v.GetOrn() + accounts[i] = account + } + } + + return d.Set("policy_entities", []map[string]interface{}{{ + "users": users, + "groups": groups, + "accounts": accounts, + }}) +} diff --git a/outscale/data_source_outscale_entities_linked_to_policy_test.go b/outscale/data_source_outscale_entities_linked_to_policy_test.go new file mode 100644 index 000000000..d71331a12 --- /dev/null +++ b/outscale/data_source_outscale_entities_linked_to_policy_test.go @@ -0,0 +1,64 @@ +package outscale + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccOthers_entities_linked_to_policy_basic(t *testing.T) { + t.Parallel() + resourceName := "data.outscale_entities_linked_to_policy.entitiesLinked" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataEntitiesLinkedConfig, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet(resourceName, "policy_entities.#"), + ), + }, + }, + }) +} + +const testAccDataEntitiesLinkedConfig = ` +resource "outscale_user" "user_01" { + user_name = "userLedGroup" + path = "/linkedUser/" + policy { + policy_orn = outscale_policy.policyEntities_01.orn + } +} +resource "outscale_user_group" "uGroupLinked" { + user_group_name = "GLinkedTestACC" + path = "/" + user { + user_name = outscale_user.user_01.user_name + path = "/linkedUser/" + } + policy { + policy_orn = outscale_policy.policyEntities_01.orn + } + depends_on = [outscale_user.user_01] +} +resource "outscale_user_group" "GroupLinkedPolicy" { + user_group_name = "GroupPolicyTestAcc" + path = "/TestPath/" + policy { + policy_orn = outscale_policy.policyEntities_01.orn + } +} +resource "outscale_policy" "policyEntities_01" { + description = "Example Entities Linked to policy" + document = "{\"Statement\": [ {\"Effect\": \"Allow\", \"Action\": [\"*\"], \"Resource\": [\"*\"]} ]}" + path = "/Okht_test/" + policy_name = "policyEntitiesLinked" +} + +data "outscale_entities_linked_to_policy" "entitiesLinked" { + policy_orn = outscale_policy.policyEntities_01.orn + depends_on = [outscale_user_group.uGroupLinked, outscale_user_group.GroupLinkedPolicy, outscale_user.user_01] +}` diff --git a/outscale/data_source_outscale_policies_linked_to_user.go b/outscale/data_source_outscale_policies_linked_to_user.go new file mode 100644 index 000000000..1159d5a56 --- /dev/null +++ b/outscale/data_source_outscale_policies_linked_to_user.go @@ -0,0 +1,90 @@ +package outscale + +import ( + "context" + "fmt" + "time" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + oscgo "github.com/outscale/osc-sdk-go/v2" + "github.com/outscale/terraform-provider-outscale/utils" +) + +func DataSourcePoliciesLinkedToUser() *schema.Resource { + return &schema.Resource{ + Read: DataSourcePoliciesLinkedToUserRead, + Schema: map[string]*schema.Schema{ + "user_name": { + Type: schema.TypeString, + Required: true, + }, + "policies": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + + "policy_name": { + Type: schema.TypeString, + Computed: true, + }, + "policy_id": { + Type: schema.TypeString, + Computed: true, + }, + "orn": { + Type: schema.TypeString, + Computed: true, + }, + "creation_date": { + Type: schema.TypeString, + Computed: true, + }, + "last_modification_date": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + }, + } +} + +func DataSourcePoliciesLinkedToUserRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*OutscaleClient).OSCAPI + req := oscgo.NewReadLinkedPoliciesRequest(d.Get("user_name").(string)) + var resp oscgo.ReadLinkedPoliciesResponse + + err := resource.Retry(2*time.Minute, func() *resource.RetryError { + rp, httpResp, err := conn.PolicyApi.ReadLinkedPolicies(context.Background()).ReadLinkedPoliciesRequest(*req).Execute() + if err != nil { + return utils.CheckThrottling(httpResp, err) + } + resp = rp + return nil + }) + + if err != nil { + return err + } + policiesList := resp.GetPolicies() + if len(policiesList) == 0 { + return fmt.Errorf("unable to find Policies linked to user: %v", d.Get("user_name").(string)) + } + d.SetId(resource.UniqueId()) + + policies := make([]map[string]interface{}, len(policiesList)) + + for i, v := range policiesList { + policy := make(map[string]interface{}) + policy["policy_name"] = v.GetPolicyName() + policy["policy_id"] = v.GetPolicyId() + policy["orn"] = v.GetOrn() + policy["creation_date"] = v.GetCreationDate() + policy["last_modification_date"] = v.GetLastModificationDate() + policies[i] = policy + } + return d.Set("policies", policies) +} diff --git a/outscale/data_source_outscale_policies_linked_to_user_group.go b/outscale/data_source_outscale_policies_linked_to_user_group.go new file mode 100644 index 000000000..3e6ae9c44 --- /dev/null +++ b/outscale/data_source_outscale_policies_linked_to_user_group.go @@ -0,0 +1,94 @@ +package outscale + +import ( + "context" + "fmt" + "time" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + oscgo "github.com/outscale/osc-sdk-go/v2" + "github.com/outscale/terraform-provider-outscale/utils" +) + +func DataSourcePoliciesLinkedToUserGroup() *schema.Resource { + return &schema.Resource{ + Read: DataSourcePoliciesLinkedToUserGroupRead, + Schema: map[string]*schema.Schema{ + "filter": dataSourceFiltersSchema(), + "user_group_name": { + Type: schema.TypeString, + Required: true, + }, + "policies": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "policy_name": { + Type: schema.TypeString, + Computed: true, + }, + "policy_id": { + Type: schema.TypeString, + Computed: true, + }, + "orn": { + Type: schema.TypeString, + Computed: true, + }, + "creation_date": { + Type: schema.TypeString, + Computed: true, + }, + "last_modification_date": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + }, + } +} + +func DataSourcePoliciesLinkedToUserGroupRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*OutscaleClient).OSCAPI + req := oscgo.ReadManagedPoliciesLinkedToUserGroupRequest{} + req.SetUserGroupName(d.Get("user_group_name").(string)) + + if filters, filtersOk := d.GetOk("filter"); filtersOk { + filterReq := buildUserGroupsFilters(filters.(*schema.Set)) + req.SetFilters(*filterReq) + } + + var resp oscgo.ReadManagedPoliciesLinkedToUserGroupResponse + err := resource.Retry(2*time.Minute, func() *resource.RetryError { + rp, httpResp, err := conn.PolicyApi.ReadManagedPoliciesLinkedToUserGroup(context.Background()).ReadManagedPoliciesLinkedToUserGroupRequest(req).Execute() + if err != nil { + return utils.CheckThrottling(httpResp, err) + } + resp = rp + return nil + }) + if err != nil { + return err + } + if _, ok := resp.GetPoliciesOk(); !ok { + return fmt.Errorf("unable to find policies linked to user group") + } + policiesResp := resp.GetPolicies() + d.SetId(resource.UniqueId()) + policies := make([]map[string]interface{}, len(policiesResp)) + for i, v := range policiesResp { + policy := make(map[string]interface{}) + policy["policy_name"] = v.GetPolicyName() + policy["policy_id"] = v.GetPolicyId() + policy["orn"] = v.GetOrn() + policy["creation_date"] = v.GetCreationDate() + policy["last_modification_date"] = v.GetLastModificationDate() + policies[i] = policy + } + + return d.Set("policies", policies) +} diff --git a/outscale/data_source_outscale_policies_linked_to_user_group_test.go b/outscale/data_source_outscale_policies_linked_to_user_group_test.go new file mode 100644 index 000000000..59095b32a --- /dev/null +++ b/outscale/data_source_outscale_policies_linked_to_user_group_test.go @@ -0,0 +1,50 @@ +package outscale + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccOthers_policies_linked_to_user_group_basic(t *testing.T) { + t.Parallel() + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataPoliciesLinkedConfig, + }, + }, + }) +} + +const testAccDataPoliciesToGroupConfig = ` +resource "outscale_user_group" "userGroupPolicies01" { + user_group_name = "usergroup" + path = "/policiesGroup/" + policy { + policy_orn = outscale_policy.groupLinked_01.orn + } + policy { + policy_orn = outscale_policy.groupLinked_02.orn + } +} + +resource "outscale_policy" "groupLinked_01" { + description = "Example Linked to user_group" + document = "{\"Statement\": [ {\"Effect\": \"Allow\", \"Action\": [\"*\"], \"Resource\": [\"*\"]} ]}" + path = "/TestAllOK/" + policy_name = "policiesGroupLinked" +} +resource "outscale_policy" "groupLinked_02" { + description = "Example Linked policy to group" + document = "{\"Statement\": [ {\"Effect\": \"Deny\", \"Action\": [\"*\"], \"Resource\": [\"*\"]} ]}" + path = "/Okhtgroup/" + policy_name = "DenyPolicy" +} +data "outscale_policies_linked_to_user_group" "policiesLinkToGroup" { + user_group_name = outscale_user_group.userGroupPolicies01.user_group_name + depends_on = [outscale_user_group.userGroupPolicies01] +} +` diff --git a/outscale/data_source_outscale_policies_linked_to_user_test.go b/outscale/data_source_outscale_policies_linked_to_user_test.go new file mode 100644 index 000000000..ddbf551c3 --- /dev/null +++ b/outscale/data_source_outscale_policies_linked_to_user_test.go @@ -0,0 +1,54 @@ +package outscale + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccOthers_policies_linked_to_user_basic(t *testing.T) { + t.Parallel() + resourceName := "data.outscale_policies_linked_to_user.policiesLinkedToUser" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataPoliciesLinkedConfig, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet(resourceName, "policies.#"), + ), + }, + }, + }) +} + +const testAccDataPoliciesLinkedConfig = ` +resource "outscale_user" "userPolicies01" { + user_name = "userLedGroup" + path = "/policiesUser/" + policy { + policy_orn = outscale_policy.policyLinked_01.orn + } + policy { + policy_orn = outscale_policy.policyLinked_02.orn + } +} + +resource "outscale_policy" "policyLinked_01" { + description = "Example Linked to user" + document = "{\"Statement\": [ {\"Effect\": \"Allow\", \"Action\": [\"*\"], \"Resource\": [\"*\"]} ]}" + path = "/Allow_est/" + policy_name = "policiesLinked" +} +resource "outscale_policy" "policyLinked_02" { + description = "Example Linked policy to user" + document = "{\"Statement\": [ {\"Effect\": \"Deny\", \"Action\": [\"*\"], \"Resource\": [\"*\"]} ]}" + path = "/OkhtTest/" + policy_name = "policyStopAll" +} +data "outscale_policies_linked_to_user" "policiesLinkedToUser" { + user_name = outscale_user.userPolicies01.user_name + depends_on = [outscale_user.userPolicies01] +}` diff --git a/outscale/data_source_outscale_user_groups_per_user.go b/outscale/data_source_outscale_user_groups_per_user.go new file mode 100644 index 000000000..7ef9ba067 --- /dev/null +++ b/outscale/data_source_outscale_user_groups_per_user.go @@ -0,0 +1,102 @@ +package outscale + +import ( + "context" + "fmt" + "time" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + oscgo "github.com/outscale/osc-sdk-go/v2" + "github.com/outscale/terraform-provider-outscale/utils" +) + +func DataSourceUserGroupsPerUser() *schema.Resource { + return &schema.Resource{ + Read: DataSourceUserGroupsPerUserRead, + Schema: map[string]*schema.Schema{ + "user_name": { + Type: schema.TypeString, + Required: true, + }, + "user_path": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "user_groups": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "user_group_name": { + Type: schema.TypeString, + Computed: true, + }, + "path": { + Type: schema.TypeString, + Computed: true, + }, + "user_group_id": { + Type: schema.TypeString, + Computed: true, + }, + "orn": { + Type: schema.TypeString, + Computed: true, + }, + "creation_date": { + Type: schema.TypeString, + Computed: true, + }, + "last_modification_date": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + }, + } +} + +func DataSourceUserGroupsPerUserRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*OutscaleClient).OSCAPI + + req := oscgo.NewReadUserGroupsPerUserRequest(d.Get("user_name").(string)) + if userPath := d.Get("user_path").(string); userPath != "" { + req.SetUserPath(userPath) + } + var resp oscgo.ReadUserGroupsPerUserResponse + err := resource.Retry(2*time.Minute, func() *resource.RetryError { + rp, httpResp, err := conn.UserGroupApi.ReadUserGroupsPerUser(context.Background()).ReadUserGroupsPerUserRequest(*req).Execute() + if err != nil { + return utils.CheckThrottling(httpResp, err) + } + resp = rp + return nil + }) + + if err != nil { + return err + } + + if _, ok := resp.GetUserGroupsOk(); !ok { + return fmt.Errorf("unable to find user groups") + } + d.SetId(resource.UniqueId()) + userGps := resp.GetUserGroups() + userGroups := make([]map[string]interface{}, len(userGps)) + + for i, v := range userGps { + userGroup := make(map[string]interface{}) + userGroup["user_group_name"] = v.GetName() + userGroup["user_group_id"] = v.GetUserGroupId() + userGroup["path"] = v.GetPath() + userGroup["orn"] = v.GetOrn() + userGroup["creation_date"] = v.GetCreationDate() + userGroup["last_modification_date"] = v.GetLastModificationDate() + userGroups[i] = userGroup + } + return d.Set("user_groups", userGroups) +} diff --git a/outscale/data_source_outscale_user_groups_per_user_test.go b/outscale/data_source_outscale_user_groups_per_user_test.go new file mode 100644 index 000000000..67a3d1620 --- /dev/null +++ b/outscale/data_source_outscale_user_groups_per_user_test.go @@ -0,0 +1,51 @@ +package outscale + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccOthers_user_groups_per_user_basic(t *testing.T) { + t.Parallel() + resourceName := "data.outscale_user_groups_per_user.groupList" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataUserGroupsPerUserBasicConfig, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet(resourceName, "user_groups.#"), + ), + }, + }, + }) +} + +const testAccDataUserGroupsPerUserBasicConfig = ` +resource "outscale_user" "userForGroup01" { + user_name = "user1_per_group" + path = "/groupsPerUser/" +} + +resource "outscale_user_group" "uGroupFORuser" { + user_group_name = "Group1TestACC" + path = "/" + user { + user_name = outscale_user.userForGroup01.user_name + path = "/groupsPerUser/" + } +} +resource "outscale_user_group" "uGroup2FORuser" { + user_group_name = "Group02TestACC" + path = "/TestPath/" + user { + user_name = outscale_user.userForGroup01.user_name + } +} +data "outscale_user_groups_per_user" "groupList" { + user_name = outscale_user.userForGroup01.user_name + depends_on =[outscale_user_group.uGroup2FORuser] +}` From b06f49c95c4664940415ac61ed4ed5b0888b73df Mon Sep 17 00:00:00 2001 From: Thiery Ouattara Date: Wed, 11 Dec 2024 15:46:44 +0000 Subject: [PATCH 6/9] Add EIM resources and data_sources to provider --- outscale/provider.go | 164 +++++++++++++++++++++++-------------------- 1 file changed, 89 insertions(+), 75 deletions(-) diff --git a/outscale/provider.go b/outscale/provider.go index bc474ccb8..d4a38f46f 100644 --- a/outscale/provider.go +++ b/outscale/provider.go @@ -130,83 +130,97 @@ func Provider() *schema.Provider { "outscale_api_access_rule": ResourceOutscaleApiAccessRule(), "outscale_api_access_policy": ResourceOutscaleApiAccessPolicy(), "outscale_main_route_table_link": resourceLinkMainRouteTable(), + "outscale_user": ResourceOutscaleUser(), + "outscale_user_group": ResourceUserGroup(), + "outscale_policy": ResourceOutscalePolicy(), + "outscale_policy_version": ResourcePolicyVersion(), }, DataSourcesMap: map[string]*schema.Resource{ - "outscale_vm": DataSourceOutscaleVM(), - "outscale_vms": DataSourceOutscaleVMS(), - "outscale_security_group": DataSourceOutscaleSecurityGroup(), - "outscale_security_groups": DataSourceOutscaleSecurityGroups(), - "outscale_image": DataSourceOutscaleImage(), - "outscale_images": DataSourceOutscaleImages(), - "outscale_tag": DataSourceOutscaleTag(), - "outscale_tags": DataSourceOutscaleTags(), - "outscale_public_ip": DataSourceOutscalePublicIP(), - "outscale_public_ips": DataSourceOutscalePublicIPS(), - "outscale_volume": DataSourceOutscaleVolume(), - "outscale_volumes": DataSourceOutscaleVolumes(), - "outscale_nat_service": DataSourceOutscaleNatService(), - "outscale_nat_services": DataSourceOutscaleNatServices(), - "outscale_keypair": DataSourceOutscaleKeyPair(), - "outscale_keypairs": DataSourceOutscaleKeyPairs(), - "outscale_vm_state": DataSourceOutscaleVMState(), - "outscale_vm_states": DataSourceOutscaleVMStates(), - "outscale_internet_service": DataSourceOutscaleInternetService(), - "outscale_internet_services": DataSourceOutscaleInternetServices(), - "outscale_subnet": DataSourceOutscaleSubnet(), - "outscale_subnets": DataSourceOutscaleSubnets(), - "outscale_net": DataSourceOutscaleVpc(), - "outscale_nets": DataSourceOutscaleVpcs(), - "outscale_net_attributes": DataSourceOutscaleVpcAttr(), - "outscale_route_table": DataSourceOutscaleRouteTable(), - "outscale_route_tables": DataSourceOutscaleRouteTables(), - "outscale_snapshot": DataSourceOutscaleSnapshot(), - "outscale_snapshots": DataSourceOutscaleSnapshots(), - "outscale_net_peering": DataSourceOutscaleLinPeeringConnection(), - "outscale_net_peerings": DataSourceOutscaleLinPeeringsConnection(), - "outscale_nics": DataSourceOutscaleNics(), - "outscale_nic": DataSourceOutscaleNic(), - "outscale_client_gateway": DataSourceOutscaleClientGateway(), - "outscale_client_gateways": DataSourceOutscaleClientGateways(), - "outscale_virtual_gateway": DataSourceOutscaleVirtualGateway(), - "outscale_virtual_gateways": DataSourceOutscaleVirtualGateways(), - "outscale_vpn_connection": DataSourceOutscaleVPNConnection(), - "outscale_vpn_connections": DataSourceOutscaleVPNConnections(), - "outscale_access_key": DataSourceOutscaleAccessKey(), - "outscale_access_keys": DataSourceOutscaleAccessKeys(), - "outscale_dhcp_option": DataSourceOutscaleDHCPOption(), - "outscale_dhcp_options": DataSourceOutscaleDHCPOptions(), - "outscale_load_balancer": DataSourceOutscaleLoadBalancer(), - "outscale_load_balancer_listener_rule": DataSourceOutscaleLoadBalancerLDRule(), - "outscale_load_balancer_listener_rules": DataSourceOutscaleLoadBalancerLDRules(), - "outscale_load_balancer_tags": DataSourceOutscaleLBUTags(), - "outscale_load_balancer_vm_health": DataSourceOutscaleLoadBalancerVmsHeals(), - "outscale_load_balancers": DataSourceOutscaleLoadBalancers(), - "outscale_vm_types": DataSourceOutscaleVMTypes(), - "outscale_net_access_point": DataSourceOutscaleNetAccessPoint(), - "outscale_net_access_points": DataSourceOutscaleNetAccessPoints(), - "outscale_flexible_gpu": DataSourceOutscaleFlexibleGpu(), - "outscale_flexible_gpus": DataSourceOutscaleFlexibleGpus(), - "outscale_subregions": DataSourceOutscaleSubregions(), - "outscale_regions": DataSourceOutscaleRegions(), - "outscale_net_access_point_services": DataSourceOutscaleNetAccessPointServices(), - "outscale_flexible_gpu_catalog": DataSourceOutscaleFlexibleGpuCatalog(), - "outscale_product_type": DataSourceOutscaleProductType(), - "outscale_product_types": DataSourceOutscaleProductTypes(), - "outscale_quotas": DataSourceOutscaleQuotas(), - "outscale_image_export_task": DataSourceOutscaleImageExportTask(), - "outscale_image_export_tasks": DataSourceOutscaleImageExportTasks(), - "outscale_server_certificate": DataSourceOutscaleServerCertificate(), - "outscale_server_certificates": DataSourceOutscaleServerCertificates(), - "outscale_snapshot_export_task": DataSourceOutscaleSnapshotExportTask(), - "outscale_snapshot_export_tasks": DataSourceOutscaleSnapshotExportTasks(), - "outscale_ca": DataSourceOutscaleCa(), - "outscale_cas": DataSourceOutscaleCas(), - "outscale_api_access_rule": DataSourceOutscaleApiAccessRule(), - "outscale_api_access_rules": DataSourceOutscaleApiAccessRules(), - "outscale_api_access_policy": DataSourceOutscaleApiAccessPolicy(), - "outscale_public_catalog": DataSourceOutscalePublicCatalog(), - "outscale_account": DataSourceAccount(), - "outscale_accounts": DataSourceAccounts(), + "outscale_vm": DataSourceOutscaleVM(), + "outscale_vms": DataSourceOutscaleVMS(), + "outscale_security_group": DataSourceOutscaleSecurityGroup(), + "outscale_security_groups": DataSourceOutscaleSecurityGroups(), + "outscale_image": DataSourceOutscaleImage(), + "outscale_images": DataSourceOutscaleImages(), + "outscale_tag": DataSourceOutscaleTag(), + "outscale_tags": DataSourceOutscaleTags(), + "outscale_public_ip": DataSourceOutscalePublicIP(), + "outscale_public_ips": DataSourceOutscalePublicIPS(), + "outscale_volume": DataSourceOutscaleVolume(), + "outscale_volumes": DataSourceOutscaleVolumes(), + "outscale_nat_service": DataSourceOutscaleNatService(), + "outscale_nat_services": DataSourceOutscaleNatServices(), + "outscale_keypair": DataSourceOutscaleKeyPair(), + "outscale_keypairs": DataSourceOutscaleKeyPairs(), + "outscale_vm_state": DataSourceOutscaleVMState(), + "outscale_vm_states": DataSourceOutscaleVMStates(), + "outscale_internet_service": DataSourceOutscaleInternetService(), + "outscale_internet_services": DataSourceOutscaleInternetServices(), + "outscale_subnet": DataSourceOutscaleSubnet(), + "outscale_subnets": DataSourceOutscaleSubnets(), + "outscale_net": DataSourceOutscaleVpc(), + "outscale_nets": DataSourceOutscaleVpcs(), + "outscale_net_attributes": DataSourceOutscaleVpcAttr(), + "outscale_route_table": DataSourceOutscaleRouteTable(), + "outscale_route_tables": DataSourceOutscaleRouteTables(), + "outscale_snapshot": DataSourceOutscaleSnapshot(), + "outscale_snapshots": DataSourceOutscaleSnapshots(), + "outscale_net_peering": DataSourceOutscaleLinPeeringConnection(), + "outscale_net_peerings": DataSourceOutscaleLinPeeringsConnection(), + "outscale_nics": DataSourceOutscaleNics(), + "outscale_nic": DataSourceOutscaleNic(), + "outscale_client_gateway": DataSourceOutscaleClientGateway(), + "outscale_client_gateways": DataSourceOutscaleClientGateways(), + "outscale_virtual_gateway": DataSourceOutscaleVirtualGateway(), + "outscale_virtual_gateways": DataSourceOutscaleVirtualGateways(), + "outscale_vpn_connection": DataSourceOutscaleVPNConnection(), + "outscale_vpn_connections": DataSourceOutscaleVPNConnections(), + "outscale_access_key": DataSourceOutscaleAccessKey(), + "outscale_access_keys": DataSourceOutscaleAccessKeys(), + "outscale_dhcp_option": DataSourceOutscaleDHCPOption(), + "outscale_dhcp_options": DataSourceOutscaleDHCPOptions(), + "outscale_load_balancer": DataSourceOutscaleLoadBalancer(), + "outscale_load_balancer_listener_rule": DataSourceOutscaleLoadBalancerLDRule(), + "outscale_load_balancer_listener_rules": DataSourceOutscaleLoadBalancerLDRules(), + "outscale_load_balancer_tags": DataSourceOutscaleLBUTags(), + "outscale_load_balancer_vm_health": DataSourceOutscaleLoadBalancerVmsHeals(), + "outscale_load_balancers": DataSourceOutscaleLoadBalancers(), + "outscale_vm_types": DataSourceOutscaleVMTypes(), + "outscale_net_access_point": DataSourceOutscaleNetAccessPoint(), + "outscale_net_access_points": DataSourceOutscaleNetAccessPoints(), + "outscale_flexible_gpu": DataSourceOutscaleFlexibleGpu(), + "outscale_flexible_gpus": DataSourceOutscaleFlexibleGpus(), + "outscale_subregions": DataSourceOutscaleSubregions(), + "outscale_regions": DataSourceOutscaleRegions(), + "outscale_net_access_point_services": DataSourceOutscaleNetAccessPointServices(), + "outscale_flexible_gpu_catalog": DataSourceOutscaleFlexibleGpuCatalog(), + "outscale_product_type": DataSourceOutscaleProductType(), + "outscale_product_types": DataSourceOutscaleProductTypes(), + "outscale_quotas": DataSourceOutscaleQuotas(), + "outscale_image_export_task": DataSourceOutscaleImageExportTask(), + "outscale_image_export_tasks": DataSourceOutscaleImageExportTasks(), + "outscale_server_certificate": DataSourceOutscaleServerCertificate(), + "outscale_server_certificates": DataSourceOutscaleServerCertificates(), + "outscale_snapshot_export_task": DataSourceOutscaleSnapshotExportTask(), + "outscale_snapshot_export_tasks": DataSourceOutscaleSnapshotExportTasks(), + "outscale_ca": DataSourceOutscaleCa(), + "outscale_cas": DataSourceOutscaleCas(), + "outscale_api_access_rule": DataSourceOutscaleApiAccessRule(), + "outscale_api_access_rules": DataSourceOutscaleApiAccessRules(), + "outscale_api_access_policy": DataSourceOutscaleApiAccessPolicy(), + "outscale_public_catalog": DataSourceOutscalePublicCatalog(), + "outscale_account": DataSourceAccount(), + "outscale_accounts": DataSourceAccounts(), + "outscale_users": DataSourceUsers(), + "outscale_user": DataSourceUser(), + "outscale_user_groups": DataSourceUserGroups(), + "outscale_user_groups_per_user": DataSourceUserGroupsPerUser(), + "outscale_user_group": DataSourceUserGroup(), + "outscale_policy": DataSourcePolicy(), + "outscale_policies": DataSourcePolicies(), + "outscale_policies_linked_to_user": DataSourcePoliciesLinkedToUser(), + "outscale_entities_linked_to_policy": DataSourceEntitiesLinkedToPolicy(), + "outscale_policies_linked_to_user_group": DataSourcePoliciesLinkedToUserGroup(), }, ConfigureFunc: providerConfigureClient, From 63f0dfcaac8cbe693e37a6c3924966ea4c807721 Mon Sep 17 00:00:00 2001 From: Thiery Ouattara Date: Fri, 13 Dec 2024 09:09:52 +0000 Subject: [PATCH 7/9] Fix osc profile configuration --- outscale/config.go | 20 ++++++------ outscale/framework_config.go | 34 +++++++++----------- outscale/framework_provider.go | 44 ++++++++++++------------- outscale/framework_provider_test.go | 8 ++--- outscale/provider.go | 50 ++++++++++++++--------------- utils/utils.go | 1 + 6 files changed, 77 insertions(+), 80 deletions(-) diff --git a/outscale/config.go b/outscale/config.go index 81865ce3b..2886e56e1 100644 --- a/outscale/config.go +++ b/outscale/config.go @@ -13,16 +13,16 @@ import ( // Config ... type Config struct { - AccessKeyID string - SecretKeyID string - Region string - TokenID string - Endpoints map[string]interface{} - X509CertPath string - X509KeyPath string - Insecure bool - ConfigFilePath string - Profile string + AccessKeyID string + SecretKeyID string + Region string + TokenID string + Endpoints map[string]interface{} + X509CertPath string + X509KeyPath string + Insecure bool + ConfigFile string + Profile string } // OutscaleClient client diff --git a/outscale/framework_config.go b/outscale/framework_config.go index fb3a7a887..fa2d06a44 100644 --- a/outscale/framework_config.go +++ b/outscale/framework_config.go @@ -4,7 +4,6 @@ import ( "context" "crypto/tls" "fmt" - "io/ioutil" "net/http" "os" "strings" @@ -25,7 +24,7 @@ type OutscaleClient_fw struct { // Client ... func (c *frameworkProvider) Client_fw(ctx context.Context, data *ProviderModel, diags *diag.Diagnostics) (*OutscaleClient_fw, error) { - ok, err := IsProfileSet(data) + ok, err := isProfileSet(data) if err != nil { return nil, err } @@ -75,39 +74,38 @@ func (c *frameworkProvider) Client_fw(ctx context.Context, data *ProviderModel, return client, nil } -func IsProfileSet(data *ProviderModel) (bool, error) { +func isProfileSet(data *ProviderModel) (bool, error) { isProfSet := false if profileName, ok := os.LookupEnv("OSC_PROFILE"); ok || !data.Profile.IsNull() { if data.Profile.ValueString() != "" { profileName = data.Profile.ValueString() } - var profilePath string - if envPath, ok := os.LookupEnv("OSC_CONFIG_FILE"); ok || !data.ConfigFilePath.IsNull() { - if data.ConfigFilePath.ValueString() != "" { - profilePath = data.ConfigFilePath.ValueString() + var configFilePath string + if envPath, ok := os.LookupEnv("OSC_CONFIG_FILE"); ok || !data.ConfigFile.IsNull() { + if data.ConfigFile.ValueString() != "" { + configFilePath = data.ConfigFile.ValueString() } else { - profilePath = envPath + configFilePath = envPath } - if profilePath == "" { - homePath, err := os.UserHomeDir() - if err != nil { - return isProfSet, err - } - profilePath = homePath + "/.osc/config.json" + } else { + homePath, err := os.UserHomeDir() + if err != nil { + return isProfSet, err } + configFilePath = homePath + utils.SuffixConfigFilePath } - jsonFile, err := ioutil.ReadFile(profilePath) + jsonFile, err := os.ReadFile(configFilePath) if err != nil { - return isProfSet, err + return isProfSet, fmt.Errorf("%v \n Connot found configue file: %v", err, configFilePath) } profile := gjson.GetBytes(jsonFile, profileName) if !gjson.Valid(profile.String()) { - return isProfSet, fmt.Errorf("Invalid json profile file") + return isProfSet, fmt.Errorf("invalid json profile file") } if !profile.Get("access_key").Exists() || !profile.Get("secret_key").Exists() { - return isProfSet, fmt.Errorf("Profile 'access_key' or 'secret_key' are not defined!") + return isProfSet, fmt.Errorf("profile 'access_key' or 'secret_key' are not defined! ") } setProfile(data, profile) isProfSet = true diff --git a/outscale/framework_provider.go b/outscale/framework_provider.go index 8c2927ed8..cf66141a1 100644 --- a/outscale/framework_provider.go +++ b/outscale/framework_provider.go @@ -22,28 +22,28 @@ func New(version string) provider.Provider { } type frameworkProvider struct { - accessKeyId types.String - secretKeyId types.String - region types.String - endpoints []Endpoints - x509CertPath string - x509KeyPath string - configFilePath string - insecure bool - profile string - version string + accessKeyId types.String + secretKeyId types.String + region types.String + endpoints []Endpoints + x509CertPath string + x509KeyPath string + configFile string + insecure bool + profile string + version string } type ProviderModel struct { - AccessKeyId types.String `tfsdk:"access_key_id"` - SecretKeyId types.String `tfsdk:"secret_key_id"` - Region types.String `tfsdk:"region"` - Endpoints []Endpoints `tfsdk:"endpoints"` - X509CertPath types.String `tfsdk:"x509_cert_path"` - X509KeyPath types.String `tfsdk:"x509_key_path"` - ConfigFilePath types.String `tfsdk:"config_file_path"` - Profile types.String `tfsdk:"profile"` - Insecure types.Bool `tfsdk:"insecure"` + AccessKeyId types.String `tfsdk:"access_key_id"` + SecretKeyId types.String `tfsdk:"secret_key_id"` + Region types.String `tfsdk:"region"` + Endpoints []Endpoints `tfsdk:"endpoints"` + X509CertPath types.String `tfsdk:"x509_cert_path"` + X509KeyPath types.String `tfsdk:"x509_key_path"` + ConfigFile types.String `tfsdk:"config_file"` + Profile types.String `tfsdk:"profile"` + Insecure types.Bool `tfsdk:"insecure"` } type Endpoints struct { @@ -91,7 +91,7 @@ func (p *frameworkProvider) Schema(ctx context.Context, req provider.SchemaReque Optional: true, Description: "The path to your x509 key", }, - "config_file_path": schema.StringAttribute{ + "config_file": schema.StringAttribute{ Optional: true, Description: "The path to your configuration file in which you have defined your credentials.", }, @@ -161,9 +161,9 @@ func (p *frameworkProvider) Configure(ctx context.Context, req provider.Configur "Either target apply the source of the value first, set the value statically in the configuration, or use the 'OSC_X509_CLIENT_KEY or OUTSCALE_X509KEY' environment variable.", ) } - if config.ConfigFilePath.IsUnknown() { + if config.ConfigFile.IsUnknown() { resp.Diagnostics.AddAttributeError( - path.Root("config_file_path"), + path.Root("config_file"), "Unknown Outscale API ConfigFilePath", "The provider cannot create the Outscale API client as there is an unknown configuration value for the Outscale API profile. "+ "Either target apply the source of the value first, set the value statically in the configuration, or use the 'OSC_CONFIG_FILE' environment variable.", diff --git a/outscale/framework_provider_test.go b/outscale/framework_provider_test.go index 31250c838..3e5ea504b 100644 --- a/outscale/framework_provider_test.go +++ b/outscale/framework_provider_test.go @@ -91,10 +91,10 @@ func TestDataSource_UpgradeFromVersion(t *testing.T) { } const fwtestAccDataSourceOutscaleQuotaConfig = ` - data "outscale_quota" "lbuquota1" { - filter { - name = "quota_names" - values = ["lb_listeners_limit"] + data "outscale_quota" "lbuquota1" { + filter { + name = "quota_names" + values = ["lb_listeners_limit"] } } ` diff --git a/outscale/provider.go b/outscale/provider.go index d4a38f46f..7a9362bef 100644 --- a/outscale/provider.go +++ b/outscale/provider.go @@ -2,7 +2,6 @@ package outscale import ( "fmt" - "io/ioutil" "os" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -60,7 +59,7 @@ func Provider() *schema.Provider { Optional: true, Description: "The path to your x509 key", }, - "config_file_path": { + "config_file": { Type: schema.TypeString, Optional: true, Description: "The path to your configuration file in which you have defined your credentials.", @@ -229,15 +228,15 @@ func Provider() *schema.Provider { func providerConfigureClient(d *schema.ResourceData) (interface{}, error) { config := Config{ - AccessKeyID: d.Get("access_key_id").(string), - SecretKeyID: d.Get("secret_key_id").(string), - Region: d.Get("region").(string), - Endpoints: make(map[string]interface{}), - X509CertPath: d.Get("x509_cert_path").(string), - X509KeyPath: d.Get("x509_key_path").(string), - ConfigFilePath: d.Get("config_file_path").(string), - Profile: d.Get("profile").(string), - Insecure: d.Get("insecure").(bool), + AccessKeyID: d.Get("access_key_id").(string), + SecretKeyID: d.Get("secret_key_id").(string), + Region: d.Get("region").(string), + Endpoints: make(map[string]interface{}), + X509CertPath: d.Get("x509_cert_path").(string), + X509KeyPath: d.Get("x509_key_path").(string), + ConfigFile: d.Get("config_file").(string), + Profile: d.Get("profile").(string), + Insecure: d.Get("insecure").(bool), } endpointsSet := d.Get("endpoints").(*schema.Set) for _, endpointsSetI := range endpointsSet.List() { @@ -263,32 +262,31 @@ func IsOldProfileSet(conf *Config) (bool, error) { profileName = conf.Profile } - var profilePath string - if envPath, ok := os.LookupEnv("OSC_CONFIG_FILE"); ok || conf.ConfigFilePath != "" { - if conf.ConfigFilePath != "" { - profilePath = conf.ConfigFilePath + var configFilePath string + if envPath, ok := os.LookupEnv("OSC_CONFIG_FILE"); ok || conf.ConfigFile != "" { + if conf.ConfigFile != "" { + configFilePath = conf.ConfigFile } else { - profilePath = envPath + configFilePath = envPath } - if profilePath == "" { - homePath, err := os.UserHomeDir() - if err != nil { - return isProfSet, err - } - profilePath = homePath + "/.osc/config.json" + } else { + homePath, err := os.UserHomeDir() + if err != nil { + return isProfSet, err } + configFilePath = homePath + utils.SuffixConfigFilePath } - jsonFile, err := ioutil.ReadFile(profilePath) + jsonFile, err := os.ReadFile(configFilePath) if err != nil { - return isProfSet, err + return isProfSet, fmt.Errorf("%v \nConnot found configue file: %v", err, configFilePath) } profile := gjson.GetBytes(jsonFile, profileName) if !gjson.Valid(profile.String()) { - return isProfSet, fmt.Errorf("Invalid json profile file") + return isProfSet, fmt.Errorf("invalid json profile file") } if !profile.Get("access_key").Exists() || !profile.Get("secret_key").Exists() { - return isProfSet, fmt.Errorf("Profile 'access_key' or 'secret_key' are not defined!") + return isProfSet, fmt.Errorf("profile 'access_key' or 'secret_key' are not defined! ") } setOldProfile(conf, profile) isProfSet = true diff --git a/utils/utils.go b/utils/utils.go index 8dc31be3a..34c874bb4 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -34,6 +34,7 @@ const ( MaxSize int = 14901 LinkedPolicyNotFound string = "5102" InvalidState string = "InvalidState" + SuffixConfigFilePath string = "/.osc/config.json" pathRegex string = "^(/[a-zA-Z0-9/_]+/)" pathError string = "path must begin and end with '/' and contain only alphanumeric characters and/or '/', '_' characters" VolumeIOPSError string = ` From b3c2994a2e156fa545a1df23c75c7941ffc03607 Mon Sep 17 00:00:00 2001 From: Thiery Ouattara Date: Fri, 13 Dec 2024 09:10:32 +0000 Subject: [PATCH 8/9] Update go module --- go.mod | 8 ++++---- go.sum | 25 ++++++++++++++----------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/go.mod b/go.mod index 3986d7fce..6cb6ac8dc 100644 --- a/go.mod +++ b/go.mod @@ -58,12 +58,12 @@ require ( github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect github.com/zclconf/go-cty v1.14.0 // indirect - golang.org/x/crypto v0.23.0 // indirect - golang.org/x/mod v0.12.0 // indirect + golang.org/x/crypto v0.31.0 // indirect + golang.org/x/mod v0.17.0 // indirect golang.org/x/net v0.25.0 // indirect golang.org/x/oauth2 v0.24.0 // indirect - golang.org/x/sys v0.20.0 // indirect - golang.org/x/text v0.15.0 // indirect + golang.org/x/sys v0.28.0 // indirect + golang.org/x/text v0.21.0 // indirect google.golang.org/appengine v1.6.8 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240221002015-b0ce06bbee7c // indirect google.golang.org/grpc v1.62.0 // indirect diff --git a/go.sum b/go.sum index a6e626b70..e05076ff3 100644 --- a/go.sum +++ b/go.sum @@ -185,12 +185,12 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.3.1-0.20221117191849-2c476679df9a/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4= golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU= -golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI= -golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8= +golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U= +golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= -golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc= -golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA= +golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= @@ -211,6 +211,8 @@ golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ= +golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -227,15 +229,15 @@ golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y= -golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA= +golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U= -golang.org/x/term v0.20.0 h1:VnkxpohqXaOBYJtBmEppKUG6mXpi+4O6purfc2+sMhw= -golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY= +golang.org/x/term v0.27.0 h1:WP60Sv1nlK1T6SupCHbXzSaN0b9wUmsPoRS9b61A23Q= +golang.org/x/term v0.27.0/go.mod h1:iMsnZpn0cago0GOrHO2+Y7u7JPn5AylBrcoWkElMTSM= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= @@ -244,13 +246,14 @@ golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= -golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk= -golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo= +golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= -golang.org/x/tools v0.6.0 h1:BOw41kyTf3PuCW1pVQf8+Cyg8pMlkYB1oo9iJ6D/lKM= golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= +golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg= +golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= From 76a7a00be5795ae8c7b8c155d26f2d97339f8228 Mon Sep 17 00:00:00 2001 From: outscale-mzi Date: Thu, 19 Dec 2024 10:18:03 +0100 Subject: [PATCH 9/9] add eim tests and update test_provider_oapi --- ...listener_rule_datasource_attributes_ok.ref | 2 +- ...r_listener_rule_resource_attributes_ok.ref | 2 +- ...r_listener_rule_resource_attributes_ok.ref | 4 +- ...istener_rules_datasource_attributes_ok.ref | 2 +- ...cer_vm_health_datasource_attributes_ok.ref | 2 +- ...ad_balancer_vms_resource_attributes_ok.ref | 2 +- ...oad_balancer_vms_resource_remove_vm_ok.ref | 4 +- .../data/policies_files/policy.json | 13 + .../data/policies_files/policy11.json | 13 + .../data/policies_files/policy12.json | 13 + .../data/policies_files/policy2.json | 13 + .../data/policies_files/policyV1.json | 13 + .../data/policies_files/policyV2.json | 13 + .../data/policies_files/policyV3.json | 9 + .../data/policies_files/policy_RO.json | 13 + .../policy_ReadAccountConsumption.json | 13 + .../step1.user_resource_attributes_ok.ref | 83 +++++ .../step1.user_resource_attributes_ok.tf | 18 + .../step2.user_resource_update_ok.ref | 83 +++++ .../step2.user_resource_update_ok.tf | 18 + .../step3.user_resource_update_ak_ok.ref | 83 +++++ .../step3.user_resource_update_ak_ok.tf | 18 + ...tep1.user_group_resource_attributes_ok.ref | 34 ++ ...step1.user_group_resource_attributes_ok.tf | 5 + .../step2.user_group_resource_update_ok.ref | 34 ++ .../step2.user_group_resource_update_ok.tf | 5 + .../step1.policy_resource_attributes_ok.ref | 64 ++++ .../step1.policy_resource_attributes_ok.tf | 11 + ....policy_version_resource_attributes_ok.ref | 89 +++++ ...1.policy_version_resource_attributes_ok.tf | 18 + .../step1.all_iam_resources_attributes_ok.ref | 347 ++++++++++++++++++ .../step1.all_iam_resources_attributes_ok.tf | 90 +++++ .../step2.all_iam_resources_update_ok.ref | 347 ++++++++++++++++++ .../step2.all_iam_resources_update_ok.tf | 90 +++++ .../step2.user_datasource_after_update_ok.ref | 134 +++++++ .../step2.user_datasource_after_update_ok.tf | 45 +++ .../step1.users_datasource_attributes_ok.ref | 90 +++++ .../step1.users_datasource_attributes_ok.tf | 19 + ...p1.user_group_datasource_attributes_ok.ref | 138 +++++++ ...ep1.user_group_datasource_attributes_ok.tf | 37 ++ ...1.user_groups_datasource_attributes_ok.ref | 183 +++++++++ ...p1.user_groups_datasource_attributes_ok.tf | 49 +++ .../step1.policy_datasource_attributes_ok.ref | 161 ++++++++ .../step1.policy_datasource_attributes_ok.tf | 31 ++ ...tep1.policies_datasource_attributes_ok.ref | 191 ++++++++++ ...step1.policies_datasource_attributes_ok.tf | 41 +++ ...inked_to_user_datasource_attributes_ok.ref | 140 +++++++ ...linked_to_user_datasource_attributes_ok.tf | 31 ++ ...to_user_group_datasource_attributes_ok.ref | 142 +++++++ ..._to_user_group_datasource_attributes_ok.tf | 30 ++ ...ked_to_policy_datasource_attributes_ok.ref | 250 +++++++++++++ ...nked_to_policy_datasource_attributes_ok.tf | 71 ++++ ...oups_per_user_datasource_attributes_ok.ref | 121 ++++++ ...roups_per_user_datasource_attributes_ok.tf | 33 ++ tests/qa_provider_oapi/test_provider_oapi.py | 3 +- 55 files changed, 3498 insertions(+), 10 deletions(-) create mode 100644 tests/qa_provider_oapi/data/policies_files/policy.json create mode 100644 tests/qa_provider_oapi/data/policies_files/policy11.json create mode 100644 tests/qa_provider_oapi/data/policies_files/policy12.json create mode 100644 tests/qa_provider_oapi/data/policies_files/policy2.json create mode 100644 tests/qa_provider_oapi/data/policies_files/policyV1.json create mode 100644 tests/qa_provider_oapi/data/policies_files/policyV2.json create mode 100644 tests/qa_provider_oapi/data/policies_files/policyV3.json create mode 100644 tests/qa_provider_oapi/data/policies_files/policy_RO.json create mode 100644 tests/qa_provider_oapi/data/policies_files/policy_ReadAccountConsumption.json create mode 100644 tests/qa_provider_oapi/data/tests_iam_resources/TF001_user_resource_with_aksk_attributes_ok/step1.user_resource_attributes_ok.ref create mode 100644 tests/qa_provider_oapi/data/tests_iam_resources/TF001_user_resource_with_aksk_attributes_ok/step1.user_resource_attributes_ok.tf create mode 100644 tests/qa_provider_oapi/data/tests_iam_resources/TF001_user_resource_with_aksk_attributes_ok/step2.user_resource_update_ok.ref create mode 100644 tests/qa_provider_oapi/data/tests_iam_resources/TF001_user_resource_with_aksk_attributes_ok/step2.user_resource_update_ok.tf create mode 100644 tests/qa_provider_oapi/data/tests_iam_resources/TF001_user_resource_with_aksk_attributes_ok/step3.user_resource_update_ak_ok.ref create mode 100644 tests/qa_provider_oapi/data/tests_iam_resources/TF001_user_resource_with_aksk_attributes_ok/step3.user_resource_update_ak_ok.tf create mode 100644 tests/qa_provider_oapi/data/tests_iam_resources/TF002_user_group_resource_attributes_ok/step1.user_group_resource_attributes_ok.ref create mode 100644 tests/qa_provider_oapi/data/tests_iam_resources/TF002_user_group_resource_attributes_ok/step1.user_group_resource_attributes_ok.tf create mode 100644 tests/qa_provider_oapi/data/tests_iam_resources/TF002_user_group_resource_attributes_ok/step2.user_group_resource_update_ok.ref create mode 100644 tests/qa_provider_oapi/data/tests_iam_resources/TF002_user_group_resource_attributes_ok/step2.user_group_resource_update_ok.tf create mode 100644 tests/qa_provider_oapi/data/tests_iam_resources/TF003_policy_resource_attributes_ok/step1.policy_resource_attributes_ok.ref create mode 100644 tests/qa_provider_oapi/data/tests_iam_resources/TF003_policy_resource_attributes_ok/step1.policy_resource_attributes_ok.tf create mode 100644 tests/qa_provider_oapi/data/tests_iam_resources/TF004_policy_version_resource_attributes_ok/step1.policy_version_resource_attributes_ok.ref create mode 100644 tests/qa_provider_oapi/data/tests_iam_resources/TF004_policy_version_resource_attributes_ok/step1.policy_version_resource_attributes_ok.tf create mode 100644 tests/qa_provider_oapi/data/tests_iam_resources/TF005_all_iam_resources_attributes_ok/step1.all_iam_resources_attributes_ok.ref create mode 100644 tests/qa_provider_oapi/data/tests_iam_resources/TF005_all_iam_resources_attributes_ok/step1.all_iam_resources_attributes_ok.tf create mode 100644 tests/qa_provider_oapi/data/tests_iam_resources/TF005_all_iam_resources_attributes_ok/step2.all_iam_resources_update_ok.ref create mode 100644 tests/qa_provider_oapi/data/tests_iam_resources/TF005_all_iam_resources_attributes_ok/step2.all_iam_resources_update_ok.tf create mode 100644 tests/qa_provider_oapi/data/tests_iam_resources/TF006_user_datasource_attribute_ok/step2.user_datasource_after_update_ok.ref create mode 100644 tests/qa_provider_oapi/data/tests_iam_resources/TF006_user_datasource_attribute_ok/step2.user_datasource_after_update_ok.tf create mode 100644 tests/qa_provider_oapi/data/tests_iam_resources/TF007_users_datasource_attributes_ok/step1.users_datasource_attributes_ok.ref create mode 100644 tests/qa_provider_oapi/data/tests_iam_resources/TF007_users_datasource_attributes_ok/step1.users_datasource_attributes_ok.tf create mode 100644 tests/qa_provider_oapi/data/tests_iam_resources/TF008_user_group_datasource_attributes_ok/step1.user_group_datasource_attributes_ok.ref create mode 100644 tests/qa_provider_oapi/data/tests_iam_resources/TF008_user_group_datasource_attributes_ok/step1.user_group_datasource_attributes_ok.tf create mode 100644 tests/qa_provider_oapi/data/tests_iam_resources/TF009_user_groups_datasource_attributes_ok/step1.user_groups_datasource_attributes_ok.ref create mode 100644 tests/qa_provider_oapi/data/tests_iam_resources/TF009_user_groups_datasource_attributes_ok/step1.user_groups_datasource_attributes_ok.tf create mode 100644 tests/qa_provider_oapi/data/tests_iam_resources/TF010_policy_datasource_attributes_ok/step1.policy_datasource_attributes_ok.ref create mode 100644 tests/qa_provider_oapi/data/tests_iam_resources/TF010_policy_datasource_attributes_ok/step1.policy_datasource_attributes_ok.tf create mode 100644 tests/qa_provider_oapi/data/tests_iam_resources/TF011_policies_datasource_attributes_ok/step1.policies_datasource_attributes_ok.ref create mode 100644 tests/qa_provider_oapi/data/tests_iam_resources/TF011_policies_datasource_attributes_ok/step1.policies_datasource_attributes_ok.tf create mode 100644 tests/qa_provider_oapi/data/tests_iam_resources/TF012_policies_linked_to_user_datasource_attributes_ok/step1.policies_linked_to_user_datasource_attributes_ok.ref create mode 100644 tests/qa_provider_oapi/data/tests_iam_resources/TF012_policies_linked_to_user_datasource_attributes_ok/step1.policies_linked_to_user_datasource_attributes_ok.tf create mode 100644 tests/qa_provider_oapi/data/tests_iam_resources/TF013_policies_linked_to_user_group_datasource_attributes_ok/step1.policies_linked_to_user_group_datasource_attributes_ok.ref create mode 100644 tests/qa_provider_oapi/data/tests_iam_resources/TF013_policies_linked_to_user_group_datasource_attributes_ok/step1.policies_linked_to_user_group_datasource_attributes_ok.tf create mode 100644 tests/qa_provider_oapi/data/tests_iam_resources/TF014_entities_linked_to_policy_datasource_attributes_ok/step1.entities_linked_to_policy_datasource_attributes_ok.ref create mode 100644 tests/qa_provider_oapi/data/tests_iam_resources/TF014_entities_linked_to_policy_datasource_attributes_ok/step1.entities_linked_to_policy_datasource_attributes_ok.tf create mode 100644 tests/qa_provider_oapi/data/tests_iam_resources/TF015_user_groups_per_user_datasource_attributes_ok/step1.user_groups_per_user_datasource_attributes_ok.ref create mode 100644 tests/qa_provider_oapi/data/tests_iam_resources/TF015_user_groups_per_user_datasource_attributes_ok/step1.user_groups_per_user_datasource_attributes_ok.tf diff --git a/tests/qa_provider_oapi/data/load_balancer_listener_rule/TF-87_load_balancer_listener_rule_datasource_attributes_ok/step1.load_balancer_listener_rule_datasource_attributes_ok.ref b/tests/qa_provider_oapi/data/load_balancer_listener_rule/TF-87_load_balancer_listener_rule_datasource_attributes_ok/step1.load_balancer_listener_rule_datasource_attributes_ok.ref index 4f16cd6a9..ed3e5f228 100644 --- a/tests/qa_provider_oapi/data/load_balancer_listener_rule/TF-87_load_balancer_listener_rule_datasource_attributes_ok/step1.load_balancer_listener_rule_datasource_attributes_ok.ref +++ b/tests/qa_provider_oapi/data/load_balancer_listener_rule/TF-87_load_balancer_listener_rule_datasource_attributes_ok/step1.load_balancer_listener_rule_datasource_attributes_ok.ref @@ -355,4 +355,4 @@ } ], "check_results": "########" -} \ No newline at end of file +} diff --git a/tests/qa_provider_oapi/data/load_balancer_listener_rule/TF-88_load_balancer_listener_rule_resource_attributes_ok/step1.load_balancer_listener_rule_resource_attributes_ok.ref b/tests/qa_provider_oapi/data/load_balancer_listener_rule/TF-88_load_balancer_listener_rule_resource_attributes_ok/step1.load_balancer_listener_rule_resource_attributes_ok.ref index a576438ab..0e3115c1c 100644 --- a/tests/qa_provider_oapi/data/load_balancer_listener_rule/TF-88_load_balancer_listener_rule_resource_attributes_ok/step1.load_balancer_listener_rule_resource_attributes_ok.ref +++ b/tests/qa_provider_oapi/data/load_balancer_listener_rule/TF-88_load_balancer_listener_rule_resource_attributes_ok/step1.load_balancer_listener_rule_resource_attributes_ok.ref @@ -371,4 +371,4 @@ } ], "check_results": "########" -} \ No newline at end of file +} diff --git a/tests/qa_provider_oapi/data/load_balancer_listener_rule/TF-88_load_balancer_listener_rule_resource_attributes_ok/step2.load_balancer_listener_rule_resource_attributes_ok.ref b/tests/qa_provider_oapi/data/load_balancer_listener_rule/TF-88_load_balancer_listener_rule_resource_attributes_ok/step2.load_balancer_listener_rule_resource_attributes_ok.ref index f2f61d073..c11bf09c8 100644 --- a/tests/qa_provider_oapi/data/load_balancer_listener_rule/TF-88_load_balancer_listener_rule_resource_attributes_ok/step2.load_balancer_listener_rule_resource_attributes_ok.ref +++ b/tests/qa_provider_oapi/data/load_balancer_listener_rule/TF-88_load_balancer_listener_rule_resource_attributes_ok/step2.load_balancer_listener_rule_resource_attributes_ok.ref @@ -239,7 +239,7 @@ { "schema_version": 0, "attributes": { - "backend_ips": [], + "backend_ips": null, "backend_vm_ids": [ "##id-1##" ], @@ -373,4 +373,4 @@ } ], "check_results": "########" -} \ No newline at end of file +} diff --git a/tests/qa_provider_oapi/data/load_balancer_listener_rules/TF-89_load_balancer_listener_rules_datasource_attributes_ok/step1.load_balancer_listener_rules_datasource_attributes_ok.ref b/tests/qa_provider_oapi/data/load_balancer_listener_rules/TF-89_load_balancer_listener_rules_datasource_attributes_ok/step1.load_balancer_listener_rules_datasource_attributes_ok.ref index 7f81ca54d..a721f9305 100644 --- a/tests/qa_provider_oapi/data/load_balancer_listener_rules/TF-89_load_balancer_listener_rules_datasource_attributes_ok/step1.load_balancer_listener_rules_datasource_attributes_ok.ref +++ b/tests/qa_provider_oapi/data/load_balancer_listener_rules/TF-89_load_balancer_listener_rules_datasource_attributes_ok/step1.load_balancer_listener_rules_datasource_attributes_ok.ref @@ -371,4 +371,4 @@ } ], "check_results": "########" -} \ No newline at end of file +} diff --git a/tests/qa_provider_oapi/data/load_balancer_vm_health/TF-92_load_balancer_vm_health_datasource_attributes_ok/step1.load_balancer_vm_health_datasource_attributes_ok.ref b/tests/qa_provider_oapi/data/load_balancer_vm_health/TF-92_load_balancer_vm_health_datasource_attributes_ok/step1.load_balancer_vm_health_datasource_attributes_ok.ref index 3190caae9..7910f990a 100644 --- a/tests/qa_provider_oapi/data/load_balancer_vm_health/TF-92_load_balancer_vm_health_datasource_attributes_ok/step1.load_balancer_vm_health_datasource_attributes_ok.ref +++ b/tests/qa_provider_oapi/data/load_balancer_vm_health/TF-92_load_balancer_vm_health_datasource_attributes_ok/step1.load_balancer_vm_health_datasource_attributes_ok.ref @@ -377,4 +377,4 @@ } ], "check_results": "########" -} \ No newline at end of file +} diff --git a/tests/qa_provider_oapi/data/load_balancer_vms/TF-93_load_balancer_vms_resource_attributes_ok/step1.load_balancer_vms_resource_attributes_ok.ref b/tests/qa_provider_oapi/data/load_balancer_vms/TF-93_load_balancer_vms_resource_attributes_ok/step1.load_balancer_vms_resource_attributes_ok.ref index 0a8128aee..9553b7900 100644 --- a/tests/qa_provider_oapi/data/load_balancer_vms/TF-93_load_balancer_vms_resource_attributes_ok/step1.load_balancer_vms_resource_attributes_ok.ref +++ b/tests/qa_provider_oapi/data/load_balancer_vms/TF-93_load_balancer_vms_resource_attributes_ok/step1.load_balancer_vms_resource_attributes_ok.ref @@ -341,4 +341,4 @@ } ], "check_results": "########" -} \ No newline at end of file +} diff --git a/tests/qa_provider_oapi/data/load_balancer_vms/TF-93_load_balancer_vms_resource_attributes_ok/step2.load_balancer_vms_resource_remove_vm_ok.ref b/tests/qa_provider_oapi/data/load_balancer_vms/TF-93_load_balancer_vms_resource_attributes_ok/step2.load_balancer_vms_resource_remove_vm_ok.ref index c29ddcdc1..054a0a7bc 100644 --- a/tests/qa_provider_oapi/data/load_balancer_vms/TF-93_load_balancer_vms_resource_attributes_ok/step2.load_balancer_vms_resource_remove_vm_ok.ref +++ b/tests/qa_provider_oapi/data/load_balancer_vms/TF-93_load_balancer_vms_resource_attributes_ok/step2.load_balancer_vms_resource_remove_vm_ok.ref @@ -119,7 +119,7 @@ { "schema_version": 0, "attributes": { - "backend_ips": [], + "backend_ips": null, "backend_vm_ids": [ "##id-1##" ], @@ -343,4 +343,4 @@ } ], "check_results": "########" -} \ No newline at end of file +} diff --git a/tests/qa_provider_oapi/data/policies_files/policy.json b/tests/qa_provider_oapi/data/policies_files/policy.json new file mode 100644 index 000000000..9a2f22fd4 --- /dev/null +++ b/tests/qa_provider_oapi/data/policies_files/policy.json @@ -0,0 +1,13 @@ +{ + "Statement": [ + { + "Action": [ + "api:*" + ], + "Effect": "Allow", + "Resource": [ + "*" + ] + } + ] +} diff --git a/tests/qa_provider_oapi/data/policies_files/policy11.json b/tests/qa_provider_oapi/data/policies_files/policy11.json new file mode 100644 index 000000000..9a2f22fd4 --- /dev/null +++ b/tests/qa_provider_oapi/data/policies_files/policy11.json @@ -0,0 +1,13 @@ +{ + "Statement": [ + { + "Action": [ + "api:*" + ], + "Effect": "Allow", + "Resource": [ + "*" + ] + } + ] +} diff --git a/tests/qa_provider_oapi/data/policies_files/policy12.json b/tests/qa_provider_oapi/data/policies_files/policy12.json new file mode 100644 index 000000000..22ede45a5 --- /dev/null +++ b/tests/qa_provider_oapi/data/policies_files/policy12.json @@ -0,0 +1,13 @@ +{ + "Statement": [ + { + "Action": [ + "api:Read*" + ], + "Effect": "Allow", + "Resource": [ + "*" + ] + } + ] +} diff --git a/tests/qa_provider_oapi/data/policies_files/policy2.json b/tests/qa_provider_oapi/data/policies_files/policy2.json new file mode 100644 index 000000000..8e84d35a3 --- /dev/null +++ b/tests/qa_provider_oapi/data/policies_files/policy2.json @@ -0,0 +1,13 @@ +{ + "Statement": [ + { + "Action": [ + "api:*VM*" + ], + "Effect": "Allow", + "Resource": [ + "*" + ] + } + ] +} diff --git a/tests/qa_provider_oapi/data/policies_files/policyV1.json b/tests/qa_provider_oapi/data/policies_files/policyV1.json new file mode 100644 index 000000000..c05dec062 --- /dev/null +++ b/tests/qa_provider_oapi/data/policies_files/policyV1.json @@ -0,0 +1,13 @@ +{ + "Statement": [ + { + "Effect": "Allow", + "Action": [ + "api:ReadConsumptionAccount" + ], + "Resource": [ + "*" + ] + } + ] +} diff --git a/tests/qa_provider_oapi/data/policies_files/policyV2.json b/tests/qa_provider_oapi/data/policies_files/policyV2.json new file mode 100644 index 000000000..ba5c9624c --- /dev/null +++ b/tests/qa_provider_oapi/data/policies_files/policyV2.json @@ -0,0 +1,13 @@ +{ + "Statement": [ + { + "Action": [ + "api:Read*" + ], + "Effect": "Allow", + "Resource": [ + "*" + ] + } + ] +} diff --git a/tests/qa_provider_oapi/data/policies_files/policyV3.json b/tests/qa_provider_oapi/data/policies_files/policyV3.json new file mode 100644 index 000000000..b70e6ad83 --- /dev/null +++ b/tests/qa_provider_oapi/data/policies_files/policyV3.json @@ -0,0 +1,9 @@ +{ + "Statement": [ + { + "Action": "*", + "Resource": "*", + "Effect": "Allow" + } + ] +} diff --git a/tests/qa_provider_oapi/data/policies_files/policy_RO.json b/tests/qa_provider_oapi/data/policies_files/policy_RO.json new file mode 100644 index 000000000..ba5c9624c --- /dev/null +++ b/tests/qa_provider_oapi/data/policies_files/policy_RO.json @@ -0,0 +1,13 @@ +{ + "Statement": [ + { + "Action": [ + "api:Read*" + ], + "Effect": "Allow", + "Resource": [ + "*" + ] + } + ] +} diff --git a/tests/qa_provider_oapi/data/policies_files/policy_ReadAccountConsumption.json b/tests/qa_provider_oapi/data/policies_files/policy_ReadAccountConsumption.json new file mode 100644 index 000000000..c05dec062 --- /dev/null +++ b/tests/qa_provider_oapi/data/policies_files/policy_ReadAccountConsumption.json @@ -0,0 +1,13 @@ +{ + "Statement": [ + { + "Effect": "Allow", + "Action": [ + "api:ReadConsumptionAccount" + ], + "Resource": [ + "*" + ] + } + ] +} diff --git a/tests/qa_provider_oapi/data/tests_iam_resources/TF001_user_resource_with_aksk_attributes_ok/step1.user_resource_attributes_ok.ref b/tests/qa_provider_oapi/data/tests_iam_resources/TF001_user_resource_with_aksk_attributes_ok/step1.user_resource_attributes_ok.ref new file mode 100644 index 000000000..2bdcf4812 --- /dev/null +++ b/tests/qa_provider_oapi/data/tests_iam_resources/TF001_user_resource_with_aksk_attributes_ok/step1.user_resource_attributes_ok.ref @@ -0,0 +1,83 @@ +{ + "version": "########", + "terraform_version": "########", + "serial": "########", + "lineage": "########", + "outputs": {}, + "resources": [ + { + "mode": "managed", + "type": "outscale_access_key", + "name": "access_key_eim01", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "access_key_id": "##id-0##", + "creation_date": "########", + "expiration_date": "2028-01-01T00:00:00.000+0000", + "id": "##id-0##", + "last_modification_date": "########", + "request_id": "########", + "secret_key": "########", + "state": "ACTIVE", + "user_name": "User-terraform-2" + }, + "sensitive_attributes": [], + "private": "bnVsbA==", + "dependencies": [ + "outscale_user.user-2" + ] + } + ] + }, + { + "mode": "managed", + "type": "outscale_user", + "name": "user-1", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "creation_date": "########", + "id": "##id-1##", + "last_modification_date": "########", + "path": "/terraform/", + "policy": [], + "user_email": "test-TF1@test2.fr", + "user_id": "##id-1##", + "user_name": "User-terraform-1" + }, + "sensitive_attributes": [], + "private": "bnVsbA==" + } + ] + }, + { + "mode": "managed", + "type": "outscale_user", + "name": "user-2", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "creation_date": "########", + "id": "##id-2##", + "last_modification_date": "########", + "path": "/", + "policy": [], + "user_email": "customer-tooling@outscale.com", + "user_id": "##id-2##", + "user_name": "User-terraform-2" + }, + "sensitive_attributes": [], + "private": "bnVsbA==" + } + ] + } + ], + "check_results": "########" +} \ No newline at end of file diff --git a/tests/qa_provider_oapi/data/tests_iam_resources/TF001_user_resource_with_aksk_attributes_ok/step1.user_resource_attributes_ok.tf b/tests/qa_provider_oapi/data/tests_iam_resources/TF001_user_resource_with_aksk_attributes_ok/step1.user_resource_attributes_ok.tf new file mode 100644 index 000000000..0bada6709 --- /dev/null +++ b/tests/qa_provider_oapi/data/tests_iam_resources/TF001_user_resource_with_aksk_attributes_ok/step1.user_resource_attributes_ok.tf @@ -0,0 +1,18 @@ +resource "outscale_user" "user-1" { + user_name = "User-terraform-1" + user_email = "test-TF1@test2.fr" + path = "/terraform/" + } + + +resource "outscale_user" "user-2" { + user_name = "User-terraform-2" + } + +resource "outscale_access_key" "access_key_eim01" { + user_name = outscale_user.user-2.user_name + state = "ACTIVE" + expiration_date = "2028-01-01" +depends_on=[outscale_user.user-2] +} + diff --git a/tests/qa_provider_oapi/data/tests_iam_resources/TF001_user_resource_with_aksk_attributes_ok/step2.user_resource_update_ok.ref b/tests/qa_provider_oapi/data/tests_iam_resources/TF001_user_resource_with_aksk_attributes_ok/step2.user_resource_update_ok.ref new file mode 100644 index 000000000..043b3d305 --- /dev/null +++ b/tests/qa_provider_oapi/data/tests_iam_resources/TF001_user_resource_with_aksk_attributes_ok/step2.user_resource_update_ok.ref @@ -0,0 +1,83 @@ +{ + "version": "########", + "terraform_version": "########", + "serial": "########", + "lineage": "########", + "outputs": {}, + "resources": [ + { + "mode": "managed", + "type": "outscale_access_key", + "name": "access_key_eim01", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "access_key_id": "##id-0##", + "creation_date": "########", + "expiration_date": "2028-01-01T00:00:00.000+0000", + "id": "##id-0##", + "last_modification_date": "########", + "request_id": "########", + "secret_key": "########", + "state": "ACTIVE", + "user_name": "User-terraform-2" + }, + "sensitive_attributes": [], + "private": "bnVsbA==", + "dependencies": [ + "outscale_user.user-2" + ] + } + ] + }, + { + "mode": "managed", + "type": "outscale_user", + "name": "user-1", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "creation_date": "########", + "id": "##id-1##", + "last_modification_date": "########", + "path": "/terraform_update/", + "policy": [], + "user_email": "test-TF11@test2.fr", + "user_id": "##id-1##", + "user_name": "User-terraform-11" + }, + "sensitive_attributes": [], + "private": "bnVsbA==" + } + ] + }, + { + "mode": "managed", + "type": "outscale_user", + "name": "user-2", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "creation_date": "########", + "id": "##id-2##", + "last_modification_date": "########", + "path": "/", + "policy": [], + "user_email": "customer-tooling@outscale.com", + "user_id": "##id-2##", + "user_name": "User-terraform-2" + }, + "sensitive_attributes": [], + "private": "bnVsbA==" + } + ] + } + ], + "check_results": "########" +} \ No newline at end of file diff --git a/tests/qa_provider_oapi/data/tests_iam_resources/TF001_user_resource_with_aksk_attributes_ok/step2.user_resource_update_ok.tf b/tests/qa_provider_oapi/data/tests_iam_resources/TF001_user_resource_with_aksk_attributes_ok/step2.user_resource_update_ok.tf new file mode 100644 index 000000000..c91f5c759 --- /dev/null +++ b/tests/qa_provider_oapi/data/tests_iam_resources/TF001_user_resource_with_aksk_attributes_ok/step2.user_resource_update_ok.tf @@ -0,0 +1,18 @@ +resource "outscale_user" "user-1" { + user_name = "User-terraform-11" + user_email = "test-TF11@test2.fr" + path = "/terraform_update/" + } + + +resource "outscale_user" "user-2" { + user_name = "User-terraform-2" + } + +resource "outscale_access_key" "access_key_eim01" { + user_name = outscale_user.user-2.user_name + state = "ACTIVE" + expiration_date = "2028-01-01" +depends_on=[outscale_user.user-2] +} + diff --git a/tests/qa_provider_oapi/data/tests_iam_resources/TF001_user_resource_with_aksk_attributes_ok/step3.user_resource_update_ak_ok.ref b/tests/qa_provider_oapi/data/tests_iam_resources/TF001_user_resource_with_aksk_attributes_ok/step3.user_resource_update_ak_ok.ref new file mode 100644 index 000000000..b6d5d59ae --- /dev/null +++ b/tests/qa_provider_oapi/data/tests_iam_resources/TF001_user_resource_with_aksk_attributes_ok/step3.user_resource_update_ak_ok.ref @@ -0,0 +1,83 @@ +{ + "version": "########", + "terraform_version": "########", + "serial": "########", + "lineage": "########", + "outputs": {}, + "resources": [ + { + "mode": "managed", + "type": "outscale_access_key", + "name": "access_key_eim01", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "access_key_id": "##id-0##", + "creation_date": "########", + "expiration_date": "2028-01-01T00:00:00.000+0000", + "id": "##id-0##", + "last_modification_date": "########", + "request_id": "########", + "secret_key": "########", + "state": "INACTIVE", + "user_name": "User-terraform-2" + }, + "sensitive_attributes": [], + "private": "bnVsbA==", + "dependencies": [ + "outscale_user.user-2" + ] + } + ] + }, + { + "mode": "managed", + "type": "outscale_user", + "name": "user-1", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "creation_date": "########", + "id": "##id-1##", + "last_modification_date": "########", + "path": "/terraform_update/", + "policy": [], + "user_email": "test-TF11@test2.fr", + "user_id": "##id-1##", + "user_name": "User-terraform-11" + }, + "sensitive_attributes": [], + "private": "bnVsbA==" + } + ] + }, + { + "mode": "managed", + "type": "outscale_user", + "name": "user-2", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "creation_date": "########", + "id": "##id-2##", + "last_modification_date": "########", + "path": "/", + "policy": [], + "user_email": "customer-tooling@outscale.com", + "user_id": "##id-2##", + "user_name": "User-terraform-2" + }, + "sensitive_attributes": [], + "private": "bnVsbA==" + } + ] + } + ], + "check_results": "########" +} \ No newline at end of file diff --git a/tests/qa_provider_oapi/data/tests_iam_resources/TF001_user_resource_with_aksk_attributes_ok/step3.user_resource_update_ak_ok.tf b/tests/qa_provider_oapi/data/tests_iam_resources/TF001_user_resource_with_aksk_attributes_ok/step3.user_resource_update_ak_ok.tf new file mode 100644 index 000000000..1e2e4072e --- /dev/null +++ b/tests/qa_provider_oapi/data/tests_iam_resources/TF001_user_resource_with_aksk_attributes_ok/step3.user_resource_update_ak_ok.tf @@ -0,0 +1,18 @@ +resource "outscale_user" "user-1" { + user_name = "User-terraform-11" + user_email = "test-TF11@test2.fr" + path = "/terraform_update/" + } + + +resource "outscale_user" "user-2" { + user_name = "User-terraform-2" + } + +resource "outscale_access_key" "access_key_eim01" { + user_name = outscale_user.user-2.user_name + state = "INACTIVE" + expiration_date = "2028-01-01" +depends_on=[outscale_user.user-2] +} + diff --git a/tests/qa_provider_oapi/data/tests_iam_resources/TF002_user_group_resource_attributes_ok/step1.user_group_resource_attributes_ok.ref b/tests/qa_provider_oapi/data/tests_iam_resources/TF002_user_group_resource_attributes_ok/step1.user_group_resource_attributes_ok.ref new file mode 100644 index 000000000..141230c60 --- /dev/null +++ b/tests/qa_provider_oapi/data/tests_iam_resources/TF002_user_group_resource_attributes_ok/step1.user_group_resource_attributes_ok.ref @@ -0,0 +1,34 @@ +{ + "version": "########", + "terraform_version": "########", + "serial": "########", + "lineage": "########", + "outputs": {}, + "resources": [ + { + "mode": "managed", + "type": "outscale_user_group", + "name": "group-1", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "creation_date": "########", + "id": "##id-0##", + "last_modification_date": "########", + "orn": "########", + "path": "/terraform_group/", + "policy": [], + "user": [], + "user_group_id": "##id-0##", + "user_group_name": "Group-terraform-test-1" + }, + "sensitive_attributes": [], + "private": "bnVsbA==" + } + ] + } + ], + "check_results": "########" +} \ No newline at end of file diff --git a/tests/qa_provider_oapi/data/tests_iam_resources/TF002_user_group_resource_attributes_ok/step1.user_group_resource_attributes_ok.tf b/tests/qa_provider_oapi/data/tests_iam_resources/TF002_user_group_resource_attributes_ok/step1.user_group_resource_attributes_ok.tf new file mode 100644 index 000000000..46f6631b1 --- /dev/null +++ b/tests/qa_provider_oapi/data/tests_iam_resources/TF002_user_group_resource_attributes_ok/step1.user_group_resource_attributes_ok.tf @@ -0,0 +1,5 @@ +resource "outscale_user_group" "group-1" { + user_group_name = "Group-terraform-test-1" + path = "/terraform_group/" + } + diff --git a/tests/qa_provider_oapi/data/tests_iam_resources/TF002_user_group_resource_attributes_ok/step2.user_group_resource_update_ok.ref b/tests/qa_provider_oapi/data/tests_iam_resources/TF002_user_group_resource_attributes_ok/step2.user_group_resource_update_ok.ref new file mode 100644 index 000000000..263ce3dfe --- /dev/null +++ b/tests/qa_provider_oapi/data/tests_iam_resources/TF002_user_group_resource_attributes_ok/step2.user_group_resource_update_ok.ref @@ -0,0 +1,34 @@ +{ + "version": "########", + "terraform_version": "########", + "serial": "########", + "lineage": "########", + "outputs": {}, + "resources": [ + { + "mode": "managed", + "type": "outscale_user_group", + "name": "group-1", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "creation_date": "########", + "id": "##id-0##", + "last_modification_date": "########", + "orn": "########", + "path": "/", + "policy": [], + "user": [], + "user_group_id": "##id-0##", + "user_group_name": "Group-terraform-test-2" + }, + "sensitive_attributes": [], + "private": "bnVsbA==" + } + ] + } + ], + "check_results": "########" +} \ No newline at end of file diff --git a/tests/qa_provider_oapi/data/tests_iam_resources/TF002_user_group_resource_attributes_ok/step2.user_group_resource_update_ok.tf b/tests/qa_provider_oapi/data/tests_iam_resources/TF002_user_group_resource_attributes_ok/step2.user_group_resource_update_ok.tf new file mode 100644 index 000000000..5ba39b9d1 --- /dev/null +++ b/tests/qa_provider_oapi/data/tests_iam_resources/TF002_user_group_resource_attributes_ok/step2.user_group_resource_update_ok.tf @@ -0,0 +1,5 @@ +resource "outscale_user_group" "group-1" { + user_group_name = "Group-terraform-test-2" + path = "/" + } + diff --git a/tests/qa_provider_oapi/data/tests_iam_resources/TF003_policy_resource_attributes_ok/step1.policy_resource_attributes_ok.ref b/tests/qa_provider_oapi/data/tests_iam_resources/TF003_policy_resource_attributes_ok/step1.policy_resource_attributes_ok.ref new file mode 100644 index 000000000..3c993a00e --- /dev/null +++ b/tests/qa_provider_oapi/data/tests_iam_resources/TF003_policy_resource_attributes_ok/step1.policy_resource_attributes_ok.ref @@ -0,0 +1,64 @@ +{ + "version": "########", + "terraform_version": "########", + "serial": "########", + "lineage": "########", + "outputs": {}, + "resources": [ + { + "mode": "managed", + "type": "outscale_policy", + "name": "policy-1", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "creation_date": "########", + "description": "test-policy", + "document": "{\n \"Statement\": [\n {\n \"Action\": [\n \"api:Read*\"\n ],\n \"Effect\": \"Allow\",\n \"Resource\": [\n \"*\"\n ]\n }\n ]\n} \n", + "id": "##id-0##", + "is_linkable": true, + "last_modification_date": "########", + "orn": "########", + "path": "/terraform/", + "policy_default_version_id": "##id-1##", + "policy_id": "##id-2##", + "policy_name": "terraform-RO-policy", + "resources_count": 0 + }, + "sensitive_attributes": [], + "private": "bnVsbA==" + } + ] + }, + { + "mode": "managed", + "type": "outscale_policy", + "name": "policy-2", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "creation_date": "########", + "description": "", + "document": "{\n \"Statement\": [\n {\n \"Effect\": \"Allow\",\n \"Action\": [\n \"api:ReadConsumptionAccount\"\n ],\n \"Resource\": [\n \"*\"\n ]\n }\n ]\n} \n", + "id": "##id-3##", + "is_linkable": true, + "last_modification_date": "########", + "orn": "########", + "path": "/", + "policy_default_version_id": "##id-1##", + "policy_id": "##id-4##", + "policy_name": "terraform-Read-Account_consumption_only", + "resources_count": 0 + }, + "sensitive_attributes": [], + "private": "bnVsbA==" + } + ] + } + ], + "check_results": "########" +} \ No newline at end of file diff --git a/tests/qa_provider_oapi/data/tests_iam_resources/TF003_policy_resource_attributes_ok/step1.policy_resource_attributes_ok.tf b/tests/qa_provider_oapi/data/tests_iam_resources/TF003_policy_resource_attributes_ok/step1.policy_resource_attributes_ok.tf new file mode 100644 index 000000000..3811c84e3 --- /dev/null +++ b/tests/qa_provider_oapi/data/tests_iam_resources/TF003_policy_resource_attributes_ok/step1.policy_resource_attributes_ok.tf @@ -0,0 +1,11 @@ +resource "outscale_policy" "policy-1" { + policy_name = "terraform-RO-policy" + description = "test-policy" + document = file("data/policies_files/policy_RO.json") + path = "/terraform/" +} + +resource "outscale_policy" "policy-2" { + policy_name = "terraform-Read-Account_consumption_only" + document = file("data/policies_files/policy_ReadAccountConsumption.json") +} diff --git a/tests/qa_provider_oapi/data/tests_iam_resources/TF004_policy_version_resource_attributes_ok/step1.policy_version_resource_attributes_ok.ref b/tests/qa_provider_oapi/data/tests_iam_resources/TF004_policy_version_resource_attributes_ok/step1.policy_version_resource_attributes_ok.ref new file mode 100644 index 000000000..7299a1df1 --- /dev/null +++ b/tests/qa_provider_oapi/data/tests_iam_resources/TF004_policy_version_resource_attributes_ok/step1.policy_version_resource_attributes_ok.ref @@ -0,0 +1,89 @@ +{ + "version": "########", + "terraform_version": "########", + "serial": "########", + "lineage": "########", + "outputs": {}, + "resources": [ + { + "mode": "managed", + "type": "outscale_policy", + "name": "policy-1", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "creation_date": "########", + "description": "test-version", + "document": "{\n \"Statement\": [\n {\n \"Effect\": \"Allow\",\n \"Action\": [\n \"api:ReadConsumptionAccount\"\n ],\n \"Resource\": [\n \"*\"\n ]\n }\n ]\n} \n", + "id": "##id-0##", + "is_linkable": true, + "last_modification_date": "########", + "orn": "########", + "path": "/", + "policy_default_version_id": "##id-1##", + "policy_id": "##id-2##", + "policy_name": "terraform-policy-01", + "resources_count": 0 + }, + "sensitive_attributes": [], + "private": "bnVsbA==" + } + ] + }, + { + "mode": "managed", + "type": "outscale_policy_version", + "name": "policy-1_version-02", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "body": "########", + "creation_date": "########", + "default_version": false, + "document": "{\n \"Statement\": [\n {\n \"Action\": [\n \"api:Read*\"\n ],\n \"Effect\": \"Allow\",\n \"Resource\": [\n \"*\"\n ]\n }\n ]\n} \n", + "id": "##id-3##", + "policy_orn": "orn:ows:idauth::339215505907:policy/terraform-policy-01", + "set_as_default": null, + "version_id": "##id-4##" + }, + "sensitive_attributes": [], + "private": "bnVsbA==", + "dependencies": [ + "outscale_policy.policy-1" + ] + } + ] + }, + { + "mode": "managed", + "type": "outscale_policy_version", + "name": "version-03", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "body": "########", + "creation_date": "########", + "default_version": true, + "document": "{\n \"Statement\": [\n {\n \"Action\": \"*\",\n \"Resource\": \"*\",\n \"Effect\": \"Allow\"\n }\n ]\n}\n", + "id": "##id-5##", + "policy_orn": "orn:ows:idauth::339215505907:policy/terraform-policy-01", + "set_as_default": true, + "version_id": "##id-6##" + }, + "sensitive_attributes": [], + "private": "bnVsbA==", + "dependencies": [ + "outscale_policy.policy-1" + ] + } + ] + } + ], + "check_results": "########" +} \ No newline at end of file diff --git a/tests/qa_provider_oapi/data/tests_iam_resources/TF004_policy_version_resource_attributes_ok/step1.policy_version_resource_attributes_ok.tf b/tests/qa_provider_oapi/data/tests_iam_resources/TF004_policy_version_resource_attributes_ok/step1.policy_version_resource_attributes_ok.tf new file mode 100644 index 000000000..c9302870b --- /dev/null +++ b/tests/qa_provider_oapi/data/tests_iam_resources/TF004_policy_version_resource_attributes_ok/step1.policy_version_resource_attributes_ok.tf @@ -0,0 +1,18 @@ +resource "outscale_policy" "policy-1" { + policy_name = "terraform-policy-01" + description = "test-version" + document = file("data/policies_files/policyV1.json") + path = "/" +} + +resource "outscale_policy_version" "policy-1_version-02" { + policy_orn = outscale_policy.policy-1.orn + document = file("data/policies_files/policyV2.json") +} + +resource "outscale_policy_version" "version-03" { + policy_orn = outscale_policy.policy-1.orn + document = file("data/policies_files/policyV3.json") + set_as_default = true +} + diff --git a/tests/qa_provider_oapi/data/tests_iam_resources/TF005_all_iam_resources_attributes_ok/step1.all_iam_resources_attributes_ok.ref b/tests/qa_provider_oapi/data/tests_iam_resources/TF005_all_iam_resources_attributes_ok/step1.all_iam_resources_attributes_ok.ref new file mode 100644 index 000000000..93038c1f7 --- /dev/null +++ b/tests/qa_provider_oapi/data/tests_iam_resources/TF005_all_iam_resources_attributes_ok/step1.all_iam_resources_attributes_ok.ref @@ -0,0 +1,347 @@ +{ + "version": "########", + "terraform_version": "########", + "serial": "########", + "lineage": "########", + "outputs": {}, + "resources": [ + { + "mode": "managed", + "type": "outscale_policy", + "name": "policy-1", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "creation_date": "########", + "description": "test-terraform", + "document": "{\n \"Statement\": [\n {\n \"Action\": [\n \"api:*\"\n ],\n \"Effect\": \"Allow\",\n \"Resource\": [\n \"*\"\n ]\n }\n ]\n}\n", + "id": "##id-0##", + "is_linkable": true, + "last_modification_date": "########", + "orn": "########", + "path": "/", + "policy_default_version_id": "##id-1##", + "policy_id": "##id-2##", + "policy_name": "terraform-policy-1", + "resources_count": 0 + }, + "sensitive_attributes": [], + "private": "bnVsbA==" + } + ] + }, + { + "mode": "managed", + "type": "outscale_policy", + "name": "policy-2", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "creation_date": "########", + "description": "test-terraform", + "document": "{\n \"Statement\": [\n {\n \"Action\": [\n \"api:*\"\n ],\n \"Effect\": \"Allow\",\n \"Resource\": [\n \"*\"\n ]\n }\n ]\n}\n", + "id": "##id-3##", + "is_linkable": true, + "last_modification_date": "########", + "orn": "########", + "path": "/", + "policy_default_version_id": "##id-1##", + "policy_id": "##id-4##", + "policy_name": "terraform-policy-2", + "resources_count": 0 + }, + "sensitive_attributes": [], + "private": "bnVsbA==" + } + ] + }, + { + "mode": "managed", + "type": "outscale_policy", + "name": "policy-RO", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "creation_date": "########", + "description": "test-terraform-ro", + "document": "{\n \"Statement\": [\n {\n \"Action\": [\n \"api:Read*\"\n ],\n \"Effect\": \"Allow\",\n \"Resource\": [\n \"*\"\n ]\n }\n ]\n} \n", + "id": "##id-5##", + "is_linkable": true, + "last_modification_date": "########", + "orn": "########", + "path": "/", + "policy_default_version_id": "##id-1##", + "policy_id": "##id-6##", + "policy_name": "terraform-policy-RO", + "resources_count": 0 + }, + "sensitive_attributes": [], + "private": "bnVsbA==" + } + ] + }, + { + "mode": "managed", + "type": "outscale_policy_version", + "name": "policy-2", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "body": "########", + "creation_date": "########", + "default_version": false, + "document": "{\n \"Statement\": [\n {\n \"Action\": [\n \"api:*VM*\"\n ],\n \"Effect\": \"Allow\",\n \"Resource\": [\n \"*\"\n ]\n }\n ]\n}\n", + "id": "##id-7##", + "policy_orn": "orn:ows:idauth::339215505907:policy/terraform-policy-2", + "set_as_default": null, + "version_id": "##id-8##" + }, + "sensitive_attributes": [], + "private": "bnVsbA==", + "dependencies": [ + "outscale_policy.policy-2" + ] + } + ] + }, + { + "mode": "managed", + "type": "outscale_user", + "name": "multiple_users", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "index_key": 0, + "schema_version": 0, + "attributes": { + "creation_date": "########", + "id": "##id-9##", + "last_modification_date": "########", + "path": "/", + "policy": [], + "user_email": "test-0@test2.fr", + "user_id": "##id-9##", + "user_name": "TF-User-0" + }, + "sensitive_attributes": [], + "private": "bnVsbA==" + }, + { + "index_key": 1, + "schema_version": 0, + "attributes": { + "creation_date": "########", + "id": "##id-10##", + "last_modification_date": "########", + "path": "/", + "policy": [], + "user_email": "test-1@test2.fr", + "user_id": "##id-10##", + "user_name": "TF-User-1" + }, + "sensitive_attributes": [], + "private": "bnVsbA==" + }, + { + "index_key": 2, + "schema_version": 0, + "attributes": { + "creation_date": "########", + "id": "##id-11##", + "last_modification_date": "########", + "path": "/", + "policy": [], + "user_email": "test-2@test2.fr", + "user_id": "##id-11##", + "user_name": "TF-User-2" + }, + "sensitive_attributes": [], + "private": "bnVsbA==" + } + ] + }, + { + "mode": "managed", + "type": "outscale_user", + "name": "user-1", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "creation_date": "########", + "id": "##id-12##", + "last_modification_date": "########", + "path": "/terraform/", + "policy": [ + { + "creation_date": "########", + "default_version_id": "##id-1##", + "last_modification_date": "########", + "policy_id": "##id-2##", + "policy_name": "terraform-policy-1", + "policy_orn": "orn:ows:idauth::339215505907:policy/terraform-policy-1" + } + ], + "user_email": "test-TF11@test2.fr", + "user_id": "##id-12##", + "user_name": "User-TF-RW" + }, + "sensitive_attributes": [], + "private": "bnVsbA==", + "dependencies": [ + "outscale_policy.policy-1" + ] + } + ] + }, + { + "mode": "managed", + "type": "outscale_user", + "name": "user-2", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "creation_date": "########", + "id": "##id-13##", + "last_modification_date": "########", + "path": "/terraform2/", + "policy": [ + { + "creation_date": "########", + "default_version_id": "##id-8##", + "last_modification_date": "########", + "policy_id": "##id-4##", + "policy_name": "terraform-policy-2", + "policy_orn": "orn:ows:idauth::339215505907:policy/terraform-policy-2" + } + ], + "user_email": "test-TF12@test2.fr", + "user_id": "##id-13##", + "user_name": "User-TF-RW-2" + }, + "sensitive_attributes": [], + "private": "bnVsbA==", + "dependencies": [ + "outscale_policy.policy-2" + ] + } + ] + }, + { + "mode": "managed", + "type": "outscale_user_group", + "name": "group-No-policy", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "creation_date": "########", + "id": "##id-14##", + "last_modification_date": "########", + "orn": "########", + "path": "/terraform/", + "policy": [], + "user": [ + { + "creation_date": "########", + "last_modification_date": "########", + "path": "/terraform/", + "user_id": "##id-12##", + "user_name": "User-TF-RW" + }, + { + "creation_date": "########", + "last_modification_date": "########", + "path": "/terraform2/", + "user_id": "##id-13##", + "user_name": "User-TF-RW-2" + } + ], + "user_group_id": "##id-14##", + "user_group_name": "Group-TF-test-1" + }, + "sensitive_attributes": [], + "private": "bnVsbA==", + "dependencies": [ + "outscale_policy.policy-1", + "outscale_policy.policy-2", + "outscale_user.user-1", + "outscale_user.user-2" + ] + } + ] + }, + { + "mode": "managed", + "type": "outscale_user_group", + "name": "group-policy-RO", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "creation_date": "########", + "id": "##id-15##", + "last_modification_date": "########", + "orn": "########", + "path": "/", + "policy": [ + { + "creation_date": "########", + "default_version_id": "##id-1##", + "last_modification_date": "########", + "policy_id": "##id-6##", + "policy_name": "terraform-policy-RO", + "policy_orn": "orn:ows:idauth::339215505907:policy/terraform-policy-RO" + } + ], + "user": [ + { + "creation_date": "########", + "last_modification_date": "########", + "path": "/", + "user_id": "##id-10##", + "user_name": "TF-User-1" + }, + { + "creation_date": "########", + "last_modification_date": "########", + "path": "/", + "user_id": "##id-9##", + "user_name": "TF-User-0" + }, + { + "creation_date": "########", + "last_modification_date": "########", + "path": "/", + "user_id": "##id-11##", + "user_name": "TF-User-2" + } + ], + "user_group_id": "##id-15##", + "user_group_name": "Group-TF-RO" + }, + "sensitive_attributes": [], + "private": "bnVsbA==", + "dependencies": [ + "outscale_policy.policy-RO", + "outscale_user.multiple_users" + ] + } + ] + } + ], + "check_results": "########" +} \ No newline at end of file diff --git a/tests/qa_provider_oapi/data/tests_iam_resources/TF005_all_iam_resources_attributes_ok/step1.all_iam_resources_attributes_ok.tf b/tests/qa_provider_oapi/data/tests_iam_resources/TF005_all_iam_resources_attributes_ok/step1.all_iam_resources_attributes_ok.tf new file mode 100644 index 000000000..6b7ebadf2 --- /dev/null +++ b/tests/qa_provider_oapi/data/tests_iam_resources/TF005_all_iam_resources_attributes_ok/step1.all_iam_resources_attributes_ok.tf @@ -0,0 +1,90 @@ +resource "outscale_user" "user-1" { + user_name = "User-TF-RW" + user_email = "test-TF11@test2.fr" + path = "/terraform/" + policy { + policy_orn = outscale_policy.policy-1.orn + } +} + +resource "outscale_user" "user-2" { + user_name = "User-TF-RW-2" + user_email = "test-TF12@test2.fr" + path = "/terraform2/" + policy { + policy_orn = outscale_policy.policy-2.orn + default_version_id = "V2" + } +} + + +resource "outscale_user_group" "group-No-policy" { + user_group_name = "Group-TF-test-1" + path = "/terraform/" + user { + user_name = outscale_user.user-1.user_name + path = "/terraform/" + } + user { + user_name = outscale_user.user-2.user_name + path = "/terraform2/" + } +depends_on=[outscale_user.user-1,outscale_user.user-2] +} + + +resource "outscale_policy" "policy-1" { + policy_name = "terraform-policy-1" + description = "test-terraform" + document = file("data/policies_files/policy.json") + path = "/" +} + +resource "outscale_policy" "policy-2" { + policy_name = "terraform-policy-2" + description = "test-terraform" + document = file("data/policies_files/policy.json") + path = "/" +} + +resource "outscale_policy_version" "policy-2" { + policy_orn = outscale_policy.policy-2.orn + document = file("data/policies_files/policy2.json") +} + +#################################################################@ + +#####Create the users belonging to the same policy group#### +resource "outscale_user" "multiple_users" { + count=3 + user_name = "TF-User-${count.index}" + user_email = "test-${count.index}@test2.fr" +} + + + +resource "outscale_user_group" "group-policy-RO" { + user_group_name = "Group-TF-RO" + user { + user_name = outscale_user.multiple_users[0].user_name + } + user { + user_name = outscale_user.multiple_users[1].user_name + } + user { + user_name = outscale_user.multiple_users[2].user_name + } +policy { + policy_orn = outscale_policy.policy-RO.orn + } +depends_on=[outscale_user.multiple_users[0],outscale_user.multiple_users[1],outscale_user.multiple_users[2]] +} + + +resource "outscale_policy" "policy-RO" { + policy_name = "terraform-policy-RO" + description = "test-terraform-ro" + document = file("data/policies_files/policy_RO.json") + path = "/" +} + diff --git a/tests/qa_provider_oapi/data/tests_iam_resources/TF005_all_iam_resources_attributes_ok/step2.all_iam_resources_update_ok.ref b/tests/qa_provider_oapi/data/tests_iam_resources/TF005_all_iam_resources_attributes_ok/step2.all_iam_resources_update_ok.ref new file mode 100644 index 000000000..fe68871ea --- /dev/null +++ b/tests/qa_provider_oapi/data/tests_iam_resources/TF005_all_iam_resources_attributes_ok/step2.all_iam_resources_update_ok.ref @@ -0,0 +1,347 @@ +{ + "version": "########", + "terraform_version": "########", + "serial": "########", + "lineage": "########", + "outputs": {}, + "resources": [ + { + "mode": "managed", + "type": "outscale_policy", + "name": "policy-1", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "creation_date": "########", + "description": "test-terraform", + "document": "{\n \"Statement\": [\n {\n \"Action\": [\n \"api:*\"\n ],\n \"Effect\": \"Allow\",\n \"Resource\": [\n \"*\"\n ]\n }\n ]\n}\n", + "id": "##id-0##", + "is_linkable": true, + "last_modification_date": "########", + "orn": "########", + "path": "/", + "policy_default_version_id": "##id-1##", + "policy_id": "##id-2##", + "policy_name": "terraform-policy-1", + "resources_count": 1 + }, + "sensitive_attributes": [], + "private": "bnVsbA==" + } + ] + }, + { + "mode": "managed", + "type": "outscale_policy", + "name": "policy-2", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "creation_date": "########", + "description": "test-terraform", + "document": "{\n \"Statement\": [\n {\n \"Action\": [\n \"api:*\"\n ],\n \"Effect\": \"Allow\",\n \"Resource\": [\n \"*\"\n ]\n }\n ]\n}\n", + "id": "##id-3##", + "is_linkable": true, + "last_modification_date": "########", + "orn": "########", + "path": "/", + "policy_default_version_id": "##id-4##", + "policy_id": "##id-5##", + "policy_name": "terraform-policy-2", + "resources_count": 1 + }, + "sensitive_attributes": [], + "private": "bnVsbA==" + } + ] + }, + { + "mode": "managed", + "type": "outscale_policy", + "name": "policy-RO", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "creation_date": "########", + "description": "test-terraform-ro", + "document": "{\n \"Statement\": [\n {\n \"Action\": [\n \"api:Read*\"\n ],\n \"Effect\": \"Allow\",\n \"Resource\": [\n \"*\"\n ]\n }\n ]\n} \n", + "id": "##id-6##", + "is_linkable": true, + "last_modification_date": "########", + "orn": "########", + "path": "/", + "policy_default_version_id": "##id-1##", + "policy_id": "##id-7##", + "policy_name": "terraform-policy-RO", + "resources_count": 1 + }, + "sensitive_attributes": [], + "private": "bnVsbA==" + } + ] + }, + { + "mode": "managed", + "type": "outscale_policy_version", + "name": "policy-2", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "body": "########", + "creation_date": "########", + "default_version": true, + "document": "{\n \"Statement\": [\n {\n \"Action\": [\n \"api:*VM*\"\n ],\n \"Effect\": \"Allow\",\n \"Resource\": [\n \"*\"\n ]\n }\n ]\n}\n", + "id": "##id-8##", + "policy_orn": "orn:ows:idauth::339215505907:policy/terraform-policy-2", + "set_as_default": null, + "version_id": "##id-4##" + }, + "sensitive_attributes": [], + "private": "bnVsbA==", + "dependencies": [ + "outscale_policy.policy-2" + ] + } + ] + }, + { + "mode": "managed", + "type": "outscale_user", + "name": "multiple_users", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "index_key": 0, + "schema_version": 0, + "attributes": { + "creation_date": "########", + "id": "##id-9##", + "last_modification_date": "########", + "path": "/", + "policy": [], + "user_email": "test-0@test2.fr", + "user_id": "##id-9##", + "user_name": "TF-User-0-3" + }, + "sensitive_attributes": [], + "private": "bnVsbA==" + }, + { + "index_key": 1, + "schema_version": 0, + "attributes": { + "creation_date": "########", + "id": "##id-10##", + "last_modification_date": "########", + "path": "/", + "policy": [], + "user_email": "test-1@test2.fr", + "user_id": "##id-10##", + "user_name": "TF-User-1-3" + }, + "sensitive_attributes": [], + "private": "bnVsbA==" + }, + { + "index_key": 2, + "schema_version": 0, + "attributes": { + "creation_date": "########", + "id": "##id-11##", + "last_modification_date": "########", + "path": "/", + "policy": [], + "user_email": "test-2@test2.fr", + "user_id": "##id-11##", + "user_name": "TF-User-2-3" + }, + "sensitive_attributes": [], + "private": "bnVsbA==" + } + ] + }, + { + "mode": "managed", + "type": "outscale_user", + "name": "user-1", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "creation_date": "########", + "id": "##id-12##", + "last_modification_date": "########", + "path": "/terraform/", + "policy": [ + { + "creation_date": "########", + "default_version_id": "##id-1##", + "last_modification_date": "########", + "policy_id": "##id-2##", + "policy_name": "terraform-policy-1", + "policy_orn": "orn:ows:idauth::339215505907:policy/terraform-policy-1" + } + ], + "user_email": "test-TF11@test2.fr", + "user_id": "##id-12##", + "user_name": "User-TF-RW-11" + }, + "sensitive_attributes": [], + "private": "bnVsbA==", + "dependencies": [ + "outscale_policy.policy-1" + ] + } + ] + }, + { + "mode": "managed", + "type": "outscale_user", + "name": "user-2", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "creation_date": "########", + "id": "##id-13##", + "last_modification_date": "########", + "path": "/terraform2/", + "policy": [ + { + "creation_date": "########", + "default_version_id": "##id-4##", + "last_modification_date": "########", + "policy_id": "##id-5##", + "policy_name": "terraform-policy-2", + "policy_orn": "orn:ows:idauth::339215505907:policy/terraform-policy-2" + } + ], + "user_email": "test-TF12@test2.fr", + "user_id": "##id-13##", + "user_name": "User-TF-RW-22" + }, + "sensitive_attributes": [], + "private": "bnVsbA==", + "dependencies": [ + "outscale_policy.policy-2" + ] + } + ] + }, + { + "mode": "managed", + "type": "outscale_user_group", + "name": "group-No-policy", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "creation_date": "########", + "id": "##id-14##", + "last_modification_date": "########", + "orn": "########", + "path": "/terraform/", + "policy": [], + "user": [ + { + "creation_date": "########", + "last_modification_date": "########", + "path": "/terraform/", + "user_id": "##id-12##", + "user_name": "User-TF-RW-11" + }, + { + "creation_date": "########", + "last_modification_date": "########", + "path": "/terraform2/", + "user_id": "##id-13##", + "user_name": "User-TF-RW-22" + } + ], + "user_group_id": "##id-14##", + "user_group_name": "Group-TF-test-1" + }, + "sensitive_attributes": [], + "private": "bnVsbA==", + "dependencies": [ + "outscale_policy.policy-1", + "outscale_policy.policy-2", + "outscale_user.user-1", + "outscale_user.user-2" + ] + } + ] + }, + { + "mode": "managed", + "type": "outscale_user_group", + "name": "group-policy-RO", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "creation_date": "########", + "id": "##id-15##", + "last_modification_date": "########", + "orn": "########", + "path": "/", + "policy": [ + { + "creation_date": "########", + "default_version_id": "##id-1##", + "last_modification_date": "########", + "policy_id": "##id-7##", + "policy_name": "terraform-policy-RO", + "policy_orn": "orn:ows:idauth::339215505907:policy/terraform-policy-RO" + } + ], + "user": [ + { + "creation_date": "########", + "last_modification_date": "########", + "path": "/", + "user_id": "##id-10##", + "user_name": "TF-User-1-3" + }, + { + "creation_date": "########", + "last_modification_date": "########", + "path": "/", + "user_id": "##id-11##", + "user_name": "TF-User-2-3" + }, + { + "creation_date": "########", + "last_modification_date": "########", + "path": "/", + "user_id": "##id-9##", + "user_name": "TF-User-0-3" + } + ], + "user_group_id": "##id-15##", + "user_group_name": "Group-TF-RO" + }, + "sensitive_attributes": [], + "private": "bnVsbA==", + "dependencies": [ + "outscale_policy.policy-RO", + "outscale_user.multiple_users" + ] + } + ] + } + ], + "check_results": "########" +} \ No newline at end of file diff --git a/tests/qa_provider_oapi/data/tests_iam_resources/TF005_all_iam_resources_attributes_ok/step2.all_iam_resources_update_ok.tf b/tests/qa_provider_oapi/data/tests_iam_resources/TF005_all_iam_resources_attributes_ok/step2.all_iam_resources_update_ok.tf new file mode 100644 index 000000000..fb5a712f4 --- /dev/null +++ b/tests/qa_provider_oapi/data/tests_iam_resources/TF005_all_iam_resources_attributes_ok/step2.all_iam_resources_update_ok.tf @@ -0,0 +1,90 @@ +resource "outscale_user" "user-1" { + user_name = "User-TF-RW-11" + user_email = "test-TF11@test2.fr" + path = "/terraform/" + policy { + policy_orn = outscale_policy.policy-1.orn + } +} + +resource "outscale_user" "user-2" { + user_name = "User-TF-RW-22" + user_email = "test-TF12@test2.fr" + path = "/terraform2/" + policy { + policy_orn = outscale_policy.policy-2.orn + default_version_id = "V2" + } +} + + +resource "outscale_user_group" "group-No-policy" { + user_group_name = "Group-TF-test-1" + path = "/terraform/" + user { + user_name = outscale_user.user-1.user_name + path = "/terraform/" + } + user { + user_name = outscale_user.user-2.user_name + path = "/terraform2/" + } +depends_on=[outscale_user.user-1,outscale_user.user-2] +} + + +resource "outscale_policy" "policy-1" { + policy_name = "terraform-policy-1" + description = "test-terraform" + document = file("data/policies_files/policy.json") + path = "/" +} + +resource "outscale_policy" "policy-2" { + policy_name = "terraform-policy-2" + description = "test-terraform" + document = file("data/policies_files/policy.json") + path = "/" +} + +resource "outscale_policy_version" "policy-2" { + policy_orn = outscale_policy.policy-2.orn + document = file("data/policies_files/policy2.json") +} + +#################################################################@ + +#####Create the users belonging to the same policy group#### +resource "outscale_user" "multiple_users" { + count=3 + user_name = "TF-User-${count.index}-3" + user_email = "test-${count.index}@test2.fr" +} + + + +resource "outscale_user_group" "group-policy-RO" { + user_group_name = "Group-TF-RO" + user { + user_name = outscale_user.multiple_users[0].user_name + } + user { + user_name = outscale_user.multiple_users[1].user_name + } + user { + user_name = outscale_user.multiple_users[2].user_name + } +policy { + policy_orn = outscale_policy.policy-RO.orn + } +depends_on=[outscale_user.multiple_users[0],outscale_user.multiple_users[1],outscale_user.multiple_users[2]] +} + + +resource "outscale_policy" "policy-RO" { + policy_name = "terraform-policy-RO" + description = "test-terraform-ro" + document = file("data/policies_files/policy_RO.json") + path = "/" +} + diff --git a/tests/qa_provider_oapi/data/tests_iam_resources/TF006_user_datasource_attribute_ok/step2.user_datasource_after_update_ok.ref b/tests/qa_provider_oapi/data/tests_iam_resources/TF006_user_datasource_attribute_ok/step2.user_datasource_after_update_ok.ref new file mode 100644 index 000000000..5cb62a42a --- /dev/null +++ b/tests/qa_provider_oapi/data/tests_iam_resources/TF006_user_datasource_attribute_ok/step2.user_datasource_after_update_ok.ref @@ -0,0 +1,134 @@ +{ + "version": "########", + "terraform_version": "########", + "serial": "########", + "lineage": "########", + "outputs": {}, + "resources": [ + { + "mode": "data", + "type": "outscale_access_key", + "name": "access_key_user01", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "access_key_id": "##id-0##", + "creation_date": "########", + "expiration_date": "", + "filter": "########", + "id": "##id-0##", + "last_modification_date": "########", + "request_id": "########", + "state": "INACTIVE", + "user_name": "User-TF-65" + }, + "sensitive_attributes": [] + } + ] + }, + { + "mode": "data", + "type": "outscale_access_keys", + "name": "access_keys_user01", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "access_key_ids": null, + "access_keys": [ + { + "access_key_id": "##id-0##", + "creation_date": "########", + "expiration_date": "", + "last_modification_date": "########", + "state": "INACTIVE" + } + ], + "filter": "########", + "id": "##id-1##", + "request_id": "########", + "states": null, + "user_name": "User-TF-65" + }, + "sensitive_attributes": [] + } + ] + }, + { + "mode": "data", + "type": "outscale_user", + "name": "user01", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "creation_date": "########", + "filter": "########", + "id": "##id-2##", + "last_modification_date": "########", + "path": "/test/terraform/", + "user_email": "test@test65.fr", + "user_id": "##id-3##", + "user_name": "User-TF-65" + }, + "sensitive_attributes": [] + } + ] + }, + { + "mode": "managed", + "type": "outscale_access_key", + "name": "access_key_01", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "access_key_id": "##id-0##", + "creation_date": "########", + "expiration_date": "", + "id": "##id-0##", + "last_modification_date": "########", + "request_id": "########", + "secret_key": "########", + "state": "INACTIVE", + "user_name": "User-TF-65" + }, + "sensitive_attributes": [], + "private": "bnVsbA==", + "dependencies": [ + "outscale_user.user1" + ] + } + ] + }, + { + "mode": "managed", + "type": "outscale_user", + "name": "user1", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "creation_date": "########", + "id": "##id-3##", + "last_modification_date": "########", + "path": "/test/terraform/", + "policy": [], + "user_email": "test@test65.fr", + "user_id": "##id-3##", + "user_name": "User-TF-65" + }, + "sensitive_attributes": [], + "private": "bnVsbA==" + } + ] + } + ], + "check_results": "########" +} \ No newline at end of file diff --git a/tests/qa_provider_oapi/data/tests_iam_resources/TF006_user_datasource_attribute_ok/step2.user_datasource_after_update_ok.tf b/tests/qa_provider_oapi/data/tests_iam_resources/TF006_user_datasource_attribute_ok/step2.user_datasource_after_update_ok.tf new file mode 100644 index 000000000..cf0bce4ef --- /dev/null +++ b/tests/qa_provider_oapi/data/tests_iam_resources/TF006_user_datasource_attribute_ok/step2.user_datasource_after_update_ok.tf @@ -0,0 +1,45 @@ +resource "outscale_user" "user1" { + user_name = "User-TF-65" + user_email = "test@test65.fr" + path = "/test/terraform/" +} + +resource "outscale_access_key" "access_key_01" { + user_name = outscale_user.user1.user_name + expiration_date = "2038-01-01" + state = "INACTIVE" +depends_on=[outscale_user.user1] +} + + +data "outscale_user" "user01" { + filter { + name = "user_ids" + values = [outscale_user.user1.user_id] + } +} + +data "outscale_access_key" "access_key_user01" { + user_name = outscale_user.user1.user_name + filter { + name = "access_key_ids" + values = [outscale_access_key.access_key_01.access_key_id] + } + + filter { + name = "states" + values = ["INACTIVE"] + } +depends_on=[outscale_user.user1] +} + + +data "outscale_access_keys" "access_keys_user01" { + user_name = outscale_user.user1.user_name + filter { + name = "access_key_ids" + values = [outscale_access_key.access_key_01.access_key_id] + } +depends_on=[outscale_user.user1] +} + diff --git a/tests/qa_provider_oapi/data/tests_iam_resources/TF007_users_datasource_attributes_ok/step1.users_datasource_attributes_ok.ref b/tests/qa_provider_oapi/data/tests_iam_resources/TF007_users_datasource_attributes_ok/step1.users_datasource_attributes_ok.ref new file mode 100644 index 000000000..a9d6d4f8a --- /dev/null +++ b/tests/qa_provider_oapi/data/tests_iam_resources/TF007_users_datasource_attributes_ok/step1.users_datasource_attributes_ok.ref @@ -0,0 +1,90 @@ +{ + "version": "########", + "terraform_version": "########", + "serial": "########", + "lineage": "########", + "outputs": {}, + "resources": [ + { + "mode": "data", + "type": "outscale_users", + "name": "my_users", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "filter": "########", + "id": "##id-0##", + "users": [ + { + "creation_date": "########", + "last_modification_date": "########", + "path": "/terraform/", + "user_email": "test-TF11@test2.fr", + "user_id": "##id-1##", + "user_name": "User-TF-11" + }, + { + "creation_date": "########", + "last_modification_date": "########", + "path": "/terraform2/", + "user_email": "test-TF12@test2.fr", + "user_id": "##id-2##", + "user_name": "User-TF-12" + } + ] + }, + "sensitive_attributes": [] + } + ] + }, + { + "mode": "managed", + "type": "outscale_user", + "name": "user-1", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "creation_date": "########", + "id": "##id-1##", + "last_modification_date": "########", + "path": "/terraform/", + "policy": [], + "user_email": "test-TF11@test2.fr", + "user_id": "##id-1##", + "user_name": "User-TF-11" + }, + "sensitive_attributes": [], + "private": "bnVsbA==" + } + ] + }, + { + "mode": "managed", + "type": "outscale_user", + "name": "user-2", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "creation_date": "########", + "id": "##id-2##", + "last_modification_date": "########", + "path": "/terraform2/", + "policy": [], + "user_email": "test-TF12@test2.fr", + "user_id": "##id-2##", + "user_name": "User-TF-12" + }, + "sensitive_attributes": [], + "private": "bnVsbA==" + } + ] + } + ], + "check_results": "########" +} \ No newline at end of file diff --git a/tests/qa_provider_oapi/data/tests_iam_resources/TF007_users_datasource_attributes_ok/step1.users_datasource_attributes_ok.tf b/tests/qa_provider_oapi/data/tests_iam_resources/TF007_users_datasource_attributes_ok/step1.users_datasource_attributes_ok.tf new file mode 100644 index 000000000..364f01fe2 --- /dev/null +++ b/tests/qa_provider_oapi/data/tests_iam_resources/TF007_users_datasource_attributes_ok/step1.users_datasource_attributes_ok.tf @@ -0,0 +1,19 @@ +resource "outscale_user" "user-1" { + user_name = "User-TF-11" + user_email = "test-TF11@test2.fr" + path = "/terraform/" +} + +resource "outscale_user" "user-2" { + user_name = "User-TF-12" + user_email = "test-TF12@test2.fr" + path = "/terraform2/" +} + +data "outscale_users" "my_users" { + filter { + name = "user_ids" + values = [outscale_user.user-1.user_id,outscale_user.user-2.user_id] + } +} + diff --git a/tests/qa_provider_oapi/data/tests_iam_resources/TF008_user_group_datasource_attributes_ok/step1.user_group_datasource_attributes_ok.ref b/tests/qa_provider_oapi/data/tests_iam_resources/TF008_user_group_datasource_attributes_ok/step1.user_group_datasource_attributes_ok.ref new file mode 100644 index 000000000..acd370b0d --- /dev/null +++ b/tests/qa_provider_oapi/data/tests_iam_resources/TF008_user_group_datasource_attributes_ok/step1.user_group_datasource_attributes_ok.ref @@ -0,0 +1,138 @@ +{ + "version": "########", + "terraform_version": "########", + "serial": "########", + "lineage": "########", + "outputs": {}, + "resources": [ + { + "mode": "data", + "type": "outscale_user_group", + "name": "user_group01", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "creation_date": "########", + "id": "##id-0##", + "last_modification_date": "########", + "orn": "########", + "path": "/terraform/", + "user": [ + { + "creation_date": "########", + "last_modification_date": "########", + "path": "/terraform/", + "user_email": "test-TF011@test2.fr", + "user_id": "##id-1##", + "user_name": "User-TF-001" + }, + { + "creation_date": "########", + "last_modification_date": "########", + "path": "/terraform2/", + "user_email": "test-TF002@test2.fr", + "user_id": "##id-2##", + "user_name": "User-TF-002" + } + ], + "user_group_id": "##id-3##", + "user_group_name": "Group-TF-test-1" + }, + "sensitive_attributes": [] + } + ] + }, + { + "mode": "managed", + "type": "outscale_user", + "name": "user-1", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "creation_date": "########", + "id": "##id-1##", + "last_modification_date": "########", + "path": "/terraform/", + "policy": [], + "user_email": "test-TF011@test2.fr", + "user_id": "##id-1##", + "user_name": "User-TF-001" + }, + "sensitive_attributes": [], + "private": "bnVsbA==" + } + ] + }, + { + "mode": "managed", + "type": "outscale_user", + "name": "user-2", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "creation_date": "########", + "id": "##id-2##", + "last_modification_date": "########", + "path": "/terraform2/", + "policy": [], + "user_email": "test-TF002@test2.fr", + "user_id": "##id-2##", + "user_name": "User-TF-002" + }, + "sensitive_attributes": [], + "private": "bnVsbA==" + } + ] + }, + { + "mode": "managed", + "type": "outscale_user_group", + "name": "group-1", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "creation_date": "########", + "id": "##id-3##", + "last_modification_date": "########", + "orn": "########", + "path": "/terraform/", + "policy": [], + "user": [ + { + "creation_date": "########", + "last_modification_date": "########", + "path": "/terraform/", + "user_id": "##id-1##", + "user_name": "User-TF-001" + }, + { + "creation_date": "########", + "last_modification_date": "########", + "path": "/terraform2/", + "user_id": "##id-2##", + "user_name": "User-TF-002" + } + ], + "user_group_id": "##id-3##", + "user_group_name": "Group-TF-test-1" + }, + "sensitive_attributes": [], + "private": "bnVsbA==", + "dependencies": [ + "outscale_user.user-1", + "outscale_user.user-2" + ] + } + ] + } + ], + "check_results": "########" +} \ No newline at end of file diff --git a/tests/qa_provider_oapi/data/tests_iam_resources/TF008_user_group_datasource_attributes_ok/step1.user_group_datasource_attributes_ok.tf b/tests/qa_provider_oapi/data/tests_iam_resources/TF008_user_group_datasource_attributes_ok/step1.user_group_datasource_attributes_ok.tf new file mode 100644 index 000000000..637ada987 --- /dev/null +++ b/tests/qa_provider_oapi/data/tests_iam_resources/TF008_user_group_datasource_attributes_ok/step1.user_group_datasource_attributes_ok.tf @@ -0,0 +1,37 @@ +resource "outscale_user" "user-1" { + user_name = "User-TF-001" + user_email = "test-TF011@test2.fr" + path = "/terraform/" +} + +resource "outscale_user" "user-2" { + user_name = "User-TF-002" + user_email = "test-TF002@test2.fr" + path = "/terraform2/" +} + + + +resource "outscale_user_group" "group-1" { + user_group_name = "Group-TF-test-1" + path = "/terraform/" + user { + user_name = outscale_user.user-1.user_name + path = "/terraform/" + } + user { + user_name = outscale_user.user-2.user_name + path = "/terraform2/" + } +depends_on=[outscale_user.user-1,outscale_user.user-2] +} + + + +data "outscale_user_group" "user_group01" { + user_group_name = outscale_user_group.group-1.user_group_name + path = outscale_user_group.group-1.path +depends_on=[outscale_user_group.group-1] +} + + diff --git a/tests/qa_provider_oapi/data/tests_iam_resources/TF009_user_groups_datasource_attributes_ok/step1.user_groups_datasource_attributes_ok.ref b/tests/qa_provider_oapi/data/tests_iam_resources/TF009_user_groups_datasource_attributes_ok/step1.user_groups_datasource_attributes_ok.ref new file mode 100644 index 000000000..256f1aac7 --- /dev/null +++ b/tests/qa_provider_oapi/data/tests_iam_resources/TF009_user_groups_datasource_attributes_ok/step1.user_groups_datasource_attributes_ok.ref @@ -0,0 +1,183 @@ +{ + "version": "########", + "terraform_version": "########", + "serial": "########", + "lineage": "########", + "outputs": {}, + "resources": [ + { + "mode": "data", + "type": "outscale_user_groups", + "name": "usegroups01", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "filter": "########", + "id": "##id-0##", + "user_groups": [ + { + "creation_date": "########", + "last_modification_date": "########", + "orn": "########", + "path": "/terraform/", + "user_group_id": "##id-1##", + "user_group_name": "Group-TF-test-1" + } + ] + }, + "sensitive_attributes": [] + } + ] + }, + { + "mode": "data", + "type": "outscale_user_groups", + "name": "usegroups02", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "filter": "########", + "id": "##id-2##", + "user_groups": [ + { + "creation_date": "########", + "last_modification_date": "########", + "orn": "########", + "path": "/terraform3/", + "user_group_id": "##id-3##", + "user_group_name": "Group-TF-test-2" + }, + { + "creation_date": "########", + "last_modification_date": "########", + "orn": "########", + "path": "/terraform/", + "user_group_id": "##id-1##", + "user_group_name": "Group-TF-test-1" + } + ] + }, + "sensitive_attributes": [] + } + ] + }, + { + "mode": "managed", + "type": "outscale_user", + "name": "user-1", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "creation_date": "########", + "id": "##id-4##", + "last_modification_date": "########", + "path": "/terraform/", + "policy": [], + "user_email": "test-TF11@test2.fr", + "user_id": "##id-4##", + "user_name": "User-TF-11" + }, + "sensitive_attributes": [], + "private": "bnVsbA==" + } + ] + }, + { + "mode": "managed", + "type": "outscale_user", + "name": "user-2", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "creation_date": "########", + "id": "##id-5##", + "last_modification_date": "########", + "path": "/terraform2/", + "policy": [], + "user_email": "test-TF12@test2.fr", + "user_id": "##id-5##", + "user_name": "User-TF-12" + }, + "sensitive_attributes": [], + "private": "bnVsbA==" + } + ] + }, + { + "mode": "managed", + "type": "outscale_user_group", + "name": "group-1", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "creation_date": "########", + "id": "##id-1##", + "last_modification_date": "########", + "orn": "########", + "path": "/terraform/", + "policy": [], + "user": [ + { + "creation_date": "########", + "last_modification_date": "########", + "path": "/terraform/", + "user_id": "##id-4##", + "user_name": "User-TF-11" + }, + { + "creation_date": "########", + "last_modification_date": "########", + "path": "/terraform2/", + "user_id": "##id-5##", + "user_name": "User-TF-12" + } + ], + "user_group_id": "##id-1##", + "user_group_name": "Group-TF-test-1" + }, + "sensitive_attributes": [], + "private": "bnVsbA==", + "dependencies": [ + "outscale_user.user-1", + "outscale_user.user-2" + ] + } + ] + }, + { + "mode": "managed", + "type": "outscale_user_group", + "name": "group-2", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "creation_date": "########", + "id": "##id-3##", + "last_modification_date": "########", + "orn": "########", + "path": "/terraform3/", + "policy": [], + "user": [], + "user_group_id": "##id-3##", + "user_group_name": "Group-TF-test-2" + }, + "sensitive_attributes": [], + "private": "bnVsbA==" + } + ] + } + ], + "check_results": "########" +} \ No newline at end of file diff --git a/tests/qa_provider_oapi/data/tests_iam_resources/TF009_user_groups_datasource_attributes_ok/step1.user_groups_datasource_attributes_ok.tf b/tests/qa_provider_oapi/data/tests_iam_resources/TF009_user_groups_datasource_attributes_ok/step1.user_groups_datasource_attributes_ok.tf new file mode 100644 index 000000000..56ffa617e --- /dev/null +++ b/tests/qa_provider_oapi/data/tests_iam_resources/TF009_user_groups_datasource_attributes_ok/step1.user_groups_datasource_attributes_ok.tf @@ -0,0 +1,49 @@ +resource "outscale_user" "user-1" { + user_name = "User-TF-11" + user_email = "test-TF11@test2.fr" + path = "/terraform/" +} + +resource "outscale_user" "user-2" { + user_name = "User-TF-12" + user_email = "test-TF12@test2.fr" + path = "/terraform2/" +} + +resource "outscale_user_group" "group-1" { + user_group_name = "Group-TF-test-1" + path = "/terraform/" + user { + user_name = outscale_user.user-1.user_name + path = "/terraform/" + } + user { + user_name = outscale_user.user-2.user_name + path = "/terraform2/" + } +depends_on=[outscale_user.user-1,outscale_user.user-2] +} + +resource "outscale_user_group" "group-2" { + user_group_name = "Group-TF-test-2" + path = "/terraform3/" +} + + +data "outscale_user_groups" "usegroups01" { + filter { + name = "user_group_ids" + values = [outscale_user_group.group-1.user_group_id,outscale_user_group.group-2.user_group_id] + } + filter { + name = "path_prefix" + values = [outscale_user_group.group-1.path] + } +} + +data "outscale_user_groups" "usegroups02" { + filter { + name = "user_group_ids" + values = [outscale_user_group.group-1.user_group_id,outscale_user_group.group-2.user_group_id] + } +} diff --git a/tests/qa_provider_oapi/data/tests_iam_resources/TF010_policy_datasource_attributes_ok/step1.policy_datasource_attributes_ok.ref b/tests/qa_provider_oapi/data/tests_iam_resources/TF010_policy_datasource_attributes_ok/step1.policy_datasource_attributes_ok.ref new file mode 100644 index 000000000..a1f2b2a8e --- /dev/null +++ b/tests/qa_provider_oapi/data/tests_iam_resources/TF010_policy_datasource_attributes_ok/step1.policy_datasource_attributes_ok.ref @@ -0,0 +1,161 @@ +{ + "version": "########", + "terraform_version": "########", + "serial": "########", + "lineage": "########", + "outputs": {}, + "resources": [ + { + "mode": "data", + "type": "outscale_policy", + "name": "user_policy01", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "creation_date": "########", + "description": "test-terraform-11", + "document": null, + "id": "##id-0##", + "is_linkable": true, + "last_modification_date": "########", + "orn": "########", + "path": "/", + "policy_default_version_id": "##id-1##", + "policy_id": "##id-2##", + "policy_name": "terraform-policy-11", + "policy_orn": "orn:ows:idauth::339215505907:policy/terraform-policy-11", + "resources_count": 2 + }, + "sensitive_attributes": [] + } + ] + }, + { + "mode": "managed", + "type": "outscale_policy", + "name": "policy-1", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "creation_date": "########", + "description": "test-terraform-11", + "document": "{\n \"Statement\": [\n {\n \"Action\": [\n \"api:*\"\n ],\n \"Effect\": \"Allow\",\n \"Resource\": [\n \"*\"\n ]\n }\n ]\n}\n", + "id": "##id-3##", + "is_linkable": true, + "last_modification_date": "########", + "orn": "########", + "path": "/", + "policy_default_version_id": "##id-4##", + "policy_id": "##id-2##", + "policy_name": "terraform-policy-11", + "resources_count": 0 + }, + "sensitive_attributes": [], + "private": "bnVsbA==" + } + ] + }, + { + "mode": "managed", + "type": "outscale_policy_version", + "name": "policy11-version-02", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "body": "########", + "creation_date": "########", + "default_version": true, + "document": "{\n \"Statement\": [\n {\n \"Action\": [\n \"api:Read*\"\n ],\n \"Effect\": \"Allow\",\n \"Resource\": [\n \"*\"\n ]\n }\n ]\n}\n", + "id": "##id-5##", + "policy_orn": "orn:ows:idauth::339215505907:policy/terraform-policy-11", + "set_as_default": true, + "version_id": "##id-1##" + }, + "sensitive_attributes": [], + "private": "bnVsbA==", + "dependencies": [ + "outscale_policy.policy-1" + ] + } + ] + }, + { + "mode": "managed", + "type": "outscale_user", + "name": "user-1", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "creation_date": "########", + "id": "##id-6##", + "last_modification_date": "########", + "path": "/", + "policy": [ + { + "creation_date": "########", + "default_version_id": "##id-1##", + "last_modification_date": "########", + "policy_id": "##id-2##", + "policy_name": "terraform-policy-11", + "policy_orn": "orn:ows:idauth::339215505907:policy/terraform-policy-11" + } + ], + "user_email": "customer-tooling@outscale.com", + "user_id": "##id-6##", + "user_name": "User-TF-1" + }, + "sensitive_attributes": [], + "private": "bnVsbA==", + "dependencies": [ + "outscale_policy.policy-1" + ] + } + ] + }, + { + "mode": "managed", + "type": "outscale_user_group", + "name": "group-1", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "creation_date": "########", + "id": "##id-7##", + "last_modification_date": "########", + "orn": "########", + "path": "/terraform/", + "policy": [ + { + "creation_date": "########", + "default_version_id": "##id-1##", + "last_modification_date": "########", + "policy_id": "##id-2##", + "policy_name": "terraform-policy-11", + "policy_orn": "orn:ows:idauth::339215505907:policy/terraform-policy-11" + } + ], + "user": [], + "user_group_id": "##id-7##", + "user_group_name": "Group-TF-test-1" + }, + "sensitive_attributes": [], + "private": "bnVsbA==", + "dependencies": [ + "outscale_policy.policy-1" + ] + } + ] + } + ], + "check_results": "########" +} \ No newline at end of file diff --git a/tests/qa_provider_oapi/data/tests_iam_resources/TF010_policy_datasource_attributes_ok/step1.policy_datasource_attributes_ok.tf b/tests/qa_provider_oapi/data/tests_iam_resources/TF010_policy_datasource_attributes_ok/step1.policy_datasource_attributes_ok.tf new file mode 100644 index 000000000..98813ea4f --- /dev/null +++ b/tests/qa_provider_oapi/data/tests_iam_resources/TF010_policy_datasource_attributes_ok/step1.policy_datasource_attributes_ok.tf @@ -0,0 +1,31 @@ +resource "outscale_policy" "policy-1" { + policy_name = "terraform-policy-11" + description = "test-terraform-11" + document = file("data/policies_files/policy11.json") + path = "/" +} +resource "outscale_policy_version" "policy11-version-02" { + policy_orn = outscale_policy.policy-1.orn + document = file("data/policies_files/policy12.json") + set_as_default = true +} + +resource "outscale_user" "user-1" { + user_name = "User-TF-1" + policy { + policy_orn = outscale_policy.policy-1.orn + } +} + +resource "outscale_user_group" "group-1" { + user_group_name = "Group-TF-test-1" + path = "/terraform/" +policy { + policy_orn = outscale_policy.policy-1.orn + } +} + +data "outscale_policy" "user_policy01" { + policy_orn = outscale_policy.policy-1.orn +depends_on=[outscale_policy_version.policy11-version-02,outscale_user.user-1,outscale_user_group.group-1] +} diff --git a/tests/qa_provider_oapi/data/tests_iam_resources/TF011_policies_datasource_attributes_ok/step1.policies_datasource_attributes_ok.ref b/tests/qa_provider_oapi/data/tests_iam_resources/TF011_policies_datasource_attributes_ok/step1.policies_datasource_attributes_ok.ref new file mode 100644 index 000000000..881fa0f21 --- /dev/null +++ b/tests/qa_provider_oapi/data/tests_iam_resources/TF011_policies_datasource_attributes_ok/step1.policies_datasource_attributes_ok.ref @@ -0,0 +1,191 @@ +{ + "version": "########", + "terraform_version": "########", + "serial": "########", + "lineage": "########", + "outputs": {}, + "resources": [ + { + "mode": "data", + "type": "outscale_policies", + "name": "Mypolicies01", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "filter": "########", + "id": "##id-0##", + "policies": [ + { + "creation_date": "########", + "description": "test-terraform-11", + "is_linkable": true, + "last_modification_date": "########", + "orn": "########", + "path": "/policy1/", + "policy_default_version_id": "##id-1##", + "policy_id": "##id-2##", + "policy_name": "terraform-policy-11", + "resources_count": 0 + } + ] + }, + "sensitive_attributes": [] + } + ] + }, + { + "mode": "managed", + "type": "outscale_policy", + "name": "policy-1", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "creation_date": "########", + "description": "test-terraform-11", + "document": "{\n \"Statement\": [\n {\n \"Action\": [\n \"api:*\"\n ],\n \"Effect\": \"Allow\",\n \"Resource\": [\n \"*\"\n ]\n }\n ]\n}\n", + "id": "##id-3##", + "is_linkable": true, + "last_modification_date": "########", + "orn": "########", + "path": "/policy1/", + "policy_default_version_id": "##id-1##", + "policy_id": "##id-2##", + "policy_name": "terraform-policy-11", + "resources_count": 0 + }, + "sensitive_attributes": [], + "private": "bnVsbA==" + } + ] + }, + { + "mode": "managed", + "type": "outscale_policy", + "name": "policy-12", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "creation_date": "########", + "description": "test-terraform-12", + "document": "{\n \"Statement\": [\n {\n \"Action\": [\n \"api:Read*\"\n ],\n \"Effect\": \"Allow\",\n \"Resource\": [\n \"*\"\n ]\n }\n ]\n}\n", + "id": "##id-4##", + "is_linkable": true, + "last_modification_date": "########", + "orn": "########", + "path": "/policy12/", + "policy_default_version_id": "##id-1##", + "policy_id": "##id-5##", + "policy_name": "terraform-policy-12", + "resources_count": 0 + }, + "sensitive_attributes": [], + "private": "bnVsbA==" + } + ] + }, + { + "mode": "managed", + "type": "outscale_policy_version", + "name": "policy11-version-02", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "body": "########", + "creation_date": "########", + "default_version": true, + "document": "{\n \"Statement\": [\n {\n \"Action\": [\n \"api:Read*\"\n ],\n \"Effect\": \"Allow\",\n \"Resource\": [\n \"*\"\n ]\n }\n ]\n}\n", + "id": "##id-6##", + "policy_orn": "orn:ows:idauth::339215505907:policy/policy1/terraform-policy-11", + "set_as_default": true, + "version_id": "##id-7##" + }, + "sensitive_attributes": [], + "private": "bnVsbA==", + "dependencies": [ + "outscale_policy.policy-1" + ] + } + ] + }, + { + "mode": "managed", + "type": "outscale_user", + "name": "user-1", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "creation_date": "########", + "id": "##id-8##", + "last_modification_date": "########", + "path": "/", + "policy": [ + { + "creation_date": "########", + "default_version_id": "##id-7##", + "last_modification_date": "########", + "policy_id": "##id-2##", + "policy_name": "terraform-policy-11", + "policy_orn": "orn:ows:idauth::339215505907:policy/policy1/terraform-policy-11" + } + ], + "user_email": "customer-tooling@outscale.com", + "user_id": "##id-8##", + "user_name": "User-TF-1" + }, + "sensitive_attributes": [], + "private": "bnVsbA==", + "dependencies": [ + "outscale_policy.policy-1" + ] + } + ] + }, + { + "mode": "managed", + "type": "outscale_user_group", + "name": "group-1", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "creation_date": "########", + "id": "##id-9##", + "last_modification_date": "########", + "orn": "########", + "path": "/terraform/", + "policy": [ + { + "creation_date": "########", + "default_version_id": "##id-7##", + "last_modification_date": "########", + "policy_id": "##id-2##", + "policy_name": "terraform-policy-11", + "policy_orn": "orn:ows:idauth::339215505907:policy/policy1/terraform-policy-11" + } + ], + "user": [], + "user_group_id": "##id-9##", + "user_group_name": "Group-TF-test-1" + }, + "sensitive_attributes": [], + "private": "bnVsbA==", + "dependencies": [ + "outscale_policy.policy-1" + ] + } + ] + } + ], + "check_results": "########" +} \ No newline at end of file diff --git a/tests/qa_provider_oapi/data/tests_iam_resources/TF011_policies_datasource_attributes_ok/step1.policies_datasource_attributes_ok.tf b/tests/qa_provider_oapi/data/tests_iam_resources/TF011_policies_datasource_attributes_ok/step1.policies_datasource_attributes_ok.tf new file mode 100644 index 000000000..843ccc893 --- /dev/null +++ b/tests/qa_provider_oapi/data/tests_iam_resources/TF011_policies_datasource_attributes_ok/step1.policies_datasource_attributes_ok.tf @@ -0,0 +1,41 @@ +resource "outscale_policy" "policy-1" { + policy_name = "terraform-policy-11" + description = "test-terraform-11" + document = file("data/policies_files/policy11.json") + path = "/policy1/" +} +resource "outscale_policy_version" "policy11-version-02" { + policy_orn = outscale_policy.policy-1.orn + document = file("data/policies_files/policy12.json") + set_as_default = true +} + +resource "outscale_user" "user-1" { + user_name = "User-TF-1" + policy { + policy_orn = outscale_policy.policy-1.orn + } +} + +resource "outscale_user_group" "group-1" { + user_group_name = "Group-TF-test-1" + path = "/terraform/" +policy { + policy_orn = outscale_policy.policy-1.orn + } +} + +resource "outscale_policy" "policy-12" { + policy_name = "terraform-policy-12" + description = "test-terraform-12" + document = file("data/policies_files/policy12.json") + path = "/policy12/" +} + + +data "outscale_policies" "Mypolicies01" { + filter { + name = "path_prefix" + values = [outscale_policy.policy-1.path,outscale_policy.policy-12.path] + } +} diff --git a/tests/qa_provider_oapi/data/tests_iam_resources/TF012_policies_linked_to_user_datasource_attributes_ok/step1.policies_linked_to_user_datasource_attributes_ok.ref b/tests/qa_provider_oapi/data/tests_iam_resources/TF012_policies_linked_to_user_datasource_attributes_ok/step1.policies_linked_to_user_datasource_attributes_ok.ref new file mode 100644 index 000000000..d865930e0 --- /dev/null +++ b/tests/qa_provider_oapi/data/tests_iam_resources/TF012_policies_linked_to_user_datasource_attributes_ok/step1.policies_linked_to_user_datasource_attributes_ok.ref @@ -0,0 +1,140 @@ +{ + "version": "########", + "terraform_version": "########", + "serial": "########", + "lineage": "########", + "outputs": {}, + "resources": [ + { + "mode": "data", + "type": "outscale_policies_linked_to_user", + "name": "linked_policy01", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "id": "##id-0##", + "policies": [ + { + "creation_date": "########", + "last_modification_date": "########", + "orn": "########", + "policy_id": "##id-1##", + "policy_name": "terraform-policy-1" + }, + { + "creation_date": "########", + "last_modification_date": "########", + "orn": "########", + "policy_id": "##id-2##", + "policy_name": "terraform-policy-2" + } + ], + "user_name": "User-TF-linkPolicy" + }, + "sensitive_attributes": [] + } + ] + }, + { + "mode": "managed", + "type": "outscale_policy", + "name": "policy-1", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "creation_date": "########", + "description": "test-terraform", + "document": "{\n \"Statement\": [\n {\n \"Action\": [\n \"api:*\"\n ],\n \"Effect\": \"Allow\",\n \"Resource\": [\n \"*\"\n ]\n }\n ]\n}\n", + "id": "##id-3##", + "is_linkable": true, + "last_modification_date": "########", + "orn": "########", + "path": "/", + "policy_default_version_id": "##id-4##", + "policy_id": "##id-1##", + "policy_name": "terraform-policy-1", + "resources_count": 0 + }, + "sensitive_attributes": [], + "private": "bnVsbA==" + } + ] + }, + { + "mode": "managed", + "type": "outscale_policy", + "name": "policy-2", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "creation_date": "########", + "description": "test-terraform-2", + "document": "{\n \"Statement\": [\n {\n \"Action\": [\n \"api:Read*\"\n ],\n \"Effect\": \"Allow\",\n \"Resource\": [\n \"*\"\n ]\n }\n ]\n}\n", + "id": "##id-5##", + "is_linkable": true, + "last_modification_date": "########", + "orn": "########", + "path": "/terraform2/", + "policy_default_version_id": "##id-4##", + "policy_id": "##id-2##", + "policy_name": "terraform-policy-2", + "resources_count": 0 + }, + "sensitive_attributes": [], + "private": "bnVsbA==" + } + ] + }, + { + "mode": "managed", + "type": "outscale_user", + "name": "user-policy", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "creation_date": "########", + "id": "##id-6##", + "last_modification_date": "########", + "path": "/", + "policy": [ + { + "creation_date": "########", + "default_version_id": "##id-4##", + "last_modification_date": "########", + "policy_id": "##id-2##", + "policy_name": "terraform-policy-2", + "policy_orn": "orn:ows:idauth::339215505907:policy/terraform2/terraform-policy-2" + }, + { + "creation_date": "########", + "default_version_id": "##id-4##", + "last_modification_date": "########", + "policy_id": "##id-1##", + "policy_name": "terraform-policy-1", + "policy_orn": "orn:ows:idauth::339215505907:policy/terraform-policy-1" + } + ], + "user_email": "customer-tooling@outscale.com", + "user_id": "##id-6##", + "user_name": "User-TF-linkPolicy" + }, + "sensitive_attributes": [], + "private": "bnVsbA==", + "dependencies": [ + "outscale_policy.policy-1", + "outscale_policy.policy-2" + ] + } + ] + } + ], + "check_results": "########" +} \ No newline at end of file diff --git a/tests/qa_provider_oapi/data/tests_iam_resources/TF012_policies_linked_to_user_datasource_attributes_ok/step1.policies_linked_to_user_datasource_attributes_ok.tf b/tests/qa_provider_oapi/data/tests_iam_resources/TF012_policies_linked_to_user_datasource_attributes_ok/step1.policies_linked_to_user_datasource_attributes_ok.tf new file mode 100644 index 000000000..0df5e2cb8 --- /dev/null +++ b/tests/qa_provider_oapi/data/tests_iam_resources/TF012_policies_linked_to_user_datasource_attributes_ok/step1.policies_linked_to_user_datasource_attributes_ok.tf @@ -0,0 +1,31 @@ +resource "outscale_user" "user-policy" { + user_name = "User-TF-linkPolicy" + policy { + policy_orn = outscale_policy.policy-1.orn + } + policy { + policy_orn = outscale_policy.policy-2.orn + } +} +resource "outscale_policy" "policy-1" { + policy_name = "terraform-policy-1" + description = "test-terraform" + document = file("data/policies_files/policy11.json") + path = "/" +} + +resource "outscale_policy" "policy-2" { + policy_name = "terraform-policy-2" + description = "test-terraform-2" + document = file("data/policies_files/policy12.json") + path = "/terraform2/" +} + + +data "outscale_policies_linked_to_user" "linked_policy01" { + + user_name= outscale_user.user-policy.user_name + +depends_on=[outscale_user.user-policy] + +} diff --git a/tests/qa_provider_oapi/data/tests_iam_resources/TF013_policies_linked_to_user_group_datasource_attributes_ok/step1.policies_linked_to_user_group_datasource_attributes_ok.ref b/tests/qa_provider_oapi/data/tests_iam_resources/TF013_policies_linked_to_user_group_datasource_attributes_ok/step1.policies_linked_to_user_group_datasource_attributes_ok.ref new file mode 100644 index 000000000..ab983c8f2 --- /dev/null +++ b/tests/qa_provider_oapi/data/tests_iam_resources/TF013_policies_linked_to_user_group_datasource_attributes_ok/step1.policies_linked_to_user_group_datasource_attributes_ok.ref @@ -0,0 +1,142 @@ +{ + "version": "########", + "terraform_version": "########", + "serial": "########", + "lineage": "########", + "outputs": {}, + "resources": [ + { + "mode": "data", + "type": "outscale_policies_linked_to_user_group", + "name": "managed_policies_linked_to_user_group", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "filter": "########", + "id": "##id-0##", + "policies": [ + { + "creation_date": "########", + "last_modification_date": "########", + "orn": "########", + "policy_id": "##id-1##", + "policy_name": "terraform-policy-1" + }, + { + "creation_date": "########", + "last_modification_date": "########", + "orn": "########", + "policy_id": "##id-2##", + "policy_name": "terraform-policy-2" + } + ], + "user_group_name": "Group-TF-policy-1" + }, + "sensitive_attributes": [] + } + ] + }, + { + "mode": "managed", + "type": "outscale_policy", + "name": "policy-1", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "creation_date": "########", + "description": "test-terraform", + "document": "{\n \"Statement\": [\n {\n \"Action\": [\n \"api:*\"\n ],\n \"Effect\": \"Allow\",\n \"Resource\": [\n \"*\"\n ]\n }\n ]\n}\n", + "id": "##id-3##", + "is_linkable": true, + "last_modification_date": "########", + "orn": "########", + "path": "/", + "policy_default_version_id": "##id-4##", + "policy_id": "##id-1##", + "policy_name": "terraform-policy-1", + "resources_count": 0 + }, + "sensitive_attributes": [], + "private": "bnVsbA==" + } + ] + }, + { + "mode": "managed", + "type": "outscale_policy", + "name": "policy-2", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "creation_date": "########", + "description": "test-terraform", + "document": "{\n \"Statement\": [\n {\n \"Action\": [\n \"api:Read*\"\n ],\n \"Effect\": \"Allow\",\n \"Resource\": [\n \"*\"\n ]\n }\n ]\n}\n", + "id": "##id-5##", + "is_linkable": true, + "last_modification_date": "########", + "orn": "########", + "path": "/terraform2/", + "policy_default_version_id": "##id-4##", + "policy_id": "##id-2##", + "policy_name": "terraform-policy-2", + "resources_count": 0 + }, + "sensitive_attributes": [], + "private": "bnVsbA==" + } + ] + }, + { + "mode": "managed", + "type": "outscale_user_group", + "name": "group-1", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "creation_date": "########", + "id": "##id-6##", + "last_modification_date": "########", + "orn": "########", + "path": "/terraform/", + "policy": [ + { + "creation_date": "########", + "default_version_id": "##id-4##", + "last_modification_date": "########", + "policy_id": "##id-2##", + "policy_name": "terraform-policy-2", + "policy_orn": "orn:ows:idauth::339215505907:policy/terraform2/terraform-policy-2" + }, + { + "creation_date": "########", + "default_version_id": "##id-4##", + "last_modification_date": "########", + "policy_id": "##id-1##", + "policy_name": "terraform-policy-1", + "policy_orn": "orn:ows:idauth::339215505907:policy/terraform-policy-1" + } + ], + "user": [], + "user_group_id": "##id-6##", + "user_group_name": "Group-TF-policy-1" + }, + "sensitive_attributes": [], + "private": "bnVsbA==", + "dependencies": [ + "outscale_policy.policy-1", + "outscale_policy.policy-2" + ] + } + ] + } + ], + "check_results": "########" +} \ No newline at end of file diff --git a/tests/qa_provider_oapi/data/tests_iam_resources/TF013_policies_linked_to_user_group_datasource_attributes_ok/step1.policies_linked_to_user_group_datasource_attributes_ok.tf b/tests/qa_provider_oapi/data/tests_iam_resources/TF013_policies_linked_to_user_group_datasource_attributes_ok/step1.policies_linked_to_user_group_datasource_attributes_ok.tf new file mode 100644 index 000000000..12bfde597 --- /dev/null +++ b/tests/qa_provider_oapi/data/tests_iam_resources/TF013_policies_linked_to_user_group_datasource_attributes_ok/step1.policies_linked_to_user_group_datasource_attributes_ok.tf @@ -0,0 +1,30 @@ +resource "outscale_user_group" "group-1" { + user_group_name = "Group-TF-policy-1" + path = "/terraform/" + policy { + policy_orn = outscale_policy.policy-1.orn + } + + policy { + policy_orn = outscale_policy.policy-2.orn + } +} + +resource "outscale_policy" "policy-1" { + policy_name = "terraform-policy-1" + description = "test-terraform" + document = file("data/policies_files/policy11.json") + path = "/" +} + +resource "outscale_policy" "policy-2" { + policy_name = "terraform-policy-2" + description = "test-terraform" + document = file("data/policies_files/policy12.json") + path = "/terraform2/" +} + +data "outscale_policies_linked_to_user_group" "managed_policies_linked_to_user_group" { + user_group_name= outscale_user_group.group-1.user_group_name +depends_on=[outscale_user_group.group-1] +} diff --git a/tests/qa_provider_oapi/data/tests_iam_resources/TF014_entities_linked_to_policy_datasource_attributes_ok/step1.entities_linked_to_policy_datasource_attributes_ok.ref b/tests/qa_provider_oapi/data/tests_iam_resources/TF014_entities_linked_to_policy_datasource_attributes_ok/step1.entities_linked_to_policy_datasource_attributes_ok.ref new file mode 100644 index 000000000..478756f55 --- /dev/null +++ b/tests/qa_provider_oapi/data/tests_iam_resources/TF014_entities_linked_to_policy_datasource_attributes_ok/step1.entities_linked_to_policy_datasource_attributes_ok.ref @@ -0,0 +1,250 @@ +{ + "version": "########", + "terraform_version": "########", + "serial": "########", + "lineage": "########", + "outputs": {}, + "resources": [ + { + "mode": "managed", + "type": "outscale_policy", + "name": "policy-1", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "creation_date": "########", + "description": "test-terraform", + "document": "{\n \"Statement\": [\n {\n \"Action\": [\n \"api:*\"\n ],\n \"Effect\": \"Allow\",\n \"Resource\": [\n \"*\"\n ]\n }\n ]\n}\n", + "id": "##id-0##", + "is_linkable": true, + "last_modification_date": "########", + "orn": "########", + "path": "/", + "policy_default_version_id": "##id-1##", + "policy_id": "##id-2##", + "policy_name": "terraform-policy-1", + "resources_count": 0 + }, + "sensitive_attributes": [], + "private": "bnVsbA==" + } + ] + }, + { + "mode": "managed", + "type": "outscale_policy", + "name": "policy-2", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "creation_date": "########", + "description": "test-terraform", + "document": "{\n \"Statement\": [\n {\n \"Action\": [\n \"api:*\"\n ],\n \"Effect\": \"Allow\",\n \"Resource\": [\n \"*\"\n ]\n }\n ]\n}\n", + "id": "##id-3##", + "is_linkable": true, + "last_modification_date": "########", + "orn": "########", + "path": "/terraform2/", + "policy_default_version_id": "##id-1##", + "policy_id": "##id-4##", + "policy_name": "terraform-policy-2", + "resources_count": 0 + }, + "sensitive_attributes": [], + "private": "bnVsbA==" + } + ] + }, + { + "mode": "managed", + "type": "outscale_user", + "name": "user-1", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "creation_date": "########", + "id": "##id-5##", + "last_modification_date": "########", + "path": "/terraform/", + "policy": [ + { + "creation_date": "########", + "default_version_id": "##id-1##", + "last_modification_date": "########", + "policy_id": "##id-2##", + "policy_name": "terraform-policy-1", + "policy_orn": "orn:ows:idauth::339215505907:policy/terraform-policy-1" + } + ], + "user_email": "test-TF11@test2.fr", + "user_id": "##id-5##", + "user_name": "User-TF-11" + }, + "sensitive_attributes": [], + "private": "bnVsbA==", + "dependencies": [ + "outscale_policy.policy-1" + ] + } + ] + }, + { + "mode": "managed", + "type": "outscale_user", + "name": "user-2", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "creation_date": "########", + "id": "##id-6##", + "last_modification_date": "########", + "path": "/terraform2/", + "policy": [ + { + "creation_date": "########", + "default_version_id": "##id-1##", + "last_modification_date": "########", + "policy_id": "##id-2##", + "policy_name": "terraform-policy-1", + "policy_orn": "orn:ows:idauth::339215505907:policy/terraform-policy-1" + } + ], + "user_email": "test-TF12@test2.fr", + "user_id": "##id-6##", + "user_name": "User-TF-12" + }, + "sensitive_attributes": [], + "private": "bnVsbA==", + "dependencies": [ + "outscale_policy.policy-1" + ] + } + ] + }, + { + "mode": "managed", + "type": "outscale_user_group", + "name": "group-1", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "creation_date": "########", + "id": "##id-7##", + "last_modification_date": "########", + "orn": "########", + "path": "/terraform/", + "policy": [ + { + "creation_date": "########", + "default_version_id": "##id-1##", + "last_modification_date": "########", + "policy_id": "##id-4##", + "policy_name": "terraform-policy-2", + "policy_orn": "orn:ows:idauth::339215505907:policy/terraform2/terraform-policy-2" + }, + { + "creation_date": "########", + "default_version_id": "##id-1##", + "last_modification_date": "########", + "policy_id": "##id-2##", + "policy_name": "terraform-policy-1", + "policy_orn": "orn:ows:idauth::339215505907:policy/terraform-policy-1" + } + ], + "user": [ + { + "creation_date": "########", + "last_modification_date": "########", + "path": "/terraform/", + "user_id": "##id-5##", + "user_name": "User-TF-11" + }, + { + "creation_date": "########", + "last_modification_date": "########", + "path": "/terraform2/", + "user_id": "##id-6##", + "user_name": "User-TF-12" + } + ], + "user_group_id": "##id-7##", + "user_group_name": "Group-TF-test-1" + }, + "sensitive_attributes": [], + "private": "bnVsbA==", + "dependencies": [ + "outscale_policy.policy-1", + "outscale_policy.policy-2", + "outscale_user.user-1", + "outscale_user.user-2" + ] + } + ] + }, + { + "mode": "managed", + "type": "outscale_user_group", + "name": "group-2", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "creation_date": "########", + "id": "##id-8##", + "last_modification_date": "########", + "orn": "########", + "path": "/terraform3/", + "policy": [ + { + "creation_date": "########", + "default_version_id": "##id-1##", + "last_modification_date": "########", + "policy_id": "##id-4##", + "policy_name": "terraform-policy-2", + "policy_orn": "orn:ows:idauth::339215505907:policy/terraform2/terraform-policy-2" + } + ], + "user": [ + { + "creation_date": "########", + "last_modification_date": "########", + "path": "/terraform/", + "user_id": "##id-5##", + "user_name": "User-TF-11" + }, + { + "creation_date": "########", + "last_modification_date": "########", + "path": "/terraform2/", + "user_id": "##id-6##", + "user_name": "User-TF-12" + } + ], + "user_group_id": "##id-8##", + "user_group_name": "Group-TF-test-2" + }, + "sensitive_attributes": [], + "private": "bnVsbA==", + "dependencies": [ + "outscale_policy.policy-1", + "outscale_policy.policy-2", + "outscale_user.user-1", + "outscale_user.user-2" + ] + } + ] + } + ], + "check_results": "########" +} \ No newline at end of file diff --git a/tests/qa_provider_oapi/data/tests_iam_resources/TF014_entities_linked_to_policy_datasource_attributes_ok/step1.entities_linked_to_policy_datasource_attributes_ok.tf b/tests/qa_provider_oapi/data/tests_iam_resources/TF014_entities_linked_to_policy_datasource_attributes_ok/step1.entities_linked_to_policy_datasource_attributes_ok.tf new file mode 100644 index 000000000..c0c60448c --- /dev/null +++ b/tests/qa_provider_oapi/data/tests_iam_resources/TF014_entities_linked_to_policy_datasource_attributes_ok/step1.entities_linked_to_policy_datasource_attributes_ok.tf @@ -0,0 +1,71 @@ +resource "outscale_user" "user-1" { + user_name = "User-TF-11" + user_email = "test-TF11@test2.fr" + path = "/terraform/" + policy { + policy_orn = outscale_policy.policy-1.orn + } +} + +resource "outscale_user" "user-2" { + user_name = "User-TF-12" + user_email = "test-TF12@test2.fr" + path = "/terraform2/" + policy { + policy_orn = outscale_policy.policy-1.orn + } +} + +resource "outscale_user_group" "group-1" { + user_group_name = "Group-TF-test-1" + path = "/terraform/" + user { + user_name = outscale_user.user-1.user_name + path = "/terraform/" + } + user { + user_name = outscale_user.user-2.user_name + path = "/terraform2/" + } + policy { + policy_orn = outscale_policy.policy-1.orn + } + + policy { + policy_orn = outscale_policy.policy-2.orn + } +depends_on=[outscale_user.user-1,outscale_user.user-2] +} + +resource "outscale_user_group" "group-2" { + user_group_name = "Group-TF-test-2" + path = "/terraform3/" + user { + user_name = outscale_user.user-1.user_name + path = "/terraform/" + } + user { + user_name = outscale_user.user-2.user_name + path = "/terraform2/" + } +policy { + policy_orn = outscale_policy.policy-2.orn + } +depends_on=[outscale_user.user-1,outscale_user.user-2] +} + +resource "outscale_policy" "policy-1" { + policy_name = "terraform-policy-1" + description = "test-terraform" + document = file("data/policies_files/policy.json") + path = "/" +} + +resource "outscale_policy" "policy-2" { + policy_name = "terraform-policy-2" + description = "test-terraform" + document = file("data/policies_files/policy.json") + path = "/terraform2/" +} + + diff --git a/tests/qa_provider_oapi/data/tests_iam_resources/TF015_user_groups_per_user_datasource_attributes_ok/step1.user_groups_per_user_datasource_attributes_ok.ref b/tests/qa_provider_oapi/data/tests_iam_resources/TF015_user_groups_per_user_datasource_attributes_ok/step1.user_groups_per_user_datasource_attributes_ok.ref new file mode 100644 index 000000000..c8c017115 --- /dev/null +++ b/tests/qa_provider_oapi/data/tests_iam_resources/TF015_user_groups_per_user_datasource_attributes_ok/step1.user_groups_per_user_datasource_attributes_ok.ref @@ -0,0 +1,121 @@ +{ + "version": "########", + "terraform_version": "########", + "serial": "########", + "lineage": "########", + "outputs": {}, + "resources": [ + { + "mode": "data", + "type": "outscale_user_groups_per_user", + "name": "usegroups_per_user01", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "id": "##id-0##", + "user_groups": [], + "user_name": "User-TF-group1", + "user_path": "/terraform/" + }, + "sensitive_attributes": [] + } + ] + }, + { + "mode": "managed", + "type": "outscale_user", + "name": "user-1", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "creation_date": "########", + "id": "##id-1##", + "last_modification_date": "########", + "path": "/terraform/", + "policy": [], + "user_email": "customer-tooling@outscale.com", + "user_id": "##id-1##", + "user_name": "User-TF-group1" + }, + "sensitive_attributes": [], + "private": "bnVsbA==" + } + ] + }, + { + "mode": "managed", + "type": "outscale_user_group", + "name": "group-1", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "creation_date": "########", + "id": "##id-2##", + "last_modification_date": "########", + "orn": "########", + "path": "/terraform/", + "policy": [], + "user": [ + { + "creation_date": "########", + "last_modification_date": "########", + "path": "/terraform/", + "user_id": "##id-1##", + "user_name": "User-TF-group1" + } + ], + "user_group_id": "##id-2##", + "user_group_name": "Group-TF-test-1" + }, + "sensitive_attributes": [], + "private": "bnVsbA==", + "dependencies": [ + "outscale_user.user-1" + ] + } + ] + }, + { + "mode": "managed", + "type": "outscale_user_group", + "name": "group-2", + "provider": "provider[\"registry.terraform.io/outscale/outscale\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "creation_date": "########", + "id": "##id-3##", + "last_modification_date": "########", + "orn": "########", + "path": "/terraform3/", + "policy": [], + "user": [ + { + "creation_date": "########", + "last_modification_date": "########", + "path": "/terraform/", + "user_id": "##id-1##", + "user_name": "User-TF-group1" + } + ], + "user_group_id": "##id-3##", + "user_group_name": "Group-TF-test-2" + }, + "sensitive_attributes": [], + "private": "bnVsbA==", + "dependencies": [ + "outscale_user.user-1" + ] + } + ] + } + ], + "check_results": "########" +} \ No newline at end of file diff --git a/tests/qa_provider_oapi/data/tests_iam_resources/TF015_user_groups_per_user_datasource_attributes_ok/step1.user_groups_per_user_datasource_attributes_ok.tf b/tests/qa_provider_oapi/data/tests_iam_resources/TF015_user_groups_per_user_datasource_attributes_ok/step1.user_groups_per_user_datasource_attributes_ok.tf new file mode 100644 index 000000000..d506ebafe --- /dev/null +++ b/tests/qa_provider_oapi/data/tests_iam_resources/TF015_user_groups_per_user_datasource_attributes_ok/step1.user_groups_per_user_datasource_attributes_ok.tf @@ -0,0 +1,33 @@ +resource "outscale_user" "user-1" { + user_name = "User-TF-group1" + path = "/terraform/" +} + + + +resource "outscale_user_group" "group-1" { + user_group_name = "Group-TF-test-1" + path = "/terraform/" + user { + user_name = outscale_user.user-1.user_name + path = "/terraform/" + } +depends_on=[outscale_user.user-1] +} + + + +resource "outscale_user_group" "group-2" { + user_group_name = "Group-TF-test-2" + path = "/terraform3/" + user { + user_name = outscale_user.user-1.user_name + path = "/terraform/" + } +depends_on=[outscale_user.user-1] +} + +data "outscale_user_groups_per_user" "usegroups_per_user01" { + user_name = outscale_user.user-1.user_name + user_path = outscale_user.user-1.path +} diff --git a/tests/qa_provider_oapi/test_provider_oapi.py b/tests/qa_provider_oapi/test_provider_oapi.py index c9d89298d..651906fad 100644 --- a/tests/qa_provider_oapi/test_provider_oapi.py +++ b/tests/qa_provider_oapi/test_provider_oapi.py @@ -52,7 +52,8 @@ 'available_ips_count', 'load_balancer_name', 'load_balancer_names', - 'listener_rule_name'] + 'listener_rule_name', + 'backend_ips'] IGNORE_END_PATHS = [] TINA_ID_PREFIXES = ['i', 'subnet', 'snap', 'img', 'vol', 'eni', 'vpc', 'igw', 'nat', 'vgw', 'pcx', 'sg', 'rtb', 'rtbassoc', 'vpn', 'vpcconn', 'ami', 'dxvif','vpce','fgpu','aar','ca'] VARIABLES_FILE_NAME = ['resources.auto.tfvars']