From 4ca6f2cec20f9b36e0a86b2460e76ab04c2bca82 Mon Sep 17 00:00:00 2001 From: jaime Bernabe <6184069+Monitob@users.noreply.github.com> Date: Tue, 29 Nov 2022 09:54:38 +0100 Subject: [PATCH] fix(account_project): add missing option organization_id (#1633) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Rémy Léone Co-authored-by: Jules Castéran --- docs/data-sources/account_project.md | 2 +- docs/resources/account_project.md | 4 ++-- scaleway/resource_account_project.go | 19 ++++++++++++++++--- scaleway/resource_account_project_test.go | 4 ++-- 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/docs/data-sources/account_project.md b/docs/data-sources/account_project.md index 453d36fe3..59312b66c 100644 --- a/docs/data-sources/account_project.md +++ b/docs/data-sources/account_project.md @@ -15,7 +15,7 @@ Gets information about an existing Project. # Get info by name data scaleway_account_project "by_name" { name = "myproject" - organization_id = "%s" + organization_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" } # Get default project data scaleway_account_project "by_name" { diff --git a/docs/resources/account_project.md b/docs/resources/account_project.md index 68932fe04..08f1f56b5 100644 --- a/docs/resources/account_project.md +++ b/docs/resources/account_project.md @@ -12,7 +12,7 @@ Manages organization's projects on Scaleway. ```hcl resource "scaleway_account_project" "project" { - name = "myproject" + name = "project" } ``` @@ -22,7 +22,7 @@ The following arguments are supported: - `name` - (Optional) The name of the Project. - `description` - (Optional) The description of the Project. -- `organization_id` - The organization ID the Project is associated with. +- `organization_id` - (Optional. Defaults to [provider](../index.md#organization_id) `organization_id`)The organization ID the Project is associated with. Please note that any change in `organization_id` will recreate the resource. ## Attributes Reference diff --git a/scaleway/resource_account_project.go b/scaleway/resource_account_project.go index 7060afaab..8709acd3e 100644 --- a/scaleway/resource_account_project.go +++ b/scaleway/resource_account_project.go @@ -41,7 +41,14 @@ func resourceScalewayAccountProject() *schema.Resource { Computed: true, Description: "The date and time of the last update of the Project (Format ISO 8601)", }, - "organization_id": organizationIDSchema(), + "organization_id": { + Type: schema.TypeString, + Description: "The organization_id you want to attach the resource to", + Optional: true, + ForceNew: true, + Computed: true, + ValidateFunc: validationUUID(), + }, }, } } @@ -49,10 +56,16 @@ func resourceScalewayAccountProject() *schema.Resource { func resourceScalewayAccountProjectCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { accountAPI := accountV2API(meta) - res, err := accountAPI.CreateProject(&accountV2.CreateProjectRequest{ + request := &accountV2.CreateProjectRequest{ Name: expandOrGenerateString(d.Get("name"), "project-"), Description: expandStringPtr(d.Get("description").(string)), - }, scw.WithContext(ctx)) + } + + if organisationIDRaw, exist := d.GetOk("organization_id"); exist { + request.OrganizationID = organisationIDRaw.(string) + } + + res, err := accountAPI.CreateProject(request, scw.WithContext(ctx)) if err != nil { return diag.FromErr(err) } diff --git a/scaleway/resource_account_project_test.go b/scaleway/resource_account_project_test.go index bfea9fc62..1c09a9936 100644 --- a/scaleway/resource_account_project_test.go +++ b/scaleway/resource_account_project_test.go @@ -16,11 +16,11 @@ func init() { } resource.AddTestSweepers("scaleway_account_project", &resource.Sweeper{ Name: "scaleway_account_project", - F: testSweepAccountproject, + F: testSweepAccountProject, }) } -func testSweepAccountproject(_ string) error { +func testSweepAccountProject(_ string) error { return sweep(func(scwClient *scw.Client) error { accountAPI := accountV2.NewAPI(scwClient)