Terraform 扩展

news2024/11/24 18:40:35

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.tf

locals {
    zone = "evescn.com"
    records = ["devops1","devops2","devops3"]
}

resource "alicloud_dns_record" "record" {
  count = length(local.records)
  name        = local.zone
  host_record = local.records[count.index]
  type        = "A"
  value       = "192.168.1.1"
}
## count.tf

locals {
    zone = "evescn.com"
    records = ["devops1","devops2","devops3"]
}

resource "alicloud_dns_record" "record" {
  count = length(local.records)
  name        = local.zone
  host_record = local.records[count.index]
  type        = "A"
  value       = "192.168.1.1"
}
创建 DNS 解析
evescn@evescndeMacBook-Pro count % terraform init

Initializing 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.tf

evescn@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:
  + create

Terraform 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-approve

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  + create

Terraform 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.zone
  host_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
  - destroy

Terraform 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
  - destroy

Terraform 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.tf

terraform {
  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.tf

locals {
  zone = "evescn.com"
  # records = ["devops1", "devops2", "devops3"]
  records = ["devops1", "devops3"]
}

resource "alicloud_dns_record" "eachrecord" {
  for_each    = toset(local.records)
  name        = local.zone
  host_record = each.value
  type        = "A"
  value       = "192.168.1.1"
}
创建 DNS 解析
evescn@evescndeMacBook-Pro for_each % terraform init

Initializing 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.tf

evescn@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:
  + create

Terraform 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: yes

alicloud_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.tf

locals {
  zone = "evescn.com"
  # records = ["devops1", "devops2", "devops3"]
  records = ["devops1", "devops3"]
}

resource "alicloud_dns_record" "eachrecord" {
  for_each    = toset(local.records)
  name        = local.zone
  host_record = each.value
  type        = "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:
  - destroy

Terraform 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: yes

alicloud_dns_record.eachrecord["devops2"]: Destroying... [id=843317481926367232]
alicloud_dns_record.eachrecord["devops2"]: Destruction complete after 0s

Apply 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_name
  content {
    key = iterator_name.value
  }
}
dynamic "ports" {
  for_each = local.jenkins_ports
  content {
    internal = ports.value.internal
    external = ports.value.external
    ip       = "0.0.0.0"
    protocol = "tcp"
  }
}

Docker 中的 ports{}

resource "docker_container" "jenkins" {

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

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

locals {
  jenkins_ports = [
    {
      internal = 8080
      external = 8080
    },
    {
      internal = 50000
      external = 50000
    }
  ]
}

resource "docker_container" "jenkins" {

  // 使用dynamic来实现动态
  dynamic "ports" {
    for_each = local.jenkins_ports
    content {
      internal = ports.value.internal
      external = ports.value.external
      ip       = "0.0.0.0"
      protocol = "tcp"
    }
  }

depends_on 依赖关系

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

resource "docker_image" "jenkins" {
  name         = "jenkins/jenkins:2.332.2-centos7-jdk8"
  force_remove = false
  keep_locally = true
}


resource "docker_container" "jenkins" {
  image      = docker_image.jenkins.name
  name       = "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 = true
  ignore_changes = [
    tags, instance_name
  ]
  replace_triggered_by = [
    alicloud_vpc.vpc.vpc_name
  ]
}

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

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

相关文章

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

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

读书笔记之人生算法(7)

孤独、爆仓与迷信 跨越出身和运气&#xff0c;实现富足与自由&#xff0c;用概率思维做好决策 13 孤独 孤独&#xff1a;获得好姻缘的算法 姻缘是奇妙的东西&#xff0c;体现了世界的随机性&#xff1a;即使是最理性的人&#xff0c;也可能需要靠运气寻找另一半。 中国有句古话…

Hot100【十一】:最大子数组和

// 定义dp&#xff1a;以i结尾的最大子数组和 dp[i] max(dp[i-1] nums[i],nums[i]) class Solution {public int maxSubArray(int[] nums) {// 1. 不需要特殊处理// 2. 定义dpint[] dp new int[nums.length];dp[0] nums[0];int maxResult nums[0];// 3. dp递推for (int i …

onSaveInstanceState()与onRestoreInstanceState()

目录 1.二者作用 2.onSaveInstanceState调用时机 2.1 五种情况 前4种情况Activity生命周期&#xff1a; 2.2 注意事项&#xff1a;确定会被系统回收并销毁&#xff0c;不会调用此方法 两个例子 3.onRestoreInstanceState调用时机 3.1实例——屏幕切换生命周期 3.2 极端…

https访问http的minio 图片展示不出来

问题描述&#xff1a;请求到的图片地址单独访问能显示&#xff0c;但是在网页中展示不出来 原因&#xff1a;https中直接访问http是不行的&#xff0c;需要用nginx再转发一下 nginx配置如下&#xff08;注意&#xff1a;9000是minio默认端口&#xff0c;已经占用&#xff0c;…

RobotFramework教程2——第一个例子(hello world)

前言&#xff1a;安装好RF框架后&#xff0c;我们现在开始创建并执行我们的第一个测试用例&#xff0c;第一个例子当然是用入门经典“hello world”啦&#xff01;运行也会有坑&#xff0c;注意避开&#xff0c;最新的东西不一定是现阶段最好的&#xff0c;稳定可运行才关键&am…

halcon缺陷检测-印刷品检测(差异化模型),键盘字符缺陷检测

前言 在实际项目中&#xff0c;印刷品缺陷检测是缺陷检测中的难点项目。通常印刷品检测往往具备缺陷小&#xff0c;缺陷所在位置不固定&#xff0c;出现少印或者多印的情况。并且由于产线原因&#xff0c;大量的印刷品在视野中的大小并不是完全一致的&#xff0c;可能出现细微…

《高通量测序技术》分享,生物信息学生信流程的性能验证,以肿瘤NGS基因检测为例。

这是这本书&#xff0c;第四章第五节的内容&#xff0c;这一部分是以NGS检测肿瘤基因突变为例&#xff0c;描述了其原理和大概流程&#xff0c;这和以前我分享的病原宏基因组高通量测序性能确认方案可以互相补充&#xff0c;大家可以都看一下&#xff0c;但是想要真正的弄懂&am…

AI应用实战2:使用scikit-learn进行回归任务实战

代码仓库在gitlab&#xff0c;本博客对应于02文件夹。 1.问题分析 在此篇博客中我们来对回归任务进行实战演练&#xff0c;背景是直播带货平台的业绩预测。第一步&#xff0c;就是分析问题。 问题痛点&#xff1a; 在直播带货平台上&#xff0c;由于市场环境多变、用户行为复…

SHOPFA:APP定制开发的哪种二开项目容易交付,哪些不可以接?

在商城系统开发领域&#xff0c;定制开发与二次开发&#xff08;二开&#xff09;是两种截然不同的项目类型。它们之间的主要差异体现在项目起点、灵活性、成本、时间以及风险等多个方面。 一、项目起点 商城定制开发通常是从零开始&#xff0c;根据客户的实际需求&#xff0c…

OpenOCD中flash编程算法的实现

OpenOCD中flash编程算法的实现 如何自己设计一个基于openocd调试架构的芯片下载算法&#xff0c;作为一个嵌入式er, 如果做MCU的开发是必须要了解的&#xff0c;因为各个芯片公司都有自己的芯片&#xff0c;而flash驱动各家有不同&#xff0c;所以往往需要自家的工程师去支持&…

【设计模式】笔记篇

目录标题 OO设计原则策略模式 - Strategy定义案例分析需求思路分析核心代码展示进一步优化UML 图 观察者模式 - Observe定义案例分析需求UML图内置的Java观察者模式核心代码 总结 装饰者模式 - Decorator定义案例分析需求UML图分析核心代码 总结 工厂模式 - Abstract Method/Fa…

【C++基础】变量和数据类型

变量和数据类型 引言&#xff1a;为什么需要变量&#xff1f;一、变量1. 变量的声明2. 变量的赋值3. 标识符4. 作用域5. 常量6. 注意 二、基本数据类型1. 整型1.1 常用整型1.2 无符号整型1.3 char类型1.4 bool类型 2. 浮点型3. 字面值常量3.1 整型字面值3.2 浮点型字面值3.3 字…

蓝桥杯第十二届c++大学B组详解

目录 1.空间 2.直线 3.路径 4.卡片 5.货物摆放 6.时间显示 7.砝码称重 8.杨辉三角 9.双向排序 10.括号序列 1.空间 题目解析&#xff1a;1Byte 8bit 1kb 1024B 1MB 1024kb; 先将256MB变成Byte 256 * 1024 * 1024; 再将32位 变成Byte就是 32 / 8 4&#xff1b;…

人工智能前沿成科技竞争新高地

以下文章来源&#xff1a;经济参考报 近日&#xff0c;首届中国具身智能大会&#xff08;CEAI 2024&#xff09;在上海举行。作为人工智能领域的前沿热点&#xff0c;具身智能正逐步走进现实&#xff0c;成为当前全球科技竞争的新高地、未来产业的新赛道、经济发展的新引擎。 “…

在Linux终端查找指定类型的文件并统计数量

下面举例说明&#xff1a; find /path/to/directory -type f -exec file {} \; | grep "MIDI"它的作用是在指定的目录&#xff08;/path/to/directory&#xff09;中搜索所有的文件&#xff08;-type f&#xff09;&#xff0c;然后使用file命令检查每个文件的类型&a…

《QT实用小工具·二十四》各种数学和数据的坐标演示图

1、概述 源码放在文章末尾 该项目实现了各种数学和数据的坐标演示图&#xff0c;下面是demo演示&#xff1a; 项目部分代码如下&#xff1a; #ifndef FRMMAIN_H #define FRMMAIN_H#include <QWidget> class QAbstractButton;namespace Ui { class frmMain; }class fr…

AWD靶机实战第二天:使用python脚本获取flag

上一部分我们通过读源码和利用源码审计的工具找到了这个漏洞&#xff0c;但是在比赛的时候有很多靶机&#xff0c;我们去一个个的注册&#xff0c;一个个的登录然后输入很浪费时间&#xff0c;所以我选择写一个python脚本来实现自动获得flag以及自动提交flag. 首先我们将这次的…

群联AI云防护中的防盗链技术原理及其作用探析---

一、引言 随着云计算和AI技术的快速发展&#xff0c;云防护方案已经成为现代企业防范网络攻击和保护数字资产的重要手段之一。群联科技作为存储解决方案和技术服务的领导者&#xff0c;已将其AI技术应用于云端防护系统中&#xff0c;并特别强化了防盗链功能&#xff0c;以帮助…

第十四届蓝桥杯省赛真题-幸运数

代码及解析: #include <iostream> using namespace std;bool check(int x) {int tmpx,len0;while(tmp){len;tmp/10;}//算位数的方法 if(len%21)return 0;//直接retrun 0 int tlen/2;int ans10,ans20;while(t--){ans1x%10;//加每一位x/10; }while(x){ans2x%10;x/10;}if(…