Skip to content

Commit 05c6d89

Browse files
committed
add terraform modules to data source
1 parent 3bc8d76 commit 05c6d89

File tree

6 files changed

+226
-13
lines changed

6 files changed

+226
-13
lines changed

docs/data-sources/platform.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,43 @@ data "stacklet_platform" "example" {}
2222

2323
### Read-Only
2424

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))
2527
- `default_role` (String) Default role for users.
2628
- `execution_regions` (List of String) List of regions for which execution is enabled.
2729
- `external_id` (String) The external ID for the deployment.
2830
- `id` (String) The GraphQL Node ID.
31+
32+
<a id="nestedatt--aws_account_customer_config"></a>
33+
### Nested Schema for `aws_account_customer_config`
34+
35+
Read-Only:
36+
37+
- `terraform_module` (Attributes) Terraform module configuration for account setup. (see [below for nested schema](#nestedatt--aws_account_customer_config--terraform_module))
38+
39+
<a id="nestedatt--aws_account_customer_config--terraform_module"></a>
40+
### Nested Schema for `aws_account_customer_config.terraform_module`
41+
42+
Read-Only:
43+
44+
- `repository_url` (String) Module repository URL.
45+
- `source` (String) Module source.
46+
- `variables_json` (String) JSON-encoded variables for module configuration.
47+
48+
49+
50+
<a id="nestedatt--aws_org_read_customer_config"></a>
51+
### Nested Schema for `aws_org_read_customer_config`
52+
53+
Read-Only:
54+
55+
- `terraform_module` (Attributes) Terraform module configuration for organization read access setup. (see [below for nested schema](#nestedatt--aws_org_read_customer_config--terraform_module))
56+
57+
<a id="nestedatt--aws_org_read_customer_config--terraform_module"></a>
58+
### Nested Schema for `aws_org_read_customer_config.terraform_module`
59+
60+
Read-Only:
61+
62+
- `repository_url` (String) Module repository URL.
63+
- `source` (String) Module source.
64+
- `variables_json` (String) JSON-encoded variables for module configuration.

internal/acceptance_tests/platform_data_source_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ func TestAccPlatformDataSource(t *testing.T) {
2020
// at least one region is enabled
2121
resource.TestCheckResourceAttrSet("data.stacklet_platform.test", "execution_regions.0"),
2222
resource.TestCheckResourceAttrSet("data.stacklet_platform.test", "default_role"),
23+
resource.TestCheckResourceAttrSet("data.stacklet_platform.test", "aws_account_customer_config.terraform_module.source"),
24+
resource.TestCheckResourceAttrSet("data.stacklet_platform.test", "aws_org_read_customer_config.terraform_module.source"),
2325
),
2426
},
2527
}

internal/acceptance_tests/recordings/TestAccPlatformDataSource.json

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
11
{
2-
"{platform{id,externalID,executionRegions,defaultRole}}": [
2+
"{platform{id,externalID,executionRegions,defaultRole,awsOrgReadCustomerConfig{terraformModule{repositoryURL,source,variablesJSON}},awsAccountCustomerConfig{terraformModule{repositoryURL,source,variablesJSON}}}}": [
33
{
44
"request": {
5-
"query": "{platform{id,externalID,executionRegions,defaultRole}}"
5+
"query": "{platform{id,externalID,executionRegions,defaultRole,awsOrgReadCustomerConfig{terraformModule{repositoryURL,source,variablesJSON}},awsAccountCustomerConfig{terraformModule{repositoryURL,source,variablesJSON}}}}"
66
},
77
"response": {
88
"data": {
99
"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+
},
1024
"defaultRole": "admin",
1125
"executionRegions": [
1226
"eu-north-1",
@@ -20,11 +34,25 @@
2034
},
2135
{
2236
"request": {
23-
"query": "{platform{id,externalID,executionRegions,defaultRole}}"
37+
"query": "{platform{id,externalID,executionRegions,defaultRole,awsOrgReadCustomerConfig{terraformModule{repositoryURL,source,variablesJSON}},awsAccountCustomerConfig{terraformModule{repositoryURL,source,variablesJSON}}}}"
2438
},
2539
"response": {
2640
"data": {
2741
"platform": {
42+
"awsAccountCustomerConfig": {
43+
"terraformModule": {
44+
"repositoryURL": "https://github.com/stacklet/terraform-aws-onboarding",
45+
"source": "github.com/stacklet/terraform-aws-onboarding//access",
46+
"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\"}"
47+
}
48+
},
49+
"awsOrgReadCustomerConfig": {
50+
"terraformModule": {
51+
"repositoryURL": "https://github.com/stacklet/terraform-aws-onboarding",
52+
"source": "github.com/stacklet/terraform-aws-onboarding//org-read",
53+
"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\"}"
54+
}
55+
},
2856
"defaultRole": "admin",
2957
"executionRegions": [
3058
"eu-north-1",
@@ -38,11 +66,25 @@
3866
},
3967
{
4068
"request": {
41-
"query": "{platform{id,externalID,executionRegions,defaultRole}}"
69+
"query": "{platform{id,externalID,executionRegions,defaultRole,awsOrgReadCustomerConfig{terraformModule{repositoryURL,source,variablesJSON}},awsAccountCustomerConfig{terraformModule{repositoryURL,source,variablesJSON}}}}"
4270
},
4371
"response": {
4472
"data": {
4573
"platform": {
74+
"awsAccountCustomerConfig": {
75+
"terraformModule": {
76+
"repositoryURL": "https://github.com/stacklet/terraform-aws-onboarding",
77+
"source": "github.com/stacklet/terraform-aws-onboarding//access",
78+
"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\"}"
79+
}
80+
},
81+
"awsOrgReadCustomerConfig": {
82+
"terraformModule": {
83+
"repositoryURL": "https://github.com/stacklet/terraform-aws-onboarding",
84+
"source": "github.com/stacklet/terraform-aws-onboarding//org-read",
85+
"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\"}"
86+
}
87+
},
4688
"defaultRole": "admin",
4789
"executionRegions": [
4890
"eu-north-1",
@@ -55,4 +97,4 @@
5597
}
5698
}
5799
]
58-
}
100+
}

internal/api/platform.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,24 @@ import (
1010

1111
// Platform is the data returned by reading platform data.
1212
type Platform struct {
13-
ID string
14-
ExternalID *string `graphql:"externalID"`
15-
ExecutionRegions []string
16-
DefaultRole *string
13+
ID string
14+
ExternalID *string `graphql:"externalID"`
15+
ExecutionRegions []string
16+
DefaultRole *string
17+
AWSOrgReadCustomerConfig PlatformCustomerConfig `graphql:"awsOrgReadCustomerConfig"`
18+
AWSAccountCustomerConfig PlatformCustomerConfig `graphql:"awsAccountCustomerConfig"`
19+
}
20+
21+
// PlatformCustomerConfig is the data returned for a customer configuration.
22+
type PlatformCustomerConfig struct {
23+
TerraformModule TerraformModule
24+
}
25+
26+
// TerraformModule is the data returned for terraform module definitions.
27+
type TerraformModule struct {
28+
RepositoryURL string `graphql:"repositoryURL"`
29+
Source string
30+
VariablesJSON string `graphql:"variablesJSON"`
1731
}
1832

1933
type platformAPI struct {

internal/datasources/platform.go

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ import (
77

88
"github.com/hashicorp/terraform-plugin-framework/datasource"
99
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
10+
"github.com/hashicorp/terraform-plugin-framework/diag"
1011
"github.com/hashicorp/terraform-plugin-framework/types"
12+
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
1113

1214
"github.com/stacklet/terraform-provider-stacklet/internal/api"
1315
"github.com/stacklet/terraform-provider-stacklet/internal/errors"
@@ -53,6 +55,54 @@ func (d *platformDataSource) Schema(_ context.Context, _ datasource.SchemaReques
5355
Description: "Default role for users.",
5456
Computed: true,
5557
},
58+
"aws_account_customer_config": schema.SingleNestedAttribute{
59+
Description: "Customer configuration for AWS accounts.",
60+
Computed: true,
61+
Attributes: map[string]schema.Attribute{
62+
"terraform_module": schema.SingleNestedAttribute{
63+
Description: "Terraform module configuration for account setup.",
64+
Computed: true,
65+
Attributes: map[string]schema.Attribute{
66+
"repository_url": schema.StringAttribute{
67+
Description: "Module repository URL.",
68+
Computed: true,
69+
},
70+
"source": schema.StringAttribute{
71+
Description: "Module source.",
72+
Computed: true,
73+
},
74+
"variables_json": schema.StringAttribute{
75+
Description: "JSON-encoded variables for module configuration.",
76+
Computed: true,
77+
},
78+
},
79+
},
80+
},
81+
},
82+
"aws_org_read_customer_config": schema.SingleNestedAttribute{
83+
Description: "Customer configuration for AWS organization read access.",
84+
Computed: true,
85+
Attributes: map[string]schema.Attribute{
86+
"terraform_module": schema.SingleNestedAttribute{
87+
Description: "Terraform module configuration for organization read access setup.",
88+
Computed: true,
89+
Attributes: map[string]schema.Attribute{
90+
"repository_url": schema.StringAttribute{
91+
Description: "Module repository URL.",
92+
Computed: true,
93+
},
94+
"source": schema.StringAttribute{
95+
Description: "Module source.",
96+
Computed: true,
97+
},
98+
"variables_json": schema.StringAttribute{
99+
Description: "JSON-encoded variables for module configuration.",
100+
Computed: true,
101+
},
102+
},
103+
},
104+
},
105+
},
56106
},
57107
}
58108
}
@@ -82,5 +132,42 @@ func (d *platformDataSource) Read(ctx context.Context, req datasource.ReadReques
82132
data.ExternalID = tftypes.NullableString(platform.ExternalID)
83133
data.ExecutionRegions = tftypes.StringsList(platform.ExecutionRegions)
84134
data.DefaultRole = tftypes.NullableString(platform.DefaultRole)
135+
awsAccountCustomerConfig, diags := d.getCustomerConfig(ctx, platform.AWSAccountCustomerConfig)
136+
resp.Diagnostics.Append(diags...)
137+
data.AWSAccountCustomerConfig = awsAccountCustomerConfig
138+
awsOrgReadCustomerConfig, diags := d.getCustomerConfig(ctx, platform.AWSOrgReadCustomerConfig)
139+
resp.Diagnostics.Append(diags...)
140+
data.AWSOrgReadCustomerConfig = awsOrgReadCustomerConfig
141+
142+
if resp.Diagnostics.HasError() {
143+
return
144+
}
85145
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
86146
}
147+
148+
func (d platformDataSource) getCustomerConfig(ctx context.Context, config api.PlatformCustomerConfig) (basetypes.ObjectValue, diag.Diagnostics) {
149+
terraformModule, diags := tftypes.ObjectValue(
150+
ctx,
151+
&config.TerraformModule,
152+
func() (*models.TerraformModule, diag.Diagnostics) {
153+
return &models.TerraformModule{
154+
RepositoryURL: types.StringValue(config.TerraformModule.RepositoryURL),
155+
Source: types.StringValue(config.TerraformModule.Source),
156+
VariablesJSON: types.StringValue(config.TerraformModule.VariablesJSON),
157+
}, nil
158+
},
159+
)
160+
if diags.HasError() {
161+
return basetypes.NewObjectNull(models.PlatformCustomerConfig{}.AttributeTypes()), diags
162+
}
163+
164+
return tftypes.ObjectValue(
165+
ctx,
166+
&config,
167+
func() (*models.PlatformCustomerConfig, diag.Diagnostics) {
168+
return &models.PlatformCustomerConfig{
169+
TerraformModule: terraformModule,
170+
}, nil
171+
},
172+
)
173+
}

internal/models/platform.go

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,45 @@
33
package models
44

55
import (
6+
"github.com/hashicorp/terraform-plugin-framework/attr"
67
"github.com/hashicorp/terraform-plugin-framework/types"
8+
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
79
)
810

911
// PlatformDataSource is the model for the platform data source.
1012
type PlatformDataSource struct {
11-
ID types.String `tfsdk:"id"`
12-
ExternalID types.String `tfsdk:"external_id"`
13-
ExecutionRegions types.List `tfsdk:"execution_regions"`
14-
DefaultRole types.String `tfsdk:"default_role"`
13+
ID types.String `tfsdk:"id"`
14+
ExternalID types.String `tfsdk:"external_id"`
15+
ExecutionRegions types.List `tfsdk:"execution_regions"`
16+
DefaultRole types.String `tfsdk:"default_role"`
17+
AWSAccountCustomerConfig types.Object `tfsdk:"aws_account_customer_config"`
18+
AWSOrgReadCustomerConfig types.Object `tfsdk:"aws_org_read_customer_config"`
19+
}
20+
21+
// PlatformCustomerConfig is the model for customer config definitions.
22+
type PlatformCustomerConfig struct {
23+
TerraformModule types.Object `tfsdk:"terraform_module"`
24+
}
25+
26+
func (c PlatformCustomerConfig) AttributeTypes() map[string]attr.Type {
27+
return map[string]attr.Type{
28+
"terraform_module": basetypes.ObjectType{
29+
AttrTypes: TerraformModule{}.AttributeTypes(),
30+
},
31+
}
32+
}
33+
34+
// TerraformModule is the model for terraform modules definitions.
35+
type TerraformModule struct {
36+
RepositoryURL types.String `tfsdk:"repository_url"`
37+
Source types.String `tfsdk:"source"`
38+
VariablesJSON types.String `tfsdk:"variables_json"`
39+
}
40+
41+
func (c TerraformModule) AttributeTypes() map[string]attr.Type {
42+
return map[string]attr.Type{
43+
"repository_url": types.StringType,
44+
"source": types.StringType,
45+
"variables_json": types.StringType,
46+
}
1547
}

0 commit comments

Comments
 (0)