mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
Implement Quotas v3 (#5012)
* provisioner/terraform: add cost to resource_metadata * provisionerd/runner: use Options struct * Complete provisionerd implementation * Add quota_allowance to groups * Combine Quota and RBAC licenses * Add Opts to InTx
This commit is contained in:
@@ -55,6 +55,7 @@ type metadataAttributes struct {
|
||||
ResourceID string `mapstructure:"resource_id"`
|
||||
Hide bool `mapstructure:"hide"`
|
||||
Icon string `mapstructure:"icon"`
|
||||
DailyCost int32 `mapstructure:"daily_cost"`
|
||||
Items []metadataItem `mapstructure:"item"`
|
||||
}
|
||||
|
||||
@@ -301,6 +302,8 @@ func ConvertResources(module *tfjson.StateModule, rawGraph string) ([]*proto.Res
|
||||
resourceMetadata := map[string][]*proto.Resource_Metadata{}
|
||||
resourceHidden := map[string]bool{}
|
||||
resourceIcon := map[string]string{}
|
||||
resourceCost := map[string]int32{}
|
||||
|
||||
for _, resource := range tfResourceByLabel {
|
||||
if resource.Type != "coder_metadata" {
|
||||
continue
|
||||
@@ -360,6 +363,7 @@ func ConvertResources(module *tfjson.StateModule, rawGraph string) ([]*proto.Res
|
||||
|
||||
resourceHidden[targetLabel] = attrs.Hide
|
||||
resourceIcon[targetLabel] = attrs.Icon
|
||||
resourceCost[targetLabel] = attrs.DailyCost
|
||||
for _, item := range attrs.Items {
|
||||
resourceMetadata[targetLabel] = append(resourceMetadata[targetLabel],
|
||||
&proto.Resource_Metadata{
|
||||
@@ -389,9 +393,10 @@ func ConvertResources(module *tfjson.StateModule, rawGraph string) ([]*proto.Res
|
||||
Name: resource.Name,
|
||||
Type: resource.Type,
|
||||
Agents: agents,
|
||||
Metadata: resourceMetadata[label],
|
||||
Hide: resourceHidden[label],
|
||||
Icon: resourceIcon[label],
|
||||
Metadata: resourceMetadata[label],
|
||||
DailyCost: resourceCost[label],
|
||||
InstanceType: applyInstanceType(resource),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -145,10 +145,11 @@ func TestConvertResources(t *testing.T) {
|
||||
}},
|
||||
// Tests fetching metadata about workspace resources.
|
||||
"resource-metadata": {{
|
||||
Name: "about",
|
||||
Type: "null_resource",
|
||||
Hide: true,
|
||||
Icon: "/icon/server.svg",
|
||||
Name: "about",
|
||||
Type: "null_resource",
|
||||
Hide: true,
|
||||
Icon: "/icon/server.svg",
|
||||
DailyCost: 29,
|
||||
Metadata: []*proto.Resource_Metadata{{
|
||||
Key: "hello",
|
||||
Value: "world",
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"format_version": "1.1",
|
||||
"terraform_version": "1.3.4",
|
||||
"terraform_version": "1.3.3",
|
||||
"planned_values": {
|
||||
"root_module": {
|
||||
"resources": [
|
||||
|
||||
+3
-3
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"format_version": "1.0",
|
||||
"terraform_version": "1.3.4",
|
||||
"terraform_version": "1.3.3",
|
||||
"values": {
|
||||
"root_module": {
|
||||
"resources": [
|
||||
@@ -17,11 +17,11 @@
|
||||
"connection_timeout": 120,
|
||||
"dir": null,
|
||||
"env": null,
|
||||
"id": "f7ee18b5-2baf-461b-9d82-7654c669930c",
|
||||
"id": "5c92d003-112d-4eb1-8e5f-d3009aa52fcb",
|
||||
"init_script": "",
|
||||
"os": "linux",
|
||||
"startup_script": null,
|
||||
"token": "2b47c5a8-1511-46f5-9821-95510c83afb2",
|
||||
"token": "fedbf404-c42d-4360-815b-5ffc34198df3",
|
||||
"troubleshooting_url": null
|
||||
},
|
||||
"sensitive_values": {}
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"format_version": "1.1",
|
||||
"terraform_version": "1.3.4",
|
||||
"terraform_version": "1.3.3",
|
||||
"planned_values": {
|
||||
"root_module": {
|
||||
"resources": [
|
||||
|
||||
Generated
Vendored
+3
-3
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"format_version": "1.0",
|
||||
"terraform_version": "1.3.4",
|
||||
"terraform_version": "1.3.3",
|
||||
"values": {
|
||||
"root_module": {
|
||||
"resources": [
|
||||
@@ -17,11 +17,11 @@
|
||||
"connection_timeout": 120,
|
||||
"dir": null,
|
||||
"env": null,
|
||||
"id": "9f9cf95a-77ea-40bf-b9bc-055f4971923d",
|
||||
"id": "6cc2be0d-fe90-4256-944f-482787433587",
|
||||
"init_script": "",
|
||||
"os": "linux",
|
||||
"startup_script": null,
|
||||
"token": "0d846d9b-1fa9-4ab3-962c-f249395645a7",
|
||||
"token": "1927809c-5fcf-4fdd-94d7-9a619fb86d13",
|
||||
"troubleshooting_url": null
|
||||
},
|
||||
"sensitive_values": {}
|
||||
|
||||
Generated
Vendored
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"format_version": "1.1",
|
||||
"terraform_version": "1.3.4",
|
||||
"terraform_version": "1.3.3",
|
||||
"planned_values": {
|
||||
"root_module": {
|
||||
"resources": [
|
||||
|
||||
Generated
Vendored
+5
-5
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"format_version": "1.0",
|
||||
"terraform_version": "1.3.4",
|
||||
"terraform_version": "1.3.3",
|
||||
"values": {
|
||||
"root_module": {
|
||||
"resources": [
|
||||
@@ -17,11 +17,11 @@
|
||||
"connection_timeout": 120,
|
||||
"dir": null,
|
||||
"env": null,
|
||||
"id": "aac3d245-52fa-4588-9759-694017908e7c",
|
||||
"id": "bcaf2577-5dfd-4083-a446-789092a7babe",
|
||||
"init_script": "",
|
||||
"os": "linux",
|
||||
"startup_script": null,
|
||||
"token": "a9f32b40-d630-47f0-80a6-5727fd729fae",
|
||||
"token": "862867af-cf08-4aea-a2af-70d0014f848b",
|
||||
"troubleshooting_url": null
|
||||
},
|
||||
"sensitive_values": {}
|
||||
@@ -34,7 +34,7 @@
|
||||
"provider_name": "registry.terraform.io/hashicorp/null",
|
||||
"schema_version": 0,
|
||||
"values": {
|
||||
"id": "5577006791947779410",
|
||||
"id": "8674665223082153551",
|
||||
"triggers": null
|
||||
},
|
||||
"sensitive_values": {},
|
||||
@@ -50,7 +50,7 @@
|
||||
"provider_name": "registry.terraform.io/hashicorp/null",
|
||||
"schema_version": 0,
|
||||
"values": {
|
||||
"id": "8674665223082153551",
|
||||
"id": "5577006791947779410",
|
||||
"triggers": null
|
||||
},
|
||||
"sensitive_values": {},
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"format_version": "1.1",
|
||||
"terraform_version": "1.3.4",
|
||||
"terraform_version": "1.3.3",
|
||||
"planned_values": {
|
||||
"root_module": {
|
||||
"resources": [
|
||||
|
||||
+5
-5
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"format_version": "1.0",
|
||||
"terraform_version": "1.3.4",
|
||||
"terraform_version": "1.3.3",
|
||||
"values": {
|
||||
"root_module": {
|
||||
"resources": [
|
||||
@@ -17,11 +17,11 @@
|
||||
"connection_timeout": 120,
|
||||
"dir": null,
|
||||
"env": null,
|
||||
"id": "327a022c-8b88-4d57-8d25-4b1dd66d817b",
|
||||
"id": "30431432-7afb-4d73-8eeb-ee464a28e157",
|
||||
"init_script": "",
|
||||
"os": "linux",
|
||||
"startup_script": null,
|
||||
"token": "a0082875-2172-456c-a8fe-ae45499443af",
|
||||
"token": "3ce9bbd8-0f31-4460-842b-8e9c1de9a567",
|
||||
"troubleshooting_url": null
|
||||
},
|
||||
"sensitive_values": {}
|
||||
@@ -34,8 +34,8 @@
|
||||
"provider_name": "registry.terraform.io/coder/coder",
|
||||
"schema_version": 0,
|
||||
"values": {
|
||||
"agent_id": "327a022c-8b88-4d57-8d25-4b1dd66d817b",
|
||||
"id": "ddb786af-b1a5-4b22-954b-387177e17f16",
|
||||
"agent_id": "30431432-7afb-4d73-8eeb-ee464a28e157",
|
||||
"id": "679f9bf2-8887-4201-a5cd-e53913e8d361",
|
||||
"instance_id": "example"
|
||||
},
|
||||
"sensitive_values": {},
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"format_version": "1.1",
|
||||
"terraform_version": "1.3.4",
|
||||
"terraform_version": "1.3.3",
|
||||
"planned_values": {
|
||||
"root_module": {
|
||||
"resources": [
|
||||
|
||||
+7
-7
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"format_version": "1.0",
|
||||
"terraform_version": "1.3.4",
|
||||
"terraform_version": "1.3.3",
|
||||
"values": {
|
||||
"root_module": {
|
||||
"resources": [
|
||||
@@ -17,11 +17,11 @@
|
||||
"connection_timeout": 120,
|
||||
"dir": null,
|
||||
"env": null,
|
||||
"id": "2777eff3-2f9f-4515-8cea-0dc7dbb53bf0",
|
||||
"id": "e545d734-f852-4fda-ac8f-39e3ff094e58",
|
||||
"init_script": "",
|
||||
"os": "linux",
|
||||
"startup_script": null,
|
||||
"token": "0fb4dd96-6acd-48d2-a41a-396e957cf5f6",
|
||||
"token": "c2c47266-af7a-467c-9ffc-30c3270ffecb",
|
||||
"troubleshooting_url": null
|
||||
},
|
||||
"sensitive_values": {}
|
||||
@@ -39,11 +39,11 @@
|
||||
"connection_timeout": 1,
|
||||
"dir": null,
|
||||
"env": null,
|
||||
"id": "48c7e389-c6a3-4cff-8331-aec26ee42cc4",
|
||||
"id": "b5e18556-d202-478f-80d9-76f34a4cb105",
|
||||
"init_script": "",
|
||||
"os": "darwin",
|
||||
"startup_script": null,
|
||||
"token": "0e9a30ca-59a4-4070-8517-0f7ebc5d1ab8",
|
||||
"token": "795082f9-642a-4647-a595-6539edaa74a3",
|
||||
"troubleshooting_url": null
|
||||
},
|
||||
"sensitive_values": {}
|
||||
@@ -61,11 +61,11 @@
|
||||
"connection_timeout": 120,
|
||||
"dir": null,
|
||||
"env": null,
|
||||
"id": "f4b435ff-47a5-4fd5-8529-5ca0288eec6d",
|
||||
"id": "27e1114a-bc92-4e35-ab57-1680f3b7658f",
|
||||
"init_script": "",
|
||||
"os": "windows",
|
||||
"startup_script": null,
|
||||
"token": "763e2baa-36d0-45d6-9511-08034fa752ca",
|
||||
"token": "c4fc1679-eb42-4d9f-bca8-fcf9641a7256",
|
||||
"troubleshooting_url": "https://coder.com/troubleshoot"
|
||||
},
|
||||
"sensitive_values": {}
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"format_version": "1.1",
|
||||
"terraform_version": "1.3.4",
|
||||
"terraform_version": "1.3.3",
|
||||
"planned_values": {
|
||||
"root_module": {
|
||||
"resources": [
|
||||
|
||||
+9
-9
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"format_version": "1.0",
|
||||
"terraform_version": "1.3.4",
|
||||
"terraform_version": "1.3.3",
|
||||
"values": {
|
||||
"root_module": {
|
||||
"resources": [
|
||||
@@ -17,11 +17,11 @@
|
||||
"connection_timeout": 120,
|
||||
"dir": null,
|
||||
"env": null,
|
||||
"id": "8cf70a43-80fa-4f84-b651-f6ff21f7fbcc",
|
||||
"id": "f911bd98-54fc-476a-aec1-df6e525630a9",
|
||||
"init_script": "",
|
||||
"os": "linux",
|
||||
"startup_script": null,
|
||||
"token": "b41f44b7-f889-4ce9-9061-4f34952103d7",
|
||||
"token": "fa05ad9c-2062-4707-a27f-12364c89641e",
|
||||
"troubleshooting_url": null
|
||||
},
|
||||
"sensitive_values": {}
|
||||
@@ -34,12 +34,12 @@
|
||||
"provider_name": "registry.terraform.io/coder/coder",
|
||||
"schema_version": 0,
|
||||
"values": {
|
||||
"agent_id": "8cf70a43-80fa-4f84-b651-f6ff21f7fbcc",
|
||||
"agent_id": "f911bd98-54fc-476a-aec1-df6e525630a9",
|
||||
"command": null,
|
||||
"display_name": null,
|
||||
"healthcheck": [],
|
||||
"icon": null,
|
||||
"id": "927154ef-0b53-4b90-b6de-034581c46759",
|
||||
"id": "038d0f6c-90b7-465b-915a-8a9f0cf21757",
|
||||
"name": null,
|
||||
"relative_path": null,
|
||||
"share": "owner",
|
||||
@@ -62,7 +62,7 @@
|
||||
"provider_name": "registry.terraform.io/coder/coder",
|
||||
"schema_version": 0,
|
||||
"values": {
|
||||
"agent_id": "8cf70a43-80fa-4f84-b651-f6ff21f7fbcc",
|
||||
"agent_id": "f911bd98-54fc-476a-aec1-df6e525630a9",
|
||||
"command": null,
|
||||
"display_name": null,
|
||||
"healthcheck": [
|
||||
@@ -73,7 +73,7 @@
|
||||
}
|
||||
],
|
||||
"icon": null,
|
||||
"id": "e8b2c750-ac93-4126-964f-603cb06aa12e",
|
||||
"id": "c00ec121-a167-4418-8c4e-2ccae0a0cd6e",
|
||||
"name": null,
|
||||
"relative_path": null,
|
||||
"share": "owner",
|
||||
@@ -98,12 +98,12 @@
|
||||
"provider_name": "registry.terraform.io/coder/coder",
|
||||
"schema_version": 0,
|
||||
"values": {
|
||||
"agent_id": "8cf70a43-80fa-4f84-b651-f6ff21f7fbcc",
|
||||
"agent_id": "f911bd98-54fc-476a-aec1-df6e525630a9",
|
||||
"command": null,
|
||||
"display_name": null,
|
||||
"healthcheck": [],
|
||||
"icon": null,
|
||||
"id": "a1897b85-9691-4c7b-9a10-ff87c12efc89",
|
||||
"id": "e9226aa6-a1a6-42a7-8557-64620cbf3dc2",
|
||||
"name": null,
|
||||
"relative_path": null,
|
||||
"share": "owner",
|
||||
|
||||
@@ -2,7 +2,7 @@ terraform {
|
||||
required_providers {
|
||||
coder = {
|
||||
source = "coder/coder"
|
||||
version = "0.6.1"
|
||||
version = "0.6.3"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@ resource "coder_metadata" "about_info" {
|
||||
resource_id = null_resource.about.id
|
||||
hide = true
|
||||
icon = "/icon/server.svg"
|
||||
daily_cost = 29
|
||||
item {
|
||||
key = "hello"
|
||||
value = "world"
|
||||
|
||||
+7
-2
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"format_version": "1.1",
|
||||
"terraform_version": "1.3.4",
|
||||
"terraform_version": "1.3.3",
|
||||
"planned_values": {
|
||||
"root_module": {
|
||||
"resources": [
|
||||
@@ -31,6 +31,7 @@
|
||||
"provider_name": "registry.terraform.io/coder/coder",
|
||||
"schema_version": 0,
|
||||
"values": {
|
||||
"daily_cost": 29,
|
||||
"hide": true,
|
||||
"icon": "/icon/server.svg",
|
||||
"item": [
|
||||
@@ -125,6 +126,7 @@
|
||||
],
|
||||
"before": null,
|
||||
"after": {
|
||||
"daily_cost": 29,
|
||||
"hide": true,
|
||||
"icon": "/icon/server.svg",
|
||||
"item": [
|
||||
@@ -206,7 +208,7 @@
|
||||
"coder": {
|
||||
"name": "coder",
|
||||
"full_name": "registry.terraform.io/coder/coder",
|
||||
"version_constraint": "0.6.1"
|
||||
"version_constraint": "0.6.3"
|
||||
},
|
||||
"null": {
|
||||
"name": "null",
|
||||
@@ -238,6 +240,9 @@
|
||||
"name": "about_info",
|
||||
"provider_config_key": "coder",
|
||||
"expressions": {
|
||||
"daily_cost": {
|
||||
"constant_value": 29
|
||||
},
|
||||
"hide": {
|
||||
"constant_value": true
|
||||
},
|
||||
|
||||
+5
-4
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"format_version": "1.0",
|
||||
"terraform_version": "1.3.4",
|
||||
"terraform_version": "1.3.3",
|
||||
"values": {
|
||||
"root_module": {
|
||||
"resources": [
|
||||
@@ -17,11 +17,11 @@
|
||||
"connection_timeout": 120,
|
||||
"dir": null,
|
||||
"env": null,
|
||||
"id": "3aeed2cf-2a5a-40f7-a0d6-2c3508f601a4",
|
||||
"id": "7766b2a9-c00f-4cde-9acc-1fc05651dbdf",
|
||||
"init_script": "",
|
||||
"os": "linux",
|
||||
"startup_script": null,
|
||||
"token": "c22c9b1f-b077-4ed3-afa6-e10fc5485399",
|
||||
"token": "5e54c173-a813-4df0-b87d-0617082769dc",
|
||||
"troubleshooting_url": null
|
||||
},
|
||||
"sensitive_values": {}
|
||||
@@ -34,9 +34,10 @@
|
||||
"provider_name": "registry.terraform.io/coder/coder",
|
||||
"schema_version": 0,
|
||||
"values": {
|
||||
"daily_cost": 29,
|
||||
"hide": true,
|
||||
"icon": "/icon/server.svg",
|
||||
"id": "1f43c366-e7a6-49dc-ac19-894fd9fceac8",
|
||||
"id": "e43f1cd6-5dbb-4d6b-8942-37f914b37be5",
|
||||
"item": [
|
||||
{
|
||||
"is_null": false,
|
||||
|
||||
Reference in New Issue
Block a user