# string, number, bool.
# list, set, map
# object, tuple
# any, null
# enter value: {a:"1",b:"2",c:3,d:null,f:["1"],h:[],j:[1,2],i:[],v:{},x:["18",12,true],z:{age:18,name:"simple"}}
variable "an_object" {
type = object({
a = string
b = string
c = number
d = any
f = list(number)
h = list(any) # 所有的value需要是统一类型
j = set(string)
i = set(any)
v = map(number) # map的key必须是string
z = object({ age = number, name = string })
x = tuple([string, number, bool]) # = list(["18", "true", "john"])
o = optional(string)
t = optional(number, 216)
})
default = {
a = "value"
b = "value"
c = 1
d = null
f = [1]
h = []
i = []
j = ["value"]
o = "value"
t = 1
v = {
"key" = 1
}
x = ["value", 1, false]
z = {
age = 1
name = "value"
}
}
}
variable "image_id" {
type = string
default = "ami-xxxx"
description = "an extra id" # 可以在输入变量中定义一个描述,简单地向调用者描述该变量的意义和用法
validation {
# 不符合条件则显示error message
condition = can(regex("^ami-", var.image_id))
# condition = length(var.image_id) > 4 && substr(var.image_id,0,4)=="ami-"
error_message = "The image_id value must be a valid AMI id, starting with \"ami-\"."
}
}
variable "availability_zone_names" {
type = list(string)
default = ["us-west-1a"]
}
variable "docker_ports" {
type = list(object({
internal = number
external = number
protocol = string
}))
default = [{
external = 8300
internal = 8888
protocol = "tcp"
}]
}
# {name:"zx",address:"123 12sa"}
variable "user_information" {
type = object({
name = string
address = string
})
default = {
address = "xxxxx"
name = "xxxx"
}
sensitive = true
}
# resource "resource_name" "a" {
# name = var.user_information.name
# address = var.user_information.address
# nested_block {
# At least one attribute in this block is (or was) sensitive,
# so its contents will not be displayed.
# }
# }
terraform {
required_providers {
hashicups = {
version = "~> 0.3.1"
source = "hashicorp.com/edu/hashicups"
}
}
}
provider "hashicups" {
username = "education"
password = "test123"
}
# resource "hashicups_order" "edu" {
# items {
# coffee {
# id = 3
# }
# quantity = 3
# }
# items {
# coffee {
# id = 2
# }
# quantity = 4
# }
# }
# output "edu_order" {
# value = hashicups_order.edu
# }