Skip to content

Commit

Permalink
fix(account_project): add missing option organization_id (#1633)
Browse files Browse the repository at this point in the history
Co-authored-by: Rémy Léone <rleone@scaleway.com>
Co-authored-by: Jules Castéran <jcasteran@scaleway.com>
  • Loading branch information
3 people committed Nov 29, 2022
1 parent 265aa23 commit 4ca6f2c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
2 changes: 1 addition & 1 deletion docs/data-sources/account_project.md
Expand Up @@ -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" {
Expand Down
4 changes: 2 additions & 2 deletions docs/resources/account_project.md
Expand Up @@ -12,7 +12,7 @@ Manages organization's projects on Scaleway.

```hcl
resource "scaleway_account_project" "project" {
name = "myproject"
name = "project"
}
```

Expand All @@ -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

Expand Down
19 changes: 16 additions & 3 deletions scaleway/resource_account_project.go
Expand Up @@ -41,18 +41,31 @@ 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(),
},
},
}
}

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)
}
Expand Down
4 changes: 2 additions & 2 deletions scaleway/resource_account_project_test.go
Expand Up @@ -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)

Expand Down

0 comments on commit 4ca6f2c

Please sign in to comment.