@@ -16,12 +16,31 @@ terraform {
16
16
required_version = " >= 0.13"
17
17
required_providers {
18
18
aws = {
19
- source = " hashicorp/aws" ,
20
- version = " >= 4.60.0" ,
19
+ source = " hashicorp/aws" ,
20
+ version = " >= 4.60.0" ,
21
+ configuration_aliases = [aws.pricing_calculator]
21
22
}
22
23
}
23
24
}
24
25
26
+ # provider "aws" {
27
+ # alias = "cost_calculator"
28
+ # region = "us-east-1"
29
+ # }
30
+
31
+ locals {
32
+ pricing_os_map = {
33
+ " Red Hat Enterprise Linux" = " RHEL"
34
+ " Ubuntu" = " Linux"
35
+ " Linux/UNIX" = " Linux"
36
+ # "Windows" = "Windows"
37
+ }
38
+ # pricing_arch_map = {
39
+ # "x86_64" = "64-bit"
40
+ # "arm64" = "ARM64"
41
+ # }
42
+ }
43
+
25
44
data "aws_ami" "pvc_base" {
26
45
filter {
27
46
name = " image-id"
@@ -55,3 +74,51 @@ resource "aws_instance" "pvc_base" {
55
74
Name = var.quantity == 0 ? var.name : format (" %s-%02d" , var. name , count. index + var. offset + 1 )
56
75
})
57
76
}
77
+
78
+ data "aws_pricing_product" "pvc_base" {
79
+ for_each = { for idx , instance in aws_instance . pvc_base : idx => instance }
80
+
81
+ provider = aws. pricing_calculator
82
+
83
+ service_code = " AmazonEC2"
84
+
85
+ filters {
86
+ field = " instanceType"
87
+ value = each. value . instance_type
88
+ }
89
+
90
+ filters {
91
+ field = " regionCode"
92
+ value = each. value . region
93
+ }
94
+
95
+ filters {
96
+ field = " operatingSystem"
97
+ value = local. pricing_os_map [data . aws_ami . pvc_base . platform_details ]
98
+ }
99
+
100
+ # filters {
101
+ # field = "processorArchitecture"
102
+ # value = local.pricing_arch_map[data.aws_ami.pvc_base.architecture]
103
+ # }
104
+
105
+ filters {
106
+ field = " marketoption"
107
+ value = " OnDemand" # TODO Review marketoption as a variable to the module
108
+ }
109
+
110
+ filters {
111
+ field = " preInstalledSw"
112
+ value = " NA"
113
+ }
114
+
115
+ filters {
116
+ field = " tenancy"
117
+ value = " Shared"
118
+ }
119
+
120
+ filters {
121
+ field = " capacitystatus"
122
+ value = " Used"
123
+ }
124
+ }
0 commit comments