-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
74 lines (63 loc) · 1.71 KB
/
main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.47.0"
}
}
required_version = ">= 1.3"
}
# Workspaces allow users to manage different sets of infrastructure using the same configuration by isolating state files.
# Modules, on the other hand, are a logical container for multiple resources that are used together, facilitating reusability and better organization of your code.
# backend "s3" {
# bucket = "tf-state-bucket"
# key = "terraform.tfstate"
# region = "eu-central-1"
# dynamodb_table = "tf_state_lock"
# }
provider "aws" {
region = var.region
profile = var.profile
}
resource "aws_instance" "my_vm" {
ami = var.ami
instance_type = var.instance_type
tags = {
Name = var.instance_name
}
}
resource "aws_dynamodb_table" "basic_dynamodb_table" {
name = "DynamoDB-Terraform"
billing_mode = "PROVISIONED"
read_capacity = 20
write_capacity = 20
# hash_key: This is the partition key for the DynamoDB table. It is used to distribute data across partitions for scalability.
hash_key = "UserId"
# range_key: This is the sort key for the DynamoDB table. It allows for sorting of items with the same partition key.
range_key = "Name"
attribute {
name = "UserId"
type = "S"
}
attribute {
name = "Name"
type = "S"
}
ttl {
attribute_name = "TimeToExist"
enabled = false
}
global_secondary_index {
name = "UserTitleIndex"
hash_key = "UserId"
range_key = "Name"
write_capacity = 10
read_capacity = 10
projection_type = "KEYS_ONLY"
non_key_attributes = [ ]
}
tags = {
Name = "dynamodb-table"
Environment = "dev"
}
}