Terraform 扩展

Terraform 扩展

Terraform Meta-Arguments 元参数

  • count 创建相似的资源
  • for_each 创建相似的资源
  • depends_on 定义资源或者模块的依赖
  • provider 定义provider选项
  • lifecycle 资源的生命周期行为
参数使用范围备注
countresource module适用于创建多个相似的资源,使用索引count.index作为参数引用。如果资源存在区别,建议使用 for_each
for_eachresource modulefor_each 它只能用于set(string) 或者map(string)
depends_onresource module处理 Terraform 无法自动推断的资源或模块之间的依赖关系
providerresource module在资源中定义供应商,通常是 . ,模块中,如果子模块未定义providers则继承父模块
lifecycleresource module生命周期行为定义

Count 创建资源副本

  • count = num数值类型, 可以通过 length() 计算数量;
  • count.index 索引来遍历列表

示例: 创建三条 DNS 记录

  • devops1.evescn.com
  • devops2.evescn.com
  • devops3.evescn.com
Terraform 配置
## count.tflocals {zone = "evescn.com"records = ["devops1","devops2","devops3"]
}resource "alicloud_dns_record" "record" {count = length(local.records)name        = local.zonehost_record = local.records[count.index]type        = "A"value       = "192.168.1.1"
}
## count.tflocals {zone = "evescn.com"records = ["devops1","devops2","devops3"]
}resource "alicloud_dns_record" "record" {count = length(local.records)name        = local.zonehost_record = local.records[count.index]type        = "A"value       = "192.168.1.1"
}
创建 DNS 解析
evescn@evescndeMacBook-Pro count % terraform initInitializing the backend...Initializing provider plugins...
- Finding hashicorp/alicloud versions matching "1.164.0"...
- Installing hashicorp/alicloud v1.164.0...
- Installed hashicorp/alicloud v1.164.0 (signed by HashiCorp)Terraform has been successfully initialized!evescn@evescndeMacBook-Pro count % terraform fmt 
count.tfevescn@evescndeMacBook-Pro count % terraform validate
Success! The configuration is valid.evescn@evescndeMacBook-Pro count % terraform plan    Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:+ createTerraform will perform the following actions:# alicloud_dns_record.record[0] will be created+ resource "alicloud_dns_record" "record" {+ host_record = "devops1"+ id          = (known after apply)+ locked      = (known after apply)+ name        = "evescn.com"+ routing     = "default"+ status      = (known after apply)+ ttl         = 600+ type        = "A"+ value       = "192.168.1.1"}# alicloud_dns_record.record[1] will be created+ resource "alicloud_dns_record" "record" {+ host_record = "devops2"+ id          = (known after apply)+ locked      = (known after apply)+ name        = "evescn.com"+ routing     = "default"+ status      = (known after apply)+ ttl         = 600+ type        = "A"+ value       = "192.168.1.1"}# alicloud_dns_record.record[2] will be created+ resource "alicloud_dns_record" "record" {+ host_record = "devops3"+ id          = (known after apply)+ locked      = (known after apply)+ name        = "evescn.com"+ routing     = "default"+ status      = (known after apply)+ ttl         = 600+ type        = "A"+ value       = "192.168.1.1"}Plan: 3 to add, 0 to change, 0 to destroy.evescn@evescndeMacBook-Pro count % terraform apply --auto-approveTerraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:+ createTerraform will perform the following actions:# alicloud_dns_record.record[0] will be created+ resource "alicloud_dns_record" "record" {+ host_record = "devops1"+ id          = (known after apply)+ locked      = (known after apply)+ name        = "evescn.com"+ routing     = "default"+ status      = (known after apply)+ ttl         = 600+ type        = "A"+ value       = "192.168.1.1"}# alicloud_dns_record.record[1] will be created+ resource "alicloud_dns_record" "record" {+ host_record = "devops2"+ id          = (known after apply)+ locked      = (known after apply)+ name        = "evescn.com"+ routing     = "default"+ status      = (known after apply)+ ttl         = 600+ type        = "A"+ value       = "192.168.1.1"}# alicloud_dns_record.record[2] will be created+ resource "alicloud_dns_record" "record" {+ host_record = "devops3"+ id          = (known after apply)+ locked      = (known after apply)+ name        = "evescn.com"+ routing     = "default"+ status      = (known after apply)+ ttl         = 600+ type        = "A"+ value       = "192.168.1.1"}Plan: 3 to add, 0 to change, 0 to destroy.
alicloud_dns_record.record[1]: Creating...
alicloud_dns_record.record[0]: Creating...
alicloud_dns_record.record[2]: Creating...
alicloud_dns_record.record[0]: Creation complete after 1s [id=843289465596745728]
alicloud_dns_record.record[1]: Creation complete after 1s [id=843289465605112832]
alicloud_dns_record.record[2]: Creation complete after 1s [id=843289465619789824]Apply complete! Resources: 3 added, 0 changed, 0 destroyed.

删除 devops2 记录,会成功运行?

locals {zone    = "evescn.com"# records = ["devops1", "devops2", "devops3"]records = ["devops1", "devops3"]
}resource "alicloud_dns_record" "record" {count       = length(local.records)name        = local.zonehost_record = local.records[count.index]type        = "A"value       = "192.168.1.1"
}

 执行部署

evescn@evescndeMacBook-Pro count % terraform plan                
alicloud_dns_record.record[0]: Refreshing state... [id=843289465596745728]
alicloud_dns_record.record[2]: Refreshing state... [id=843289465619789824]
alicloud_dns_record.record[1]: Refreshing state... [id=843289465605112832]Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:~ update in-place- destroyTerraform will perform the following actions:# alicloud_dns_record.record[1] will be updated in-place~ resource "alicloud_dns_record" "record" {~ host_record = "devops2" -> "devops3"id          = "843289465605112832"name        = "evescn.com"# (7 unchanged attributes hidden)}# alicloud_dns_record.record[2] will be destroyed# (because index [2] is out of range for count)- resource "alicloud_dns_record" "record" {- host_record = "devops3" -> null- id          = "843289465619789824" -> null- locked      = false -> null- name        = "evescn.com" -> null- priority    = 0 -> null- routing     = "default" -> null- status      = "ENABLE" -> null- ttl         = 600 -> null- type        = "A" -> null- value       = "192.168.1.1" -> null}Plan: 0 to add, 1 to change, 1 to destroy.evescn@evescndeMacBook-Pro count % terraform apply --auto-approve
alicloud_dns_record.record[1]: Refreshing state... [id=843289465605112832]
alicloud_dns_record.record[0]: Refreshing state... [id=843289465596745728]
alicloud_dns_record.record[2]: Refreshing state... [id=843289465619789824]Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:~ update in-place- destroyTerraform will perform the following actions:# alicloud_dns_record.record[1] will be updated in-place~ resource "alicloud_dns_record" "record" {~ host_record = "devops2" -> "devops3"id          = "843289465605112832"name        = "evescn.com"# (7 unchanged attributes hidden)}# alicloud_dns_record.record[2] will be destroyed# (because index [2] is out of range for count)- resource "alicloud_dns_record" "record" {- host_record = "devops3" -> null- id          = "843289465619789824" -> null- locked      = false -> null- name        = "evescn.com" -> null- priority    = 0 -> null- routing     = "default" -> null- status      = "ENABLE" -> null- ttl         = 600 -> null- type        = "A" -> null- value       = "192.168.1.1" -> null}Plan: 0 to add, 1 to change, 1 to destroy.
alicloud_dns_record.record[2]: Destroying... [id=843289465619789824]
alicloud_dns_record.record[1]: Modifying... [id=843289465605112832]
alicloud_dns_record.record[2]: Destruction complete after 1s
╷
│ Error: [ERROR] terraform-provider-alicloud/alicloud/resource_alicloud_dns_record.go:138: Resource 843289465605112832 UpdateDomainRecord Failed!!! [SDK alibaba-cloud-sdk-go ERROR]:
│ SDK.ServerError
│ ErrorCode: DomainRecordDuplicate
│ Recommend: https://api.aliyun.com/troubleshoot?q=DomainRecordDuplicate&product=Alidns
│ RequestId: 17F3D4A1-6E02-5F4E-AEA0-C04C583B9A9E
│ Message: The DNS record already exists.
│ RespHeaders: map[Access-Control-Allow-Origin:[*] Access-Control-Expose-Headers:[*] Connection:[keep-alive] Content-Length:[246] Content-Type:[application/json;charset=utf-8] Date:[Wed, 02 Aug 2023 03:39:11 GMT] Keep-Alive:[timeout=25] X-Acs-Request-Id:[17F3D4A1-6E02-5F4E-AEA0-C04C583B9A9E] X-Acs-Trace-Id:[df248ca1dac580f3e90c12bf599c4e1a]]
│ 
│   with alicloud_dns_record.record[1],
│   on count.tf line 7, in resource "alicloud_dns_record" "record":
│    7: resource "alicloud_dns_record" "record" {
│ 

从 terraform 看,程序执行的操作步骤如下:

  • update: server2 > server3
  • destroy: server3

但是在执行过程中 count = length(local.records) 命令获取不了 [2] 这个下标程序出错,看看 DNS 解析记录

for_each 创建资源副本 

  • for_each = set(string) map(string)

  • for_each 只能用于 set(string) 或者 map(string),可以使用 toset 转换 list 为 set 数据

  • for_each = set(string)

    • each.key = each.value
  • for_each = map(string)

    • each.key = key
    • each.value = value

示例: 创建三条 DNS 记录

  • devops1.evescn.com
  • devops2.evescn.com
  • devops3.evescn.com
Terraform 配置
## version.tfterraform {required_version = ">=1.1.9"required_providers {alicloud = {source  = "hashicorp/alicloud"version = "1.164.0"}}
}# Configure the Alicloud Provider
provider "alicloud" {access_key = "xxxxxxxx"secret_key = "xxxxxxxx"
}
## for_each.tflocals {zone = "evescn.com"# records = ["devops1", "devops2", "devops3"]records = ["devops1", "devops3"]
}resource "alicloud_dns_record" "eachrecord" {for_each    = toset(local.records)name        = local.zonehost_record = each.valuetype        = "A"value       = "192.168.1.1"
}
创建 DNS 解析
evescn@evescndeMacBook-Pro for_each % terraform initInitializing the backend...Initializing provider plugins...
- Finding hashicorp/alicloud versions matching "1.164.0"...
- Installing hashicorp/alicloud v1.164.0...
- Installed hashicorp/alicloud v1.164.0 (signed by HashiCorp)Terraform has been successfully initialized!evescn@evescndeMacBook-Pro for_each % terraform fmt 
for_each.tfevescn@evescndeMacBook-Pro for_each % terraform validate
Success! The configuration is valid.evescn@evescndeMacBook-Pro for_each % terraform apply   Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:+ createTerraform will perform the following actions:# alicloud_dns_record.eachrecord["devops1"] will be created+ resource "alicloud_dns_record" "eachrecord" {+ host_record = "devops1"+ id          = (known after apply)+ locked      = (known after apply)+ name        = "evescn.com"+ routing     = "default"+ status      = (known after apply)+ ttl         = 600+ type        = "A"+ value       = "192.168.1.1"}# alicloud_dns_record.eachrecord["devops2"] will be created+ resource "alicloud_dns_record" "eachrecord" {+ host_record = "devops2"+ id          = (known after apply)+ locked      = (known after apply)+ name        = "evescn.com"+ routing     = "default"+ status      = (known after apply)+ ttl         = 600+ type        = "A"+ value       = "192.168.1.1"}# alicloud_dns_record.eachrecord["devops3"] will be created+ resource "alicloud_dns_record" "eachrecord" {+ host_record = "devops3"+ id          = (known after apply)+ locked      = (known after apply)+ name        = "evescn.com"+ routing     = "default"+ status      = (known after apply)+ ttl         = 600+ type        = "A"+ value       = "192.168.1.1"}Plan: 3 to add, 0 to change, 0 to destroy.Do you want to perform these actions?Terraform will perform the actions described above.Only 'yes' will be accepted to approve.Enter a value: yesalicloud_dns_record.eachrecord["devops1"]: Creating...
alicloud_dns_record.eachrecord["devops2"]: Creating...
alicloud_dns_record.eachrecord["devops3"]: Creating...
alicloud_dns_record.eachrecord["devops2"]: Creation complete after 0s [id=843317481926367232]
alicloud_dns_record.eachrecord["devops3"]: Creation complete after 0s [id=843317481928446976]
alicloud_dns_record.eachrecord["devops1"]: Creation complete after 0s [id=843317481953598464]Apply complete! Resources: 3 added, 0 changed, 0 destroyed.

 删除 devops2 记录,重新执行

## for_each.tflocals {zone = "evescn.com"# records = ["devops1", "devops2", "devops3"]records = ["devops1", "devops3"]
}resource "alicloud_dns_record" "eachrecord" {for_each    = toset(local.records)name        = local.zonehost_record = each.valuetype        = "A"value       = "192.168.1.1"
}

 执行部署

evescn@evescndeMacBook-Pro for_each % terraform apply
alicloud_dns_record.eachrecord["devops2"]: Refreshing state... [id=843317481926367232]
alicloud_dns_record.eachrecord["devops3"]: Refreshing state... [id=843317481928446976]
alicloud_dns_record.eachrecord["devops1"]: Refreshing state... [id=843317481953598464]Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:- destroyTerraform will perform the following actions:# alicloud_dns_record.eachrecord["devops2"] will be destroyed# (because key ["devops2"] is not in for_each map)- resource "alicloud_dns_record" "eachrecord" {- host_record = "devops2" -> null- id          = "843317481926367232" -> null- locked      = false -> null- name        = "evescn.com" -> null- priority    = 0 -> null- routing     = "default" -> null- status      = "ENABLE" -> null- ttl         = 600 -> null- type        = "A" -> null- value       = "192.168.1.1" -> null}Plan: 0 to add, 0 to change, 1 to destroy.Do you want to perform these actions?Terraform will perform the actions described above.Only 'yes' will be accepted to approve.Enter a value: yesalicloud_dns_record.eachrecord["devops2"]: Destroying... [id=843317481926367232]
alicloud_dns_record.eachrecord["devops2"]: Destruction complete after 0sApply complete! Resources: 0 added, 0 changed, 1 destroyed.

dynamic 动态的内联块

  • dynamic : 定义动态资源块,后面是 label, 默认为生成的语句块名称;
  • for_each : 要进行迭代循环的对象(map、list、set);
  • iterator : 临时的变量名称,如果未定义则使用 label 即 ports ;
  • content : 要生成的语句块的内容部分;
dynamic "label" {# 支持 map list set 等数据for_each = map | list | set iterator = iterator_namecontent {key = iterator_name.value}
}
dynamic "ports" {for_each = local.jenkins_portscontent {internal = ports.value.internalexternal = ports.value.externalip       = "0.0.0.0"protocol = "tcp"}
}

Docker 中的 ports{}

resource "docker_container" "jenkins" {ports {internal = 8080external = 8080ip       = "0.0.0.0"protocol = "tcp"}ports {internal = 50000external = 50000ip       = "0.0.0.0"protocol = "tcp"}
}

定义一个local变量;使用dynamic动态内联块
for_each遍历资源;ports.value引用遍历的资源

locals {jenkins_ports = [{internal = 8080external = 8080},{internal = 50000external = 50000}]
}resource "docker_container" "jenkins" {// 使用dynamic来实现动态dynamic "ports" {for_each = local.jenkins_portscontent {internal = ports.value.internalexternal = ports.value.externalip       = "0.0.0.0"protocol = "tcp"}}

depends_on 依赖关系

处理 资源或模块之间的依赖关系。

resource "docker_image" "jenkins" {name         = "jenkins/jenkins:2.332.2-centos7-jdk8"force_remove = falsekeep_locally = true
}resource "docker_container" "jenkins" {image      = docker_image.jenkins.namename       = "jenkins-demo"# 依赖 docker_image 资源depends_on = [docker_image.jenkins]
}

provider 自定义供应商

resource 覆盖资源中的 provider

例如:分别在 cn-beijing 和 cn-shanghai 区域分别创建1个实例。

provider "alicloud" {alias  = "north"region = "cn-beijing"access_key = "AKIR"secret_key = "MJy5JXmZn"
}provider "alicloud" {region     = "cn-shanghai"access_key = "AK5R"secret_key = "MJy5JX6HIqmZn"
}resource "alicloud_instance" "ecs_demo_north" {provider      = alicloud.north...
}resource "alicloud_instance" "ecs_demo" {...
}

module 默认子模块继承根模块的provider;

  • provider = map()
  • key: provider名称
  • value: <provider>.<alias>
provider "alicloud" {alias  = "north"region = "cn-beijing"
}provider "alicloud" {region = "cn-shanghai"
}module "example" { source = "./example"# module 中的 provider 配置providers = { alicloud = alicloud.north}
}

lifecycle 生命周期

标记资源不被删除或者销毁前创建新的资源;

lifecycle {xxx
}
  • create_before_destroy 先创建新的对象,再销毁旧的对象;
  • prevent_destroy 防止资源被销毁;
  • ignore_changes 忽略资源的差异;
  • replace_triggered_by 当指定的资源修改后替换当前资源;
  • precondition postcondition 条件检查
lifecycle {create_before_destroy = true# prevent_destroy = trueignore_changes = [tags, instance_name]replace_triggered_by = [alicloud_vpc.vpc.vpc_name]
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/805391.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

1999-2022年各省研究与试验发展人员全时当量数据/省研发人员全时当量数据/(RD)人员全时当量(无缺失)

1999-2022年各省研究与试验发展人员全时当量数据/省研发人员全时当量数据/(R&D)人员全时当量&#xff08;无缺失&#xff09; 1、时间&#xff1a;1999-2022年 2、来源&#xff1a;科技年鉴 3、指标&#xff1a;研究与试验发展人员全时当量/研发人员全时当量 4、范围&a…

软考-系统集成项目管理中级-新一代信息技术

本章历年考题分值统计 本章重点常考知识点汇总清单(掌握部分可直接理解记忆) 本章历年考题及答案解析 32、2019 年上半年第 23 题 云计算通过网络提供可动态伸缩的廉价计算能力&#xff0c;(23)不属于云计算的特点。 A.虚拟化 B.高可扩展性 C.按需服务 D.优化本地存储 【参考…

Docker快速上手及常用命令速查

Docker快速上手 安装 在ubuntu上安装docker: sudo apt-get install docker docker -v #查看版本在centos7上安装docker&#xff1a;(docker在YUM源的Extras仓库中) yum install docker systemctl start dockerdocker常用命令速查 #查看docker信息 docker info #查看本地镜…

hive 数据库表常用操作及相关函数讲解

创建数据库并指定hdfs存储位置 create database myhive2 location ‘/myhive2’; 使用location关键字&#xff0c;可以指定数据库在HDFS的存储路径。 Hive的库在HDFS上就是一个以.db结尾的目录 默认存储在&#xff1a; /user/hive/warehouse内 当你为Hive表指定一个LOCATION时…

NumPy入门(一)

NumPy入门(一) 工具: jupyter notebook jupyter notebook 功能 : 数据处理 &#xff08;python 处理数据功能&#xff09; coding文字型的描述 富文本 word可视化支持 官网: https://jupyter.org/ 启动命令 jupyter notebook 1.1 numpy简介 Python的拓展库, 提供数据对象 nda…

【数据下载】SODA数据更新至2022并教学下载

【数据下载】SODA数据更新至2022并教学下载 我为什么那么喜欢使用SODA数据&#xff1f; 就是三维网格化的数据&#xff0c;好用。 但是需要高分辨率还是需要找别的。 以前分享过SODA数据下载&#xff0c;但上次版本过于凌乱。因此重新借助更新再分享一次&#xff0c;不为过。…

人脸识别业务(基于腾讯人脸识别接口)

使用腾讯云人脸识别接口&#xff0c;基于优图祖母模型。 一、准备工作 人脸识别账号 申请腾讯云服务器账号&#xff0c;生成自己的秘钥。记录秘钥和秘钥ID。 创建人员库 记下人员库id 在配置文件application.yml中添加配置。 plateocr:SecretId: 秘钥IDSecretKey: 秘钥ser…

Day1 省选衔接题 思路总结

Day1 省选题 思路 取数 可反悔的贪心。我们开一个双向链表记录此时每个数的前/后一个数是什么。一个简单但不一定正确的贪心策略即为&#xff1a;每次都取走当前值最大的且可取的数&#xff0c;并更新列表。考虑如何使这个贪心思路正确。 设 p r e x pre_x prex​ 表示 x x …

Path Aggregation Network for Instance Segmentation

PANet 摘要1. 引言2.相关工作3.框架 PANet 最初是为 proposal-based 实例分割框架提出来的&#xff0c;mask 是实例的掩码&#xff0c;覆盖了物体包含的所有像素&#xff0c;proposal 在目标检测领域是可能存在目标的区域。在实例分割中&#xff0c;首先利用RPN(Region Proposa…

练习题(2024/4/10)

1. 删除有序数组中的重复项 给你一个 非严格递增排列 的数组 nums &#xff0c;请你 原地 删除重复出现的元素&#xff0c;使每个元素 只出现一次 &#xff0c;返回删除后数组的新长度。元素的 相对顺序 应该保持 一致 。然后返回 nums 中唯一元素的个数。 考虑 nums 的唯一元…

2022年蓝桥杯省赛——直线

目录 题目链接&#xff1a;11.直线 - 蓝桥云课 (lanqiao.cn) 题目描述 思路 代码思路如下 代码实现 坑来喽~~ 导致这个BUG的原因&#xff01;&#xff01;&#xff01; 总结 整体的 两种b的情况对比数据 题目链接&#xff1a;11.直线 - 蓝桥云课 (lanqiao.cn) 题目描…

JVM面试整理--对象的创建和堆

文章目录 对象的创建过程是怎样的?对象在内存中的结构是怎样的&#xff08;专业的叫法&#xff1a;对象的内存布局&#xff09;对象在内存分配时使用的哪种方式&#xff08;有的地方也称为&#xff1a;分配算法&#xff09;知道什么是“指针碰撞”吗&#xff1f;知道什么是“空…

LeetCode 80—— 删除有序数组中的重复项 II

阅读目录 1. 题目2. 解题思路3. 代码实现 1. 题目 2. 解题思路 让 index指向删除重复元素后数组的新长度&#xff1b;让 st_idx 指向重复元素的起始位置&#xff0c;而 i 指向重复元素的结束位置&#xff0c;duplicate_num代表重复元素的个数&#xff1b;一段重复元素结束后&am…

php校园活动报名系统vue+mysql

开发语言&#xff1a;php 后端框架&#xff1a;Thinkphp/Laravel 前端框架&#xff1a;vue.js 服务器&#xff1a;apache 数据库&#xff1a;mysql 运行环境:phpstudy/wamp/xammp等本选题则旨在通过标签分类管理等方式&#xff0c;管理员&#xff1b;首页、个人中心、学生管理、…

Redis 缓存穿透、缓存击穿、缓存雪崩区别和解决方案

缓存穿透 什么是缓存穿透&#xff1f; 缓存穿透说简单点就是大量请求的 key 是不合理的&#xff0c;根本不存在于缓存中&#xff0c;也不存在于数据库中 。这就导致这些请求直接到了数据库上&#xff0c;根本没有经过缓存这一层&#xff0c;对数据库造成了巨大的压力&#xf…

2、Qt UI控件 -- qucsdk项目使用

前言&#xff1a;上一篇文章讲了qucsdk的环境部署&#xff0c;可以在QDesigner和Qt Creator中看到qucsdk控件&#xff0c;这一篇来讲下在项目中使用qucsdk库中的控件。 一、准备材料 要想使用第三方库&#xff0c;需要三个先决条件&#xff0c; 1、控件的头文件 2、动/静态链…

记录vue之npm run serve报错SET NODE_OPTIONS

> vue-antd-pro3.0.0 serve > SET NODE_OPTIONS--openssl-legacy-provider && vue-cli-service servesh: SET: command not found 一定要注意&#xff1a;将 SET NODE_OPTIONS–openssl-legacy-provider && 删除即可

17 - Games101 - 笔记 - 材质与外观

**17 **材质与外观 材质与BRDF 自然界中的材质&#xff1a;丝绸、头发、蝴蝶翅膀表面、寿司表面等等 图形学中的材质&#xff1a;同一个模型之所以渲染出不同结果的原因就是因为材质。在图形学中是给不同的物体指定不同的材质&#xff0c;知道它们如何和光线作用后就能正确的…

C++11 数据结构0 什么是 “数据结构“?数据,数据对象,数据元素,数据项 概念。算法的基本概念 和 算法的度量,大O表示法,空间换时间的代码

数据&#xff1a; 是能输入计算机且能被计算机处理的各种符号的集合。数值型的数据&#xff1a;整数和实数。非数值型的数据&#xff1a;文字、图像、图形、声音等。 数据对象&#xff1a; 性质相同的 "数据元素" 的集合 例如一个 int arr[10], Teacher tea[3]; 数…