-
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
Open
david049
wants to merge
9
commits into
main
Choose a base branch
from
dliu/auditlogsinktf
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,333
−2
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
cae6fab
Audit log sink management terraform
david049 72a6ece
go generate
david049 5c06226
run tests sequentially
david049 2955c95
add datasource
david049 e221f42
add datasource
david049 8f57327
fix tests
david049 7d01344
fix cleanup
david049 06cf5cb
dont allow multisinks
david049 a98f32d
fix test
david049 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,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. |
33 changes: 33 additions & 0 deletions
33
examples/resources/temporalcloud_account_audit_log_sink/resource.tf
This file contains hidden or 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,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" | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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,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 { | ||
| case true: | ||
| idAttribute.Required = true | ||
| case false: | ||
| idAttribute.Computed = true | ||
| } | ||
|
|
||
| return map[string]schema.Attribute{ | ||
| "id": idAttribute, | ||
| "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 | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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