Skip to content

Commit

Permalink
Merge pull request #21 from stgraber/main
Browse files Browse the repository at this point in the history
Cherry-pick project import fix and doc
  • Loading branch information
adamcstephens authored Jan 17, 2024
2 parents 8b1c78f + dbd31f1 commit 34ce999
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
28 changes: 28 additions & 0 deletions docs/resources/project.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,34 @@ resource "incus_instance" "instance" {

No attributes are exported.

## Importing

Import ID syntax: `[<remote>:]<name>`

* `<remote>` - *Optional* - Remote name.
* `<name>` - **Required** - Project name.

### Import example

Example using terraform import command:

```shell
$ terraform import incus_project.myproj proj1
```

Example using the import block (only available in Terraform v1.5.0 and later):

```hcl
resource "incus_project" "myproj" {
name = "proj1"
}
import {
to = incus_project.myproj
id = "proj1"
}
```

## Notes

* The project resource `config` includes some keys that can be automatically generated by the Incus.
Expand Down
10 changes: 10 additions & 0 deletions internal/project/resource_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,16 @@ func (r *ProjectResource) ImportState(ctx context.Context, req resource.ImportSt
}

for k, v := range fields {
// Attribute "project" is parsed by default, but we use
// attribute "name" instead.
if k == "project" {
resp.Diagnostics.AddError(
fmt.Sprintf("Invalid import ID %q", req.ID),
"Valid import format:\nimport incus_project.<resource> [remote:]<name>",
)
break
}

resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root(k), v)...)
}
}
Expand Down

0 comments on commit 34ce999

Please sign in to comment.