Skip to content

Commit 058f4bd

Browse files
authored
feat: Add support for console OIDC provider type (#85)
1 parent 6c85910 commit 058f4bd

File tree

9 files changed

+61
-19
lines changed

9 files changed

+61
-19
lines changed

docs/resources/oidc_provider.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ description: |-
2323
### Optional
2424

2525
- `auth_method` (String)
26+
- `bindings` (Attributes Set) The users and groups able to utilize this provider. (see [below for nested schema](#nestedatt--bindings))
2627
- `description` (String) Description of this OIDC provider.
2728
- `redirect_uris` (Set of String)
2829

@@ -31,3 +32,12 @@ description: |-
3132
- `client_id` (String, Sensitive)
3233
- `client_secret` (String, Sensitive)
3334
- `id` (String) Internal identifier of this OIDC provider.
35+
36+
<a id="nestedatt--bindings"></a>
37+
### Nested Schema for `bindings`
38+
39+
Optional:
40+
41+
- `group_id` (String)
42+
- `id` (String)
43+
- `user_id` (String)

example/oidcprovider/main.tf

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,17 @@ provider "plural" {
1111
use_cli = true
1212
}
1313

14+
data "plural_user" "user" {
15+
16+
}
17+
1418
resource "plural_oidc_provider" "provider" {
1519
name = "tf-test-provider"
1620
auth_method = "BASIC"
17-
type = "PLURAL"
21+
type = "CONSOLE"
1822
description = "test provider"
1923
redirect_uris = ["localhost:8000"]
24+
bindings = [
25+
{ user_id = data.plural_user.user.id }
26+
]
2027
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ require (
1212
github.com/hashicorp/terraform-plugin-framework-validators v0.16.0
1313
github.com/hashicorp/terraform-plugin-log v0.9.0
1414
github.com/mitchellh/go-homedir v1.1.0
15-
github.com/pluralsh/console/go/client v1.30.0
15+
github.com/pluralsh/console/go/client v1.33.0
1616
github.com/pluralsh/plural-cli v0.12.1
1717
github.com/pluralsh/polly v0.2.0
1818
github.com/samber/lo v1.49.1

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -618,8 +618,8 @@ github.com/pjbgf/sha1cd v0.3.2/go.mod h1:zQWigSxVmsHEZow5qaLtPYxpcKMMQpa09ixqBxu
618618
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
619619
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
620620
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
621-
github.com/pluralsh/console/go/client v1.30.0 h1:HLhIoZrSfxwWkGRs36xdB5d+OAaTCDvjNDNP2Fik30s=
622-
github.com/pluralsh/console/go/client v1.30.0/go.mod h1:lpoWASYsM9keNePS3dpFiEisUHEfObIVlSL3tzpKn8k=
621+
github.com/pluralsh/console/go/client v1.33.0 h1:rsp3zopb0wdMEvvQ+dOTM+I3qCoFWOk62JETwIPJrFw=
622+
github.com/pluralsh/console/go/client v1.33.0/go.mod h1:rPx6hufc/s17Wzy+7C4ZnA1nmn1JR0m4JeoxAQYj8+4=
623623
github.com/pluralsh/gqlclient v1.12.2 h1:BrEFAASktf4quFw57CIaLAd+NZUTLhG08fe6tnhBQN4=
624624
github.com/pluralsh/gqlclient v1.12.2/go.mod h1:OEjN9L63x8m3A3eQBv5kVkFgiY9fp2aZ0cgOF0uII58=
625625
github.com/pluralsh/plural-cli v0.12.1 h1:+bcYoepZ2tT1qRwb5RgXnVPs23RO7X+T0iTgVECBpa4=

internal/common/cluster_node_pool.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func (c *NodePoolCloudSettings) Attributes() *console.NodePoolCloudAttributes {
110110
}
111111

112112
if c.AWS != nil {
113-
return &console.NodePoolCloudAttributes{Aws: c.AWS.Attributes()}
113+
return &console.NodePoolCloudAttributes{AWS: c.AWS.Attributes()}
114114
}
115115

116116
return nil
@@ -124,8 +124,8 @@ var NodePoolCloudSettingsAWSAttrTypes = map[string]attr.Type{
124124
"launch_template_id": types.StringType,
125125
}
126126

127-
func (c *NodePoolCloudSettingsAWS) Attributes() *console.AwsNodeCloudAttributes {
128-
return &console.AwsNodeCloudAttributes{
127+
func (c *NodePoolCloudSettingsAWS) Attributes() *console.AWSNodeCloudAttributes {
128+
return &console.AWSNodeCloudAttributes{
129129
LaunchTemplateID: c.LaunchTemplateId.ValueStringPointer(),
130130
}
131131
}

internal/model/oidc_provider.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ type OIDCProvider struct {
2121
ClientSecret types.String `tfsdk:"client_secret"`
2222
AuthMethod types.String `tfsdk:"auth_method"`
2323
RedirectURIs types.Set `tfsdk:"redirect_uris"`
24+
Bindings types.Set `tfsdk:"bindings"`
2425
}
2526

2627
func (p *OIDCProvider) Attributes(ctx context.Context, d *diag.Diagnostics) gqlclient.OidcProviderAttributes {
@@ -29,6 +30,7 @@ func (p *OIDCProvider) Attributes(ctx context.Context, d *diag.Diagnostics) gqlc
2930
Description: p.descriptionAttribute(),
3031
AuthMethod: p.authMethodAttribute(),
3132
RedirectUris: p.redirectURIsAttribute(ctx, d),
33+
Bindings: common.SetToPolicyBindingAttributes(p.Bindings, ctx, d),
3234
}
3335
}
3436

internal/model/provider.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,15 @@ func (p *ProviderCloudSettings) Attributes() *console.CloudProviderSettingsAttri
5353
}
5454

5555
if p.AWS != nil {
56-
return &console.CloudProviderSettingsAttributes{Aws: p.AWS.Attributes()}
56+
return &console.CloudProviderSettingsAttributes{AWS: p.AWS.Attributes()}
5757
}
5858

5959
if p.Azure != nil {
6060
return &console.CloudProviderSettingsAttributes{Azure: p.Azure.Attributes()}
6161
}
6262

6363
if p.GCP != nil {
64-
return &console.CloudProviderSettingsAttributes{Gcp: p.GCP.Attributes()}
64+
return &console.CloudProviderSettingsAttributes{GCP: p.GCP.Attributes()}
6565
}
6666

6767
return nil
@@ -72,8 +72,8 @@ type ProviderCloudSettingsAWS struct {
7272
SecretAccessKey types.String `tfsdk:"secret_access_key"`
7373
}
7474

75-
func (p *ProviderCloudSettingsAWS) Attributes() *console.AwsSettingsAttributes {
76-
return &console.AwsSettingsAttributes{
75+
func (p *ProviderCloudSettingsAWS) Attributes() *console.AWSSettingsAttributes {
76+
return &console.AWSSettingsAttributes{
7777
AccessKeyID: p.AccessKeyId.ValueString(),
7878
SecretAccessKey: p.SecretAccessKey.ValueString(),
7979
}
@@ -99,8 +99,8 @@ type ProviderCloudSettingsGCP struct {
9999
Credentials types.String `tfsdk:"credentials"`
100100
}
101101

102-
func (p *ProviderCloudSettingsGCP) Attributes() *console.GcpSettingsAttributes {
103-
return &console.GcpSettingsAttributes{
102+
func (p *ProviderCloudSettingsGCP) Attributes() *console.GCPSettingsAttributes {
103+
return &console.GCPSettingsAttributes{
104104
ApplicationCredentials: p.Credentials.ValueString(),
105105
}
106106
}

internal/resource/cluster_model.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -174,15 +174,15 @@ func (c *ClusterCloudSettings) Attributes() *console.CloudSettingsAttributes {
174174
}
175175

176176
if c.AWS != nil {
177-
return &console.CloudSettingsAttributes{Aws: c.AWS.Attributes()}
177+
return &console.CloudSettingsAttributes{AWS: c.AWS.Attributes()}
178178
}
179179

180180
if c.Azure != nil {
181181
return &console.CloudSettingsAttributes{Azure: c.Azure.Attributes()}
182182
}
183183

184184
if c.GCP != nil {
185-
return &console.CloudSettingsAttributes{Gcp: c.GCP.Attributes()}
185+
return &console.CloudSettingsAttributes{GCP: c.GCP.Attributes()}
186186
}
187187

188188
return nil
@@ -192,8 +192,8 @@ type ClusterCloudSettingsAWS struct {
192192
Region types.String `tfsdk:"region"`
193193
}
194194

195-
func (c *ClusterCloudSettingsAWS) Attributes() *console.AwsCloudAttributes {
196-
return &console.AwsCloudAttributes{
195+
func (c *ClusterCloudSettingsAWS) Attributes() *console.AWSCloudAttributes {
196+
return &console.AWSCloudAttributes{
197197
Region: c.Region.ValueStringPointer(),
198198
}
199199
}
@@ -220,8 +220,8 @@ type ClusterCloudSettingsGCP struct {
220220
Project types.String `tfsdk:"project"`
221221
}
222222

223-
func (c *ClusterCloudSettingsGCP) Attributes() *console.GcpCloudAttributes {
224-
return &console.GcpCloudAttributes{
223+
func (c *ClusterCloudSettingsGCP) Attributes() *console.GCPCloudAttributes {
224+
return &console.GCPCloudAttributes{
225225
Project: c.Project.ValueStringPointer(),
226226
Network: c.Network.ValueStringPointer(),
227227
Region: c.Region.ValueStringPointer(),

internal/resource/oidc_provider.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/hashicorp/terraform-plugin-framework/resource"
1414
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
1515
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
16+
"github.com/hashicorp/terraform-plugin-framework/resource/schema/setplanmodifier"
1617
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault"
1718
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
1819
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
@@ -92,6 +93,28 @@ func (r *OIDCProviderResource) Schema(_ context.Context, _ resource.SchemaReques
9293
Optional: true,
9394
ElementType: types.StringType,
9495
},
96+
"bindings": schema.SetNestedAttribute{
97+
Description: "The users and groups able to utilize this provider..",
98+
MarkdownDescription: "The users and groups able to utilize this provider.",
99+
Optional: true,
100+
NestedObject: schema.NestedAttributeObject{
101+
Attributes: map[string]schema.Attribute{
102+
"group_id": schema.StringAttribute{
103+
Optional: true,
104+
PlanModifiers: []planmodifier.String{stringplanmodifier.RequiresReplace()},
105+
},
106+
"id": schema.StringAttribute{
107+
Optional: true,
108+
PlanModifiers: []planmodifier.String{stringplanmodifier.RequiresReplace()},
109+
},
110+
"user_id": schema.StringAttribute{
111+
Optional: true,
112+
PlanModifiers: []planmodifier.String{stringplanmodifier.RequiresReplace()},
113+
},
114+
},
115+
},
116+
PlanModifiers: []planmodifier.Set{setplanmodifier.RequiresReplace()},
117+
},
95118
},
96119
}
97120
}

0 commit comments

Comments
 (0)