-
Notifications
You must be signed in to change notification settings - Fork 18
Audit log sink management terraform #380
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
cae6fab
72a6ece
5c06226
2955c95
e221f42
8f57327
7d01344
06cf5cb
a98f32d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| --- | ||
| # generated by https://github.com/hashicorp/terraform-plugin-docs | ||
| page_title: "temporalcloud_account_audit_log_sink Resource - terraform-provider-temporalcloud" | ||
| subcategory: "" | ||
| description: |- | ||
| Provisions an account audit log sink. | ||
| --- | ||
|
|
||
| # temporalcloud_account_audit_log_sink (Resource) | ||
|
|
||
| Provisions an account audit log sink. | ||
|
|
||
| ## Example Usage | ||
|
|
||
| ```terraform | ||
| terraform { | ||
| required_providers { | ||
| temporalcloud = { | ||
| source = "temporalio/temporalcloud" | ||
| } | ||
| } | ||
| } | ||
|
|
||
| provider "temporalcloud" { | ||
|
|
||
| } | ||
|
|
||
| # Example with Kinesis | ||
| resource "temporalcloud_account_audit_log_sink" "kinesis_sink" { | ||
| sink_name = "my-kinesis-sink" | ||
| enabled = true | ||
| kinesis = { | ||
| role_name = "arn:aws:iam::123456789012:role/TemporalCloudKinesisRole" | ||
| destination_uri = "arn:aws:kinesis:us-east-1:123456789012:stream/my-audit-stream" | ||
| region = "us-east-1" | ||
| } | ||
| } | ||
|
|
||
| # Example with PubSub | ||
| resource "temporalcloud_account_audit_log_sink" "pubsub_sink" { | ||
| sink_name = "my-pubsub-sink" | ||
| enabled = true | ||
| pubsub = { | ||
| service_account_id = "my-service-account-id" | ||
| topic_name = "temporal-audit-logs" | ||
| gcp_project_id = "my-gcp-project" | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| <!-- schema generated by tfplugindocs --> | ||
| ## Schema | ||
|
|
||
| ### Required | ||
|
|
||
| - `sink_name` (String) The unique name of the audit log sink, it can't be changed once set. | ||
|
|
||
| ### Optional | ||
|
|
||
| - `enabled` (Boolean) A flag indicating whether the audit log sink is enabled or not. | ||
| - `kinesis` (Attributes) The Kinesis configuration details when destination_type is Kinesis. (see [below for nested schema](#nestedatt--kinesis)) | ||
| - `pubsub` (Attributes) The PubSub configuration details when destination_type is PubSub. (see [below for nested schema](#nestedatt--pubsub)) | ||
| - `timeouts` (Block, Optional) (see [below for nested schema](#nestedblock--timeouts)) | ||
|
|
||
| ### Read-Only | ||
|
|
||
| - `id` (String) The unique identifier of the account audit log sink. | ||
|
|
||
| <a id="nestedatt--kinesis"></a> | ||
| ### Nested Schema for `kinesis` | ||
|
|
||
| Required: | ||
|
|
||
| - `destination_uri` (String) The destination URI of the Kinesis stream where Temporal will send data. | ||
| - `region` (String) The region of the Kinesis stream. | ||
| - `role_name` (String) The IAM role that Temporal Cloud assumes for writing records to the customer's Kinesis stream. | ||
|
|
||
|
|
||
| <a id="nestedatt--pubsub"></a> | ||
| ### Nested Schema for `pubsub` | ||
|
|
||
| Required: | ||
|
|
||
| - `gcp_project_id` (String) The GCP project ID of the PubSub topic and service account. | ||
| - `service_account_id` (String) The customer service account ID that Temporal Cloud impersonates for writing records to the customer's PubSub topic. | ||
| - `topic_name` (String) The destination PubSub topic name for Temporal. | ||
|
|
||
|
|
||
| <a id="nestedblock--timeouts"></a> | ||
| ### Nested Schema for `timeouts` | ||
|
|
||
| Optional: | ||
|
|
||
| - `create` (String) A string that can be [parsed as a duration](https://pkg.go.dev/time#ParseDuration) consisting of numbers and unit suffixes, such as "30s" or "2h45m". Valid time units are "s" (seconds), "m" (minutes), "h" (hours). | ||
| - `delete` (String) A string that can be [parsed as a duration](https://pkg.go.dev/time#ParseDuration) consisting of numbers and unit suffixes, such as "30s" or "2h45m". Valid time units are "s" (seconds), "m" (minutes), "h" (hours). Setting a timeout for a Delete operation is only applicable if changes are saved into state before the destroy operation occurs. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| terraform { | ||
| required_providers { | ||
| temporalcloud = { | ||
| source = "temporalio/temporalcloud" | ||
| } | ||
| } | ||
| } | ||
|
|
||
| provider "temporalcloud" { | ||
|
|
||
| } | ||
|
|
||
| # Example with Kinesis | ||
| resource "temporalcloud_account_audit_log_sink" "kinesis_sink" { | ||
| sink_name = "my-kinesis-sink" | ||
| enabled = true | ||
| kinesis = { | ||
| role_name = "arn:aws:iam::123456789012:role/TemporalCloudKinesisRole" | ||
| destination_uri = "arn:aws:kinesis:us-east-1:123456789012:stream/my-audit-stream" | ||
| region = "us-east-1" | ||
| } | ||
| } | ||
|
|
||
| # Example with PubSub | ||
| resource "temporalcloud_account_audit_log_sink" "pubsub_sink" { | ||
| sink_name = "my-pubsub-sink" | ||
| enabled = true | ||
| pubsub = { | ||
| service_account_id = "my-service-account-id" | ||
| topic_name = "temporal-audit-logs" | ||
| gcp_project_id = "my-gcp-project" | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,207 @@ | ||
| package provider | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
|
|
||
| "github.com/hashicorp/terraform-plugin-framework/datasource" | ||
| "github.com/hashicorp/terraform-plugin-framework/datasource/schema" | ||
| "github.com/hashicorp/terraform-plugin-framework/diag" | ||
| "github.com/hashicorp/terraform-plugin-framework/types" | ||
| "github.com/temporalio/terraform-provider-temporalcloud/internal/client" | ||
| "github.com/temporalio/terraform-provider-temporalcloud/internal/provider/enums" | ||
| internaltypes "github.com/temporalio/terraform-provider-temporalcloud/internal/types" | ||
| accountv1 "go.temporal.io/cloud-sdk/api/account/v1" | ||
| cloudservicev1 "go.temporal.io/cloud-sdk/api/cloudservice/v1" | ||
| ) | ||
|
|
||
| var ( | ||
| _ datasource.DataSource = &accountAuditLogSinkDataSource{} | ||
| _ datasource.DataSourceWithConfigure = &accountAuditLogSinkDataSource{} | ||
| ) | ||
|
|
||
| func NewAccountAuditLogSinkDataSource() datasource.DataSource { | ||
| return &accountAuditLogSinkDataSource{} | ||
| } | ||
|
|
||
| type ( | ||
| accountAuditLogSinkDataSource struct { | ||
| client *client.Client | ||
| } | ||
|
|
||
| accountAuditLogSinkDataModel struct { | ||
| ID types.String `tfsdk:"id"` | ||
| SinkName types.String `tfsdk:"sink_name"` | ||
| Enabled types.Bool `tfsdk:"enabled"` | ||
| Kinesis types.Object `tfsdk:"kinesis"` | ||
| PubSub types.Object `tfsdk:"pubsub"` | ||
| State types.String `tfsdk:"state"` | ||
| } | ||
| ) | ||
|
|
||
| func accountAuditLogSinkDataSourceSchema(idRequired bool) map[string]schema.Attribute { | ||
| idAttribute := schema.StringAttribute{ | ||
| Description: "The unique identifier of the account audit log sink.", | ||
| } | ||
|
|
||
| switch idRequired { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Whats the |
||
| case true: | ||
| idAttribute.Required = true | ||
| case false: | ||
| idAttribute.Computed = true | ||
| } | ||
|
|
||
| return map[string]schema.Attribute{ | ||
| "id": idAttribute, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need this
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll remove it since it is the same |
||
| "sink_name": schema.StringAttribute{ | ||
| Description: "The unique name of the audit log sink.", | ||
| Required: true, | ||
| }, | ||
| "enabled": schema.BoolAttribute{ | ||
| Description: "A flag indicating whether the audit log sink is enabled or not.", | ||
| Computed: true, | ||
| }, | ||
| "kinesis": schema.SingleNestedAttribute{ | ||
| Description: "The Kinesis configuration details when destination_type is Kinesis.", | ||
| Computed: true, | ||
| Attributes: map[string]schema.Attribute{ | ||
| "role_name": schema.StringAttribute{ | ||
| Description: "The IAM role that Temporal Cloud assumes for writing records to the customer's Kinesis stream.", | ||
| Computed: true, | ||
| }, | ||
| "destination_uri": schema.StringAttribute{ | ||
| Description: "The destination URI of the Kinesis stream where Temporal will send data.", | ||
| Computed: true, | ||
| }, | ||
| "region": schema.StringAttribute{ | ||
| Description: "The region of the Kinesis stream.", | ||
| Computed: true, | ||
| }, | ||
| }, | ||
| }, | ||
| "pubsub": schema.SingleNestedAttribute{ | ||
| Description: "The PubSub configuration details when destination_type is PubSub.", | ||
| Computed: true, | ||
| Attributes: map[string]schema.Attribute{ | ||
| "service_account_id": schema.StringAttribute{ | ||
| Description: "The customer service account ID that Temporal Cloud impersonates for writing records to the customer's PubSub topic.", | ||
| Computed: true, | ||
| }, | ||
| "topic_name": schema.StringAttribute{ | ||
| Description: "The destination PubSub topic name for Temporal.", | ||
| Computed: true, | ||
| }, | ||
| "gcp_project_id": schema.StringAttribute{ | ||
| Description: "The GCP project ID of the PubSub topic and service account.", | ||
| Computed: true, | ||
| }, | ||
| }, | ||
| }, | ||
| "state": schema.StringAttribute{ | ||
| Description: "The current state of the audit log sink.", | ||
| Computed: true, | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| func (d *accountAuditLogSinkDataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { | ||
| resp.TypeName = req.ProviderTypeName + "_account_audit_log_sink" | ||
| } | ||
|
|
||
| func (d *accountAuditLogSinkDataSource) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) { | ||
| if req.ProviderData == nil { | ||
| return | ||
| } | ||
|
|
||
| client, ok := req.ProviderData.(*client.Client) | ||
| if !ok { | ||
| resp.Diagnostics.AddError("Unexpected Data Source Configure Type", fmt.Sprintf("Expected *client.Client, got: %T. Please report this issue to the provider developers.", req.ProviderData)) | ||
| return | ||
| } | ||
|
|
||
| d.client = client | ||
| } | ||
|
|
||
| func (d *accountAuditLogSinkDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { | ||
| resp.Schema = schema.Schema{ | ||
| Description: "Fetches details about an account audit log sink.", | ||
| Attributes: accountAuditLogSinkDataSourceSchema(false), | ||
| } | ||
| } | ||
|
|
||
| func (d *accountAuditLogSinkDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { | ||
| var input accountAuditLogSinkDataModel | ||
| resp.Diagnostics.Append(req.Config.Get(ctx, &input)...) | ||
| if resp.Diagnostics.HasError() { | ||
| return | ||
| } | ||
|
|
||
| if len(input.SinkName.ValueString()) == 0 { | ||
| resp.Diagnostics.AddError("invalid account audit log sink sink_name", "account audit log sink sink_name is required") | ||
| return | ||
| } | ||
|
|
||
| auditLogSinkResp, err := d.client.CloudService().GetAccountAuditLogSink(ctx, &cloudservicev1.GetAccountAuditLogSinkRequest{ | ||
| Name: input.SinkName.ValueString(), | ||
| }) | ||
| if err != nil { | ||
| resp.Diagnostics.AddError("Failed to get account audit log sink", err.Error()) | ||
| return | ||
| } | ||
|
|
||
| model, diags := accountAuditLogSinkToAccountAuditLogSinkDataModel(ctx, auditLogSinkResp.GetSink()) | ||
| resp.Diagnostics.Append(diags...) | ||
| if resp.Diagnostics.HasError() { | ||
| return | ||
| } | ||
|
|
||
| diags = resp.State.Set(ctx, model) | ||
| resp.Diagnostics.Append(diags...) | ||
| } | ||
|
|
||
| func accountAuditLogSinkToAccountAuditLogSinkDataModel(ctx context.Context, auditLogSink *accountv1.AuditLogSink) (*accountAuditLogSinkDataModel, diag.Diagnostics) { | ||
| var diags diag.Diagnostics | ||
| stateStr, err := enums.FromResourceState(auditLogSink.State) | ||
| if err != nil { | ||
| diags.AddError("Failed to convert resource state", err.Error()) | ||
| return nil, diags | ||
| } | ||
|
|
||
| model := new(accountAuditLogSinkDataModel) | ||
| model.ID = types.StringValue(auditLogSink.GetName()) | ||
| model.SinkName = types.StringValue(auditLogSink.GetName()) | ||
| model.Enabled = types.BoolValue(auditLogSink.GetSpec().GetEnabled()) | ||
| model.State = types.StringValue(stateStr) | ||
|
|
||
| kinesisObj := types.ObjectNull(internaltypes.KinesisSpecModelAttrTypes) | ||
| if auditLogSink.GetSpec().GetKinesisSink() != nil { | ||
| kinesisSpec := internaltypes.KinesisSpecModel{ | ||
| RoleName: types.StringValue(auditLogSink.GetSpec().GetKinesisSink().GetRoleName()), | ||
| DestinationUri: types.StringValue(auditLogSink.GetSpec().GetKinesisSink().GetDestinationUri()), | ||
| Region: types.StringValue(auditLogSink.GetSpec().GetKinesisSink().GetRegion()), | ||
| } | ||
|
|
||
| kinesisObj, diags = types.ObjectValueFrom(ctx, internaltypes.KinesisSpecModelAttrTypes, kinesisSpec) | ||
| if diags.HasError() { | ||
| return nil, diags | ||
| } | ||
| } | ||
|
|
||
| pubsubObj := types.ObjectNull(internaltypes.PubSubSpecModelAttrTypes) | ||
| if auditLogSink.GetSpec().GetPubSubSink() != nil { | ||
| pubsubSpec := internaltypes.PubSubSpecModel{ | ||
| ServiceAccountId: types.StringValue(auditLogSink.GetSpec().GetPubSubSink().GetServiceAccountId()), | ||
| TopicName: types.StringValue(auditLogSink.GetSpec().GetPubSubSink().GetTopicName()), | ||
| GcpProjectId: types.StringValue(auditLogSink.GetSpec().GetPubSubSink().GetGcpProjectId()), | ||
| } | ||
|
|
||
| pubsubObj, diags = types.ObjectValueFrom(ctx, internaltypes.PubSubSpecModelAttrTypes, pubsubSpec) | ||
| if diags.HasError() { | ||
| return nil, diags | ||
| } | ||
| } | ||
|
|
||
| model.Kinesis = kinesisObj | ||
| model.PubSub = pubsubObj | ||
| return model, diags | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: remove this after API update