Skip to content

Commit 0eaefef

Browse files
feat: add stacklet_platform data source (#72)
### what add a datasource to retrieve general details about the platform ### why provide general info about the deployment ### testing acceptance tests and tested in sandbox ### docs added here
1 parent 523fc2e commit 0eaefef

File tree

11 files changed

+454
-2
lines changed

11 files changed

+454
-2
lines changed

docs/data-sources/platform.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "stacklet_platform Data Source - terraform-provider-stacklet"
4+
subcategory: ""
5+
description: |-
6+
Retrieve information about the Stacklet platform.
7+
---
8+
9+
# stacklet_platform (Data Source)
10+
11+
Retrieve information about the Stacklet platform.
12+
13+
## Example Usage
14+
15+
```terraform
16+
# Fetch details about the platform
17+
data "stacklet_platform" "example" {}
18+
```
19+
20+
<!-- schema generated by tfplugindocs -->
21+
## Schema
22+
23+
### Read-Only
24+
25+
- `aws_account_customer_config` (Attributes) Customer configuration for AWS accounts. (see [below for nested schema](#nestedatt--aws_account_customer_config))
26+
- `aws_org_read_customer_config` (Attributes) Customer configuration for AWS organization read access. (see [below for nested schema](#nestedatt--aws_org_read_customer_config))
27+
- `execution_regions` (List of String) List of regions for which execution is enabled.
28+
- `external_id` (String) The external ID for the deployment.
29+
- `id` (String) The GraphQL Node ID.
30+
31+
<a id="nestedatt--aws_account_customer_config"></a>
32+
### Nested Schema for `aws_account_customer_config`
33+
34+
Read-Only:
35+
36+
- `terraform_module` (Attributes) Terraform module configuration for account setup. (see [below for nested schema](#nestedatt--aws_account_customer_config--terraform_module))
37+
38+
<a id="nestedatt--aws_account_customer_config--terraform_module"></a>
39+
### Nested Schema for `aws_account_customer_config.terraform_module`
40+
41+
Read-Only:
42+
43+
- `repository_url` (String) Module repository URL.
44+
- `source` (String) Module source.
45+
- `variables_json` (String) JSON-encoded variables for module configuration.
46+
47+
48+
49+
<a id="nestedatt--aws_org_read_customer_config"></a>
50+
### Nested Schema for `aws_org_read_customer_config`
51+
52+
Read-Only:
53+
54+
- `terraform_module` (Attributes) Terraform module configuration for organization read access setup. (see [below for nested schema](#nestedatt--aws_org_read_customer_config--terraform_module))
55+
56+
<a id="nestedatt--aws_org_read_customer_config--terraform_module"></a>
57+
### Nested Schema for `aws_org_read_customer_config.terraform_module`
58+
59+
Read-Only:
60+
61+
- `repository_url` (String) Module repository URL.
62+
- `source` (String) Module source.
63+
- `variables_json` (String) JSON-encoded variables for module configuration.

docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ It allows managing resources like accounts, account groups, policy collections,
1818
terraform {
1919
required_providers {
2020
stacklet = {
21-
source = "registry.terraform.io/stacklet/stacklet"
21+
source = "stacklet/stacklet"
2222
}
2323
}
2424
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Fetch details about the platform
2+
data "stacklet_platform" "example" {}

examples/provider/provider.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
terraform {
22
required_providers {
33
stacklet = {
4-
source = "registry.terraform.io/stacklet/stacklet"
4+
source = "stacklet/stacklet"
55
}
66
}
77
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright (c) 2025 - Stacklet, Inc.
2+
3+
package acceptance_tests
4+
5+
import (
6+
"testing"
7+
8+
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
9+
)
10+
11+
func TestAccPlatformDataSource(t *testing.T) {
12+
steps := []resource.TestStep{
13+
{
14+
Config: `
15+
data "stacklet_platform" "test" {}
16+
`,
17+
Check: resource.ComposeAggregateTestCheckFunc(
18+
resource.TestCheckResourceAttrSet("data.stacklet_platform.test", "id"),
19+
resource.TestCheckResourceAttrSet("data.stacklet_platform.test", "external_id"),
20+
// at least one region is enabled
21+
resource.TestCheckResourceAttrSet("data.stacklet_platform.test", "execution_regions.0"),
22+
resource.TestCheckResourceAttrSet("data.stacklet_platform.test", "aws_account_customer_config.terraform_module.source"),
23+
resource.TestCheckResourceAttrSet("data.stacklet_platform.test", "aws_org_read_customer_config.terraform_module.source"),
24+
),
25+
},
26+
}
27+
runRecordedAccTest(t, "TestAccPlatformDataSource", steps)
28+
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
{
2+
"{platform{id,externalID,executionRegions,awsOrgReadCustomerConfig{terraformModule{repositoryURL,source,variablesJSON}},awsAccountCustomerConfig{terraformModule{repositoryURL,source,variablesJSON}}}}": [
3+
{
4+
"request": {
5+
"query": "{platform{id,externalID,executionRegions,awsOrgReadCustomerConfig{terraformModule{repositoryURL,source,variablesJSON}},awsAccountCustomerConfig{terraformModule{repositoryURL,source,variablesJSON}}}}"
6+
},
7+
"response": {
8+
"data": {
9+
"platform": {
10+
"awsAccountCustomerConfig": {
11+
"terraformModule": {
12+
"repositoryURL": "https://github.com/stacklet/terraform-aws-onboarding",
13+
"source": "github.com/stacklet/terraform-aws-onboarding//access",
14+
"variablesJSON": "{\"prefix\": \"stacklet\", \"stacklet_assetdb_role_arn\": \"arn:aws:iam::905418385756:role/dev-collector\", \"stacklet_event_bus_arn\": \"arn:aws:events:eu-north-1:905418385756:event-bus/default\", \"stacklet_execution_role_arn\": \"arn:aws:iam::905418385756:role/dev-stacklet-execution\", \"stacklet_external_id\": \"external=1e28+b6b6/cf0a-4f54.b604,9218@4cf2:50d2\"}"
15+
}
16+
},
17+
"awsOrgReadCustomerConfig": {
18+
"terraformModule": {
19+
"repositoryURL": "https://github.com/stacklet/terraform-aws-onboarding",
20+
"source": "github.com/stacklet/terraform-aws-onboarding//org-read",
21+
"variablesJSON": "{\"prefix\": \"stacklet\", \"stacklet_assetdb_role_arn\": \"arn:aws:iam::905418385756:role/dev-collector\", \"stacklet_external_id\": \"external=1e28+b6b6/cf0a-4f54.b604,9218@4cf2:50d2\", \"stacklet_platform_role_arn\": \"arn:aws:iam::905418385756:role/dev-stacklet-platform-lambda\"}"
22+
}
23+
},
24+
"executionRegions": [
25+
"eu-north-1",
26+
"us-east-1"
27+
],
28+
"externalID": "external=1e28+b6b6/cf0a-4f54.b604,9218@4cf2:50d2",
29+
"id": "WyJwbGF0Zm9ybSJd"
30+
}
31+
}
32+
}
33+
},
34+
{
35+
"request": {
36+
"query": "{platform{id,externalID,executionRegions,awsOrgReadCustomerConfig{terraformModule{repositoryURL,source,variablesJSON}},awsAccountCustomerConfig{terraformModule{repositoryURL,source,variablesJSON}}}}"
37+
},
38+
"response": {
39+
"data": {
40+
"platform": {
41+
"awsAccountCustomerConfig": {
42+
"terraformModule": {
43+
"repositoryURL": "https://github.com/stacklet/terraform-aws-onboarding",
44+
"source": "github.com/stacklet/terraform-aws-onboarding//access",
45+
"variablesJSON": "{\"prefix\": \"stacklet\", \"stacklet_assetdb_role_arn\": \"arn:aws:iam::905418385756:role/dev-collector\", \"stacklet_event_bus_arn\": \"arn:aws:events:eu-north-1:905418385756:event-bus/default\", \"stacklet_execution_role_arn\": \"arn:aws:iam::905418385756:role/dev-stacklet-execution\", \"stacklet_external_id\": \"external=1e28+b6b6/cf0a-4f54.b604,9218@4cf2:50d2\"}"
46+
}
47+
},
48+
"awsOrgReadCustomerConfig": {
49+
"terraformModule": {
50+
"repositoryURL": "https://github.com/stacklet/terraform-aws-onboarding",
51+
"source": "github.com/stacklet/terraform-aws-onboarding//org-read",
52+
"variablesJSON": "{\"prefix\": \"stacklet\", \"stacklet_assetdb_role_arn\": \"arn:aws:iam::905418385756:role/dev-collector\", \"stacklet_external_id\": \"external=1e28+b6b6/cf0a-4f54.b604,9218@4cf2:50d2\", \"stacklet_platform_role_arn\": \"arn:aws:iam::905418385756:role/dev-stacklet-platform-lambda\"}"
53+
}
54+
},
55+
"executionRegions": [
56+
"eu-north-1",
57+
"us-east-1"
58+
],
59+
"externalID": "external=1e28+b6b6/cf0a-4f54.b604,9218@4cf2:50d2",
60+
"id": "WyJwbGF0Zm9ybSJd"
61+
}
62+
}
63+
}
64+
},
65+
{
66+
"request": {
67+
"query": "{platform{id,externalID,executionRegions,awsOrgReadCustomerConfig{terraformModule{repositoryURL,source,variablesJSON}},awsAccountCustomerConfig{terraformModule{repositoryURL,source,variablesJSON}}}}"
68+
},
69+
"response": {
70+
"data": {
71+
"platform": {
72+
"awsAccountCustomerConfig": {
73+
"terraformModule": {
74+
"repositoryURL": "https://github.com/stacklet/terraform-aws-onboarding",
75+
"source": "github.com/stacklet/terraform-aws-onboarding//access",
76+
"variablesJSON": "{\"prefix\": \"stacklet\", \"stacklet_assetdb_role_arn\": \"arn:aws:iam::905418385756:role/dev-collector\", \"stacklet_event_bus_arn\": \"arn:aws:events:eu-north-1:905418385756:event-bus/default\", \"stacklet_execution_role_arn\": \"arn:aws:iam::905418385756:role/dev-stacklet-execution\", \"stacklet_external_id\": \"external=1e28+b6b6/cf0a-4f54.b604,9218@4cf2:50d2\"}"
77+
}
78+
},
79+
"awsOrgReadCustomerConfig": {
80+
"terraformModule": {
81+
"repositoryURL": "https://github.com/stacklet/terraform-aws-onboarding",
82+
"source": "github.com/stacklet/terraform-aws-onboarding//org-read",
83+
"variablesJSON": "{\"prefix\": \"stacklet\", \"stacklet_assetdb_role_arn\": \"arn:aws:iam::905418385756:role/dev-collector\", \"stacklet_external_id\": \"external=1e28+b6b6/cf0a-4f54.b604,9218@4cf2:50d2\", \"stacklet_platform_role_arn\": \"arn:aws:iam::905418385756:role/dev-stacklet-platform-lambda\"}"
84+
}
85+
},
86+
"executionRegions": [
87+
"eu-north-1",
88+
"us-east-1"
89+
],
90+
"externalID": "external=1e28+b6b6/cf0a-4f54.b604,9218@4cf2:50d2",
91+
"id": "WyJwbGF0Zm9ybSJd"
92+
}
93+
}
94+
}
95+
}
96+
]
97+
}

internal/api/api.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ type API struct {
1414
AccountGroup accountGroupAPI
1515
AccountGroupMapping accountGroupMappingAPI
1616
Binding bindingAPI
17+
Platform platformAPI
1718
Policy policyAPI
1819
PolicyCollection policyCollectionAPI
1920
PolicyCollectionMapping policyCollectionMappingAPI
@@ -28,6 +29,7 @@ func New(c *graphql.Client) *API {
2829
AccountGroup: accountGroupAPI{c},
2930
AccountGroupMapping: accountGroupMappingAPI{c},
3031
Binding: bindingAPI{c},
32+
Platform: platformAPI{c},
3133
Policy: policyAPI{c},
3234
PolicyCollection: policyCollectionAPI{c},
3335
PolicyCollectionMapping: policyCollectionMappingAPI{c},

internal/api/platform.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright (c) 2025 - Stacklet, Inc.
2+
3+
package api
4+
5+
import (
6+
"context"
7+
8+
"github.com/hasura/go-graphql-client"
9+
)
10+
11+
// Platform is the data returned by reading platform data.
12+
type Platform struct {
13+
ID string
14+
ExternalID *string `graphql:"externalID"`
15+
ExecutionRegions []string
16+
AWSOrgReadCustomerConfig PlatformCustomerConfig `graphql:"awsOrgReadCustomerConfig"`
17+
AWSAccountCustomerConfig PlatformCustomerConfig `graphql:"awsAccountCustomerConfig"`
18+
}
19+
20+
// PlatformCustomerConfig is the data returned for a customer configuration.
21+
type PlatformCustomerConfig struct {
22+
TerraformModule TerraformModule
23+
}
24+
25+
// TerraformModule is the data returned for terraform module definitions.
26+
type TerraformModule struct {
27+
RepositoryURL string `graphql:"repositoryURL"`
28+
Source string
29+
VariablesJSON string `graphql:"variablesJSON"`
30+
}
31+
32+
type platformAPI struct {
33+
c *graphql.Client
34+
}
35+
36+
// Read returns platform data.
37+
func (a platformAPI) Read(ctx context.Context) (*Platform, error) {
38+
var query struct {
39+
Platform Platform `graphql:"platform"`
40+
}
41+
if err := a.c.Query(ctx, &query, nil); err != nil {
42+
return nil, NewAPIError(err)
43+
}
44+
return &query.Platform, nil
45+
}

internal/datasources/datasources.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ var DATASOURCES = []func() datasource.DataSource{
1010
NewAccountDataSource,
1111
NewAccountGroupDataSource,
1212
NewBindingDataSource,
13+
NewPlatformDataSource,
1314
NewPolicyCollectionDataSource,
1415
NewPolicyDataSource,
1516
NewRepositoryDataSource,

0 commit comments

Comments
 (0)