Skip to content

Commit

Permalink
Merge pull request #2 from cycloidio/fg-organizations
Browse files Browse the repository at this point in the history
  • Loading branch information
xescugc authored Feb 15, 2024
2 parents bb97dca + d1d73c2 commit 44f5f21
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.tf
*.tfstate*
2 changes: 1 addition & 1 deletion DEVELOPING_TIPS.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ From the [docs](https://github.com/hashicorp/terraform-plugin-codegen-openapi/bl
> Arrays and Objects will have their child attributes merged, so example_object.string_field and example_object.bool_field will be merged into the same SingleNestedAttribute schema.

**Organizaitons**
**Organizations**

On Organization the `admins` are `MemberOrg` which itself has a `invited_by` which is also `MemberOrg` so it's a buckle and it needs to be broken

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ How it works:
terraform {
required_providers {
cycloid = {
source = "registry.terraform.io/cycloid/cycloid"
source = "cycloidio/cycloid"
}
}
}
Expand Down
22 changes: 22 additions & 0 deletions provider/organization_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,18 @@ func (r *organizationResource) Read(ctx context.Context, req resource.ReadReques
}

// Read API call logic
api := common.NewAPI(common.WithURL(r.provider.Url.ValueString()), common.WithToken(r.provider.Jwt.ValueString()))
mid := middleware.NewMiddleware(api)
org, err := mid.GetOrganization(data.Canonical.ValueString())
if err != nil {
resp.Diagnostics.AddError(
"Unable get organization",
err.Error(),
)
return
}

data.Name = types.StringPointerValue(org.Name)

// Save updated data into Terraform state
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
Expand Down Expand Up @@ -116,4 +128,14 @@ func (r *organizationResource) Delete(ctx context.Context, req resource.DeleteRe
}

// Delete API call logic
api := common.NewAPI(common.WithURL(r.provider.Url.ValueString()), common.WithToken(r.provider.Jwt.ValueString()))
mid := middleware.NewMiddleware(api)
err := mid.DeleteOrganization(data.Canonical.ValueString())
if err != nil {
resp.Diagnostics.AddError(
"Unable delete organization",
err.Error(),
)
return
}
}

0 comments on commit 44f5f21

Please sign in to comment.