Skip to content

Commit

Permalink
Add table aws_timestreamwrite_database and aws_timestreamwrite_table C…
Browse files Browse the repository at this point in the history
…loses #2263 #2262 (#2269)
  • Loading branch information
ParthaI authored Aug 20, 2024
1 parent 166a919 commit 66c95e1
Show file tree
Hide file tree
Showing 26 changed files with 965 additions and 3 deletions.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{
"arn": "{{ output.resource_aka.value }}",
"database_name": "{{ resourceName }}"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
select arn, database_name
from aws.aws_timestreamwrite_database
where database_name = '{{ resourceName }}';
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{
"arn": "{{ output.resource_aka.value }}",
"database_name": "{{ resourceName }}"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
select arn, database_name
from aws.aws_timestreamwrite_database
where akas::text = '["{{ output.resource_aka.value }}"]';
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{
"akas": ["{{ output.resource_aka.value }}"],
"title": "{{ resourceName }}"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
select akas, title
from aws.aws_timestreamwrite_database
where akas::text = '["{{ output.resource_aka.value }}"]';
1 change: 1 addition & 0 deletions aws-test/tests/aws_timestreamwrite_database/variables.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
102 changes: 102 additions & 0 deletions aws-test/tests/aws_timestreamwrite_database/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@

variable "resource_name" {
type = string
default = "turbot-test-20200125-create-update"
description = "Name of the resource used throughout the test."
}

variable "aws_profile" {
type = string
default = "default"
description = "AWS credentials profile used for the test. Default is to use the default profile."
}

variable "aws_region" {
type = string
default = "us-east-1"
description = "AWS region used for the test. Does not work with default region in config, so must be defined here."
}

variable "aws_region_alternate" {
type = string
default = "us-east-2"
description = "Alternate AWS region used for tests that require two regions (e.g. DynamoDB global tables)."
}

provider "aws" {
profile = var.aws_profile
region = var.aws_region
}

provider "aws" {
alias = "alternate"
profile = var.aws_profile
region = var.aws_region_alternate
}

data "aws_partition" "current" {}
data "aws_caller_identity" "current" {}
data "aws_region" "primary" {}
data "aws_region" "alternate" {
provider = aws.alternate
}

data "null_data_source" "resource" {
inputs = {
scope = "arn:${data.aws_partition.current.partition}:::${data.aws_caller_identity.current.account_id}"
}
}

resource "aws_kms_key" "named_test_resource" {
description = "An example symmetric encryption KMS key"
enable_key_rotation = true
deletion_window_in_days = 20
}

resource "aws_kms_key_policy" "named_test_resource" {
key_id = aws_kms_key.named_test_resource.id
policy = jsonencode({
Version = "2012-10-17"
Id = "key-default-1"
Statement = [
{
Sid = "Enable IAM User Permissions"
Effect = "Allow"
Principal = {
AWS = "arn:aws:iam::${data.aws_caller_identity.current.account_id}:root"
},
Action = "kms:*"
Resource = "*"
}
]
})
}

resource "aws_timestreamwrite_database" "named_test_resource" {
database_name = var.resource_name
kms_key_id = aws_kms_key.named_test_resource.arn

tags = {
Name = var.resource_name
}
}

output "resource_aka" {
value = aws_timestreamwrite_database.named_test_resource.arn
}

output "account_id" {
value = data.aws_caller_identity.current.account_id
}

output "region_name" {
value = data.aws_region.primary.name
}

output "aws_partition" {
value = data.aws_partition.current.partition
}

output "resource_name" {
value = var.resource_name
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{
"arn": "{{ output.resource_aka.value }}",
"database_name": "{{ resourceName }}",
"table_name": "{{ resourceName }}"
}
]
3 changes: 3 additions & 0 deletions aws-test/tests/aws_timestreamwrite_table/test-get-query.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
select table_name, arn, database_name
from aws.aws_timestreamwrite_table
where table_name = '{{ resourceName }}' and database_name = '{{ resourceName }}';
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{
"arn": "{{ output.resource_aka.value }}",
"table_name": "{{ resourceName }}"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
select arn, table_name
from aws.aws_timestreamwrite_table
where akas::text = '["{{ output.resource_aka.value }}"]';
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{
"akas": ["{{ output.resource_aka.value }}"],
"title": "{{ resourceName }}"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
select akas, title
from aws.aws_timestreamwrite_table
where akas::text = '["{{ output.resource_aka.value }}"]';
1 change: 1 addition & 0 deletions aws-test/tests/aws_timestreamwrite_table/variables.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
116 changes: 116 additions & 0 deletions aws-test/tests/aws_timestreamwrite_table/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@

variable "resource_name" {
type = string
default = "turbot-test-20200125-create-update"
description = "Name of the resource used throughout the test."
}

variable "aws_profile" {
type = string
default = "default"
description = "AWS credentials profile used for the test. Default is to use the default profile."
}

variable "aws_region" {
type = string
default = "us-east-1"
description = "AWS region used for the test. Does not work with default region in config, so must be defined here."
}

variable "aws_region_alternate" {
type = string
default = "us-east-2"
description = "Alternate AWS region used for tests that require two regions (e.g. DynamoDB global tables)."
}

provider "aws" {
profile = var.aws_profile
region = var.aws_region
}

provider "aws" {
alias = "alternate"
profile = var.aws_profile
region = var.aws_region_alternate
}

data "aws_partition" "current" {}
data "aws_caller_identity" "current" {}
data "aws_region" "primary" {}
data "aws_region" "alternate" {
provider = aws.alternate
}

data "null_data_source" "resource" {
inputs = {
scope = "arn:${data.aws_partition.current.partition}:::${data.aws_caller_identity.current.account_id}"
}
}

resource "aws_kms_key" "named_test_resource" {
description = "An example symmetric encryption KMS key"
enable_key_rotation = true
deletion_window_in_days = 20
}

resource "aws_kms_key_policy" "named_test_resource" {
key_id = aws_kms_key.named_test_resource.id
policy = jsonencode({
Version = "2012-10-17"
Id = "key-default-1"
Statement = [
{
Sid = "Enable IAM User Permissions"
Effect = "Allow"
Principal = {
AWS = "arn:aws:iam::${data.aws_caller_identity.current.account_id}:root"
},
Action = "kms:*"
Resource = "*"
}
]
})
}

resource "aws_timestreamwrite_database" "named_test_resource" {
database_name = var.resource_name
kms_key_id = aws_kms_key.named_test_resource.arn

tags = {
Name = var.resource_name
}
}

resource "aws_timestreamwrite_table" "named_test_resource" {
database_name = aws_timestreamwrite_database.named_test_resource.database_name
table_name = var.resource_name

retention_properties {
magnetic_store_retention_period_in_days = 30
memory_store_retention_period_in_hours = 8
}

tags = {
Name = var.resource_name
}
}

output "resource_aka" {
value = aws_timestreamwrite_table.named_test_resource.arn
}

output "account_id" {
value = data.aws_caller_identity.current.account_id
}

output "region_name" {
value = data.aws_region.primary.name
}

output "aws_partition" {
value = data.aws_partition.current.partition
}

output "resource_name" {
value = var.resource_name
}
2 changes: 2 additions & 0 deletions aws/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,8 @@ func Plugin(ctx context.Context) *plugin.Plugin {
"aws_ssoadmin_permission_set": tableAwsSsoAdminPermissionSet(ctx),
"aws_sts_caller_identity": tableAwsSTSCallerIdentity(ctx),
"aws_tagging_resource": tableAwsTaggingResource(ctx),
"aws_timestreamwrite_database": tableAwsTimestreamwriteDatabase(ctx),
"aws_timestreamwrite_table": tableAwsTimestreamwriteTable(ctx),
"aws_transfer_server": tableAwsTransferServer(ctx),
"aws_transfer_user": tableAwsTransferUser(ctx),
"aws_trusted_advisor_check_summary": tableAwsTrustedAdvisorCheckSummary(ctx),
Expand Down
13 changes: 13 additions & 0 deletions aws/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ import (
"github.com/aws/aws-sdk-go-v2/service/ssoadmin"
"github.com/aws/aws-sdk-go-v2/service/sts"
"github.com/aws/aws-sdk-go-v2/service/support"
"github.com/aws/aws-sdk-go-v2/service/timestreamwrite"
"github.com/aws/aws-sdk-go-v2/service/transfer"
"github.com/aws/aws-sdk-go-v2/service/waf"
"github.com/aws/aws-sdk-go-v2/service/wafregional"
Expand Down Expand Up @@ -202,6 +203,7 @@ import (
ssmEndpoint "github.com/aws/aws-sdk-go/service/ssm"
ssmIncidentsEndpoint "github.com/aws/aws-sdk-go/service/ssmincidents"
ssoEndpoint "github.com/aws/aws-sdk-go/service/sso"
timestreamwriteEndpoint "github.com/aws/aws-sdk-go/service/timestreamwrite"
transferEndpoint "github.com/aws/aws-sdk-go/service/transfer"
wafregionalEndpoint "github.com/aws/aws-sdk-go/service/wafregional"
wafv2Endpoint "github.com/aws/aws-sdk-go/service/wafv2"
Expand Down Expand Up @@ -1564,6 +1566,17 @@ func TransferClient(ctx context.Context, d *plugin.QueryData) (*transfer.Client,
return transfer.NewFromConfig(*cfg), nil
}

func TimestreamwriteClient(ctx context.Context, d *plugin.QueryData) (*timestreamwrite.Client, error) {
cfg, err := getClientForQuerySupportedRegion(ctx, d, timestreamwriteEndpoint.EndpointsID)
if err != nil {
return nil, err
}
if cfg == nil {
return nil, nil
}
return timestreamwrite.NewFromConfig(*cfg), nil
}

func WAFClient(ctx context.Context, d *plugin.QueryData) (*waf.Client, error) {
// WAF Classic a global service with a single DNS endpoint
// (waf.amazonaws.com).
Expand Down
Loading

0 comments on commit 66c95e1

Please sign in to comment.