Skip to content

Commit

Permalink
feat: add secret references to data sources
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-s committed Aug 8, 2024
1 parent 46fc21d commit 8eb8cda
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
10 changes: 6 additions & 4 deletions internal/resources/datasource_certificate_secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ func (d *certificateDataSource) Schema(_ context.Context, _ datasource.SchemaReq
Computed: true,
Description: "Public key of the certificate",
},

"reference": schema.StringAttribute{
Computed: true,
Description: "reference attribute of the secret",
},
"revision": schema.Int64Attribute{
Computed: true,
Required: false,
Expand Down Expand Up @@ -110,11 +113,9 @@ func (d *certificateDataSource) Read(ctx context.Context, req datasource.ReadReq
}

data.Name = types.StringValue(secret.Name)

data.ProjectID = types.StringValue(data.ProjectID.ValueString())

data.Reference = types.StringValue(fmt.Sprintf("projects:%s/%s", data.ProjectID, data.Name))
data.Revision = types.Int64Value(int64(secret.Revision))

data.Certificate = types.StringValue(secret.Payload.SecretMetaResponseCertificatePayload.Certificate)
date := resourceDate{
CreatedAt: secret.Date.CreatedAt,
Expand All @@ -135,6 +136,7 @@ type certificatesecretDataSourceModel struct {
ProjectID types.String `tfsdk:"project_id"`
Name types.String `tfsdk:"name"`
Certificate types.String `tfsdk:"certificate"`
Reference types.String `tfsdk:"reference"`
Revision types.Int64 `tfsdk:"revision"`
Date basetypes.ObjectValue `tfsdk:"date"`
}
10 changes: 6 additions & 4 deletions internal/resources/datasource_environment_secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ func (d *environmentDataSource) Schema(_ context.Context, _ datasource.SchemaReq
Computed: true,
Description: "Value of the environment variable",
},

"reference": schema.StringAttribute{
Computed: true,
Description: "reference attribute of the secret",
},
"revision": schema.Int64Attribute{
Computed: true,
Required: false,
Expand Down Expand Up @@ -110,11 +113,9 @@ func (d *environmentDataSource) Read(ctx context.Context, req datasource.ReadReq
}

data.Name = types.StringValue(secret.Name)

data.ProjectID = types.StringValue(data.ProjectID.ValueString())

data.Reference = types.StringValue(fmt.Sprintf("projects:%s/%s", data.ProjectID, data.Name))
data.Revision = types.Int64Value(int64(secret.Revision))

date := resourceDate{
CreatedAt: secret.Date.CreatedAt,
UpdatedAt: secret.Date.UpdatedAt,
Expand All @@ -134,6 +135,7 @@ type environmentsecretDataSourceModel struct {
ProjectID types.String `tfsdk:"project_id"`
Name types.String `tfsdk:"name"`
Value types.String `tfsdk:"value"`
Reference types.String `tfsdk:"reference"`
Revision types.Int64 `tfsdk:"revision"`
Date basetypes.ObjectValue `tfsdk:"date"`
}
11 changes: 6 additions & 5 deletions internal/resources/datasource_registry_secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ func (d *registryDataSource) Schema(_ context.Context, _ datasource.SchemaReques
Computed: true,
Description: "url of the registry",
},

"reference": schema.StringAttribute{
Computed: true,
Description: "reference attribute of the secret",
},
"revision": schema.Int64Attribute{
Computed: true,
Required: false,
Expand Down Expand Up @@ -110,13 +113,10 @@ func (d *registryDataSource) Read(ctx context.Context, req datasource.ReadReques
}

data.Name = types.StringValue(secret.Name)

data.ProjectID = types.StringValue(data.ProjectID.ValueString())

data.Registry = types.StringValue(secret.Payload.SecretMetaResponseRegistryPayload.Registry)

data.Reference = types.StringValue(fmt.Sprintf("projects:%s/%s", data.ProjectID, data.Name))
data.Revision = types.Int64Value(int64(secret.Revision))

date := resourceDate{
CreatedAt: secret.Date.CreatedAt,
UpdatedAt: secret.Date.UpdatedAt,
Expand All @@ -136,6 +136,7 @@ type registrysecretDataSourceModel struct {
ProjectID types.String `tfsdk:"project_id"`
Name types.String `tfsdk:"name"`
Registry types.String `tfsdk:"registry"`
Reference types.String `tfsdk:"reference"`
Revision types.Int64 `tfsdk:"revision"`
Date basetypes.ObjectValue `tfsdk:"date"`
}

0 comments on commit 8eb8cda

Please sign in to comment.