-
Notifications
You must be signed in to change notification settings - Fork 33
feat(resourcemanager): add folder resource/datasource #975
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat(resourcemanager): add folder resource/datasource #975
Conversation
d3752dd
to
8c8b3a8
Compare
E2E Run
![]() |
218b2d7
to
6f7a5bf
Compare
6f7a5bf
to
4ce777f
Compare
4ce777f
to
6d3c81f
Compare
stackit/internal/services/resourcemanager/project/datasource.go
Outdated
Show resolved
Hide resolved
stackit/internal/services/resourcemanager/project/datasource.go
Outdated
Show resolved
Hide resolved
6d3c81f
to
00b74ca
Compare
00b74ca
to
0def103
Compare
Signed-off-by: Mauritz Uphoff <[email protected]>
Signed-off-by: Mauritz Uphoff <[email protected]>
…sourcemanager project/folder Signed-off-by: Mauritz Uphoff <[email protected]>
Signed-off-by: Mauritz Uphoff <[email protected]>
Signed-off-by: Mauritz Uphoff <[email protected]>
Signed-off-by: Mauritz Uphoff <[email protected]>
3393dc8
to
fe258cf
Compare
name = "example-project" | ||
owner_email = "[email protected]" | ||
parent_container_id = stackit_resourcemanager_folder.example.container_id | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add an example, how to import a folder like we have it for other resources:
terraform-provider-stackit/examples/resources/stackit_resourcemanager_project/resource.tf
Lines 11 to 17 in fe258cf
# Only use the import statement, if you want to import an existing resourcemanager project | |
# Note: There will be a conflict which needs to be resolved manually. | |
# Must set a configuration value for the owner_email attribute as the provider has marked it as required. | |
import { | |
to = stackit_resourcemanager_project.import-example | |
id = var.container_id | |
} |
var ( | ||
_ datasource.DataSource = &folderDataSource{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick. to ensure the Configure method is always implemented and not changed accidentally
var ( | |
_ datasource.DataSource = &folderDataSource{} | |
var ( | |
_ datasource.DataSource = &folderDataSource{} | |
_ datasource.DataSourceWithConfigure = &folderDataSource{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be adjusted for the project datasource as well
https://github.com/h3adex/terraform-provider-stackit/blob/fe258cf586e734d019fd83c8337dd2481361fe02/stackit/internal/services/resourcemanager/project/datasource.go#L27-L29
ctx, | ||
&resp.Diagnostics, | ||
"Error deleting folder. Deletion may fail because associated projects remain hidden for up to 7 days after user deletion due to technical requirements.", | ||
fmt.Sprintf("API call failed: %v", err), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fmt.Sprintf("API call failed: %v", err), | |
fmt.Sprintf("Calling API: %v", err), |
// mapFolderCreateFields maps the Create Folder API response to the Terraform model and update the Terraform state | ||
func mapFolderCreateFields(ctx context.Context, resp *resourcemanager.FolderResponse, model *Model, state *tfsdk.State) error { | ||
return mapFolderFields(ctx, resp.ContainerId, resp.Name, resp.FolderId, resp.Labels, resp.Parent, resp.CreationTime, resp.UpdateTime, model, state) | ||
} | ||
|
||
// mapFolderDetailsFields maps the GetDetails API response to the Terraform model and update the Terraform state | ||
func mapFolderDetailsFields(ctx context.Context, resp *resourcemanager.GetFolderDetailsResponse, model *Model, state *tfsdk.State) error { | ||
return mapFolderFields(ctx, resp.ContainerId, resp.Name, resp.FolderId, resp.Labels, resp.Parent, resp.CreationTime, resp.UpdateTime, model, state) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be probably better readable when using just one map function. For this you just need to add an additional GET call in the Create method and use the response of it for the map function instead of passing each attribute separate
`, testutil.ResourceManagerProviderConfig(), resourceProject), | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
resource.TestCheckResourceAttr("data.stackit_resourcemanager_project.example", "name", testutil.ConvertConfigVariable(testConfigResourceProjectParentContainerId["name"])), | ||
resource.TestCheckResourceAttrSet("data.stackit_resourcemanager_project.example", "parent_container_id"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can check here, if the parent_container_id has the correct value
resource.TestCheckResourceAttrSet("data.stackit_resourcemanager_project.example", "parent_container_id"), | |
resource.TestCheckResourceAttr("data.stackit_resourcemanager_project.example", "parent_container_id", testutil.ConvertConfigVariable(testConfigResourceProjectParentContainerId["parent_container_id"])), |
resource.TestCheckResourceAttrSet("data.stackit_resourcemanager_project.example", "container_id"), | ||
resource.TestCheckResourceAttrSet("data.stackit_resourcemanager_project.example", "project_id"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And here, if it has the same values like the resource
resource.TestCheckResourceAttrSet("data.stackit_resourcemanager_project.example", "container_id"), | |
resource.TestCheckResourceAttrSet("data.stackit_resourcemanager_project.example", "project_id"), | |
resource.TestCheckResourceAttrPair( | |
"data.stackit_resourcemanager_project.example", "container_id", | |
"stackit_resourcemanager_project.example", "container_id", | |
), | |
resource.TestCheckResourceAttrPair( | |
"data.stackit_resourcemanager_project.example", "project_id", | |
"stackit_resourcemanager_project.example", "project_id", | |
), |
resource.TestCheckResourceAttrSet("data.stackit_resourcemanager_project.example", "parent_container_id"), | ||
resource.TestCheckResourceAttrSet("data.stackit_resourcemanager_project.example", "container_id"), | ||
resource.TestCheckResourceAttrSet("data.stackit_resourcemanager_project.example", "project_id"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
resource.TestCheckResourceAttrSet("data.stackit_resourcemanager_folder.example", "parent_container_id"), | ||
resource.TestCheckResourceAttrSet("data.stackit_resourcemanager_folder.example", "folder_id"), | ||
resource.TestCheckResourceAttrSet("data.stackit_resourcemanager_folder.example", "container_id"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
resource.TestCheckResourceAttrSet("data.stackit_resourcemanager_folder.example", "parent_container_id"), | ||
resource.TestCheckResourceAttrSet("data.stackit_resourcemanager_folder.example", "folder_id"), | ||
resource.TestCheckResourceAttrSet("data.stackit_resourcemanager_folder.example", "container_id"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and here
Description
Implements full support for resource and data source for folders (STACKITTPR-213). Both are marked as beta.
Acceptance tests/Docs updated for:
stackit_resourcemanager_project improvements:
Example configuration:
E2E test results in the comments.
Checklist
make fmt
examples/
directory)make generate-docs
(will be checked by CI)make test
(will be checked by CI)make lint
(will be checked by CI)