-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: data source service account OIDC identity
- Loading branch information
1 parent
ee401d3
commit 2cbe38e
Showing
4 changed files
with
92 additions
and
1 deletion.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
octopusdeploy_framework/datasource_service_account_oidc_identity.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package octopusdeploy_framework | ||
|
||
import ( | ||
"context" | ||
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/serviceaccounts" | ||
"github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/schemas" | ||
"github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/util" | ||
"github.com/hashicorp/terraform-plugin-framework/datasource" | ||
"github.com/hashicorp/terraform-plugin-framework/types" | ||
) | ||
|
||
type serviceAccountOIDCIdentityDataSource struct { | ||
*Config | ||
} | ||
|
||
func NewServiceAccountOIDCIdentityDataSource() datasource.DataSource { | ||
return &serviceAccountOIDCIdentityDataSource{} | ||
} | ||
|
||
func (*serviceAccountOIDCIdentityDataSource) Metadata(_ context.Context, _ datasource.MetadataRequest, resp *datasource.MetadataResponse) { | ||
resp.TypeName = util.GetTypeName(schemas.ServiceAccountOIDCIdentityDatasourceName) | ||
} | ||
|
||
func (s *serviceAccountOIDCIdentityDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) { | ||
s.Config = DataSourceConfiguration(req, resp) | ||
} | ||
|
||
func (*serviceAccountOIDCIdentityDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) { | ||
resp.Schema = schemas.ServiceAccountOIDCIdentitySchema{}.GetDatasourceSchema() | ||
} | ||
|
||
func (s *serviceAccountOIDCIdentityDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { | ||
var err error | ||
var data schemas.OIDCServiceAccountDatasourceSchemaModel | ||
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...) | ||
if resp.Diagnostics.HasError() { | ||
return | ||
} | ||
|
||
oidcIdentity, err := serviceaccounts.GetOIDCIdentityByID(s.Client, data.ServiceAccountID.ValueString(), data.ID.ValueString()) | ||
if err != nil { | ||
resp.Diagnostics.AddError("unable to load service account OIDC Identity", err.Error()) | ||
return | ||
} | ||
|
||
updateServiceAccountOIDCDataModel(oidcIdentity, &data) | ||
|
||
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) | ||
} | ||
|
||
func updateServiceAccountOIDCDataModel(request *serviceaccounts.OIDCIdentity, model *schemas.OIDCServiceAccountDatasourceSchemaModel) { | ||
model.Name = types.StringValue(request.Name) | ||
model.Issuer = types.StringValue(request.Issuer) | ||
model.Subject = types.StringValue(request.Subject) | ||
model.ID = types.StringValue(request.ID) | ||
model.ServiceAccountID = types.StringValue(request.ServiceAccountID) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters