diff --git a/docs/data-sources/organization.md b/docs/data-sources/organization.md index 801da32..526a860 100644 --- a/docs/data-sources/organization.md +++ b/docs/data-sources/organization.md @@ -16,13 +16,23 @@ Organization data source provider "mondoo" {} data "mondoo_organization" "org" { - id = "reverent-ride-275852" + id = "your-org-1234567" } output "org_mrn" { description = "MRN of the organization" value = data.mondoo_organization.org.mrn } + +output "org_name" { + description = "Name of the organization" + value = data.mondoo_organization.org.name +} + +output "org_id" { + description = "ID of the organization" + value = data.mondoo_organization.org.id +} ``` diff --git a/docs/data-sources/space.md b/docs/data-sources/space.md index 64fbced..21fff70 100644 --- a/docs/data-sources/space.md +++ b/docs/data-sources/space.md @@ -21,7 +21,7 @@ variable "mondoo_org" { provider "mondoo" {} resource "mondoo_space" "test" { - org_id = var.mondoo_org.value + org_id = var.mondoo_org name = "test-space" } @@ -42,6 +42,11 @@ output "space_mrn" { description = "The MRN of the space" value = data.mondoo_space.space.mrn } + +output "space_id" { + description = "The ID of the space" + value = data.mondoo_space.space.id +} ``` diff --git a/examples/data-sources/mondoo_organization/data-source.tf b/examples/data-sources/mondoo_organization/data-source.tf index 85b7329..d9f9347 100644 --- a/examples/data-sources/mondoo_organization/data-source.tf +++ b/examples/data-sources/mondoo_organization/data-source.tf @@ -1,10 +1,20 @@ provider "mondoo" {} data "mondoo_organization" "org" { - id = "reverent-ride-275852" + id = "your-org-1234567" } output "org_mrn" { description = "MRN of the organization" value = data.mondoo_organization.org.mrn -} \ No newline at end of file +} + +output "org_name" { + description = "Name of the organization" + value = data.mondoo_organization.org.name +} + +output "org_id" { + description = "ID of the organization" + value = data.mondoo_organization.org.id +} diff --git a/examples/data-sources/mondoo_space/data-source.tf b/examples/data-sources/mondoo_space/data-source.tf index 82c6244..cfb6976 100644 --- a/examples/data-sources/mondoo_space/data-source.tf +++ b/examples/data-sources/mondoo_space/data-source.tf @@ -6,7 +6,7 @@ variable "mondoo_org" { provider "mondoo" {} resource "mondoo_space" "test" { - org_id = var.mondoo_org.value + org_id = var.mondoo_org name = "test-space" } @@ -27,3 +27,8 @@ output "space_mrn" { description = "The MRN of the space" value = data.mondoo_space.space.mrn } + +output "space_id" { + description = "The ID of the space" + value = data.mondoo_space.space.id +} diff --git a/internal/provider/gql.go b/internal/provider/gql.go index 4e092d0..a3235f4 100644 --- a/internal/provider/gql.go +++ b/internal/provider/gql.go @@ -89,9 +89,7 @@ type spacePayload struct { Id string Mrn string Name string - Organization struct { - Id string - } + Organization orgPayload } func (c *ExtendedGqlClient) GetSpace(ctx context.Context, mrn string) (spacePayload, error) { diff --git a/internal/provider/organization_data_source.go b/internal/provider/organization_data_source.go index deddc08..83e5884 100644 --- a/internal/provider/organization_data_source.go +++ b/internal/provider/organization_data_source.go @@ -6,6 +6,7 @@ package provider import ( "context" "fmt" + "github.com/hashicorp/terraform-plugin-framework/datasource" "github.com/hashicorp/terraform-plugin-framework/datasource/schema" "github.com/hashicorp/terraform-plugin-framework/types" @@ -90,12 +91,11 @@ func (d *OrganizationDataSource) Read(ctx context.Context, req datasource.ReadRe // we fetch the organization id from the service account orgMrn := "" - if data.OrgMrn.ValueString() != "" { + if data.OrgMrn.ValueString() != "" && data.OrgID.ValueString() == "" { orgMrn = data.OrgMrn.ValueString() - } else if data.OrgID.ValueString() != "" { + } else if data.OrgID.ValueString() != "" && data.OrgMrn.ValueString() == "" { orgMrn = orgPrefix + data.OrgID.ValueString() - } - if orgMrn == "" { + } else { resp.Diagnostics.AddError("Invalid Configuration", "Either `id` or `mrn` must be set") return } @@ -106,8 +106,6 @@ func (d *OrganizationDataSource) Read(ctx context.Context, req datasource.ReadRe return } - // For the purposes of this example code, hardcoding a response value to - // save into the Terraform state. data.OrgID = types.StringValue(payload.Id) data.OrgMrn = types.StringValue(payload.Mrn) data.Name = types.StringValue(payload.Name) diff --git a/internal/provider/space_data_source.go b/internal/provider/space_data_source.go index 822a21a..a3114c9 100644 --- a/internal/provider/space_data_source.go +++ b/internal/provider/space_data_source.go @@ -6,6 +6,7 @@ package provider import ( "context" "fmt" + "github.com/hashicorp/terraform-plugin-framework/datasource" "github.com/hashicorp/terraform-plugin-framework/datasource/schema" "github.com/hashicorp/terraform-plugin-framework/types" @@ -90,12 +91,11 @@ func (d *SpaceDataSource) Read(ctx context.Context, req datasource.ReadRequest, // we fetch the organization id from the service account spaceMrn := "" - if data.SpaceMrn.ValueString() != "" { + if data.SpaceMrn.ValueString() != "" && data.SpaceID.ValueString() == "" { spaceMrn = data.SpaceMrn.ValueString() - } else if data.SpaceMrn.ValueString() != "" { - spaceMrn = orgPrefix + data.SpaceID.ValueString() - } - if spaceMrn == "" { + } else if data.SpaceID.ValueString() != "" && data.SpaceMrn.ValueString() == "" { + spaceMrn = spacePrefix + data.SpaceID.ValueString() + } else { resp.Diagnostics.AddError("Invalid Configuration", "Either `id` or `mrn` must be set") return } @@ -106,8 +106,6 @@ func (d *SpaceDataSource) Read(ctx context.Context, req datasource.ReadRequest, return } - // For the purposes of this example code, hardcoding a response value to - // save into the Terraform state. data.SpaceID = types.StringValue(payload.Id) data.SpaceMrn = types.StringValue(payload.Mrn) data.Name = types.StringValue(payload.Name)