Skip to content

Instantly share code, notes, and snippets.

@shishkin
Last active December 13, 2022 08:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shishkin/1c6b19a7e1c6fb92f2734a694c7b3013 to your computer and use it in GitHub Desktop.
Save shishkin/1c6b19a7e1c6fb92f2734a694c7b3013 to your computer and use it in GitHub Desktop.
{
"//": {
"metadata": {
"backend": "local",
"stackName": "test",
"version": "0.14.3"
},
"outputs": {
"test": {
"test": "test"
}
}
},
"output": {
"test": {
"sensitive": false,
"value": "https://${var.CLUSTER_DOMAIN}:${var.CLUSTER_PORT_HTTPS}/"
}
},
"provider": {
"kubernetes": [
{
}
]
},
"resource": {
"kubernetes_config_map_v1": {
"config": {
"//": {
"metadata": {
"path": "test/config",
"uniqueId": "config"
}
},
"data": {
"config": "${yamlencode({url = \"https://${var.CLUSTER_DOMAIN}:var.CLUSTER_PORT_HTTPS/\"})}"
},
"metadata": {
"name": "test"
}
}
}
},
"terraform": {
"backend": {
"local": {
"path": ".../terraform.test.tfstate"
}
},
"required_providers": {
"kubernetes": {
"source": "kubernetes",
"version": "2.16.1"
}
}
},
"variable": {
"CLUSTER_DOMAIN": {
"sensitive": false,
"type": "string"
},
"CLUSTER_PORT_HTTPS": {
"sensitive": false,
"type": "number"
}
}
}
apiVersion: v1
data:
config: |
"url": "https://cluster.local:var.CLUSTER_PORT_HTTPS/"
immutable: false
kind: ConfigMap
metadata:
creationTimestamp: "2022-12-12T16:47:20Z"
name: test
namespace: default
resourceVersion: "6425"
uid: 7cd788f0-91a1-4d0d-84a8-6765dd056db8
$ dotenv -- cdktf deploy --auto-approve --ignore-missing-stack-dependencies network
network Initializing the backend...
network Initializing provider plugins...
- Reusing previous version of hashicorp/kubernetes from the dependency lock file
network - Reusing previous version of hashicorp/helm from the dependency lock file
network - Reusing previous version of gavinbunney/kubectl from the dependency lock file
network - Using previously-installed hashicorp/helm v2.7.1
network - Using previously-installed gavinbunney/kubectl v1.14.0
network - Using previously-installed hashicorp/kubernetes v2.16.0
network Terraform has been successfully initialized!
You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.
If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.
network 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:
# kubernetes_config_map_v1.config (config) will be created
+ resource "kubernetes_config_map_v1" "config" {
+ data = {
+ "config" = <<-EOT
"url": "https://cluster.local:var.CLUSTER_PORT_HTTPS/"
EOT
}
+ id = (known after apply)
+ metadata {
+ generation = (known after apply)
+ name = "test"
+ namespace = "default"
+ resource_version = (known after apply)
+ uid = (known after apply)
}
}
Plan: 1 to add, 0 to change, 0 to destroy.
Changes to Outputs:
~ test = "https://login.cluster.local:8443" -> "https://cluster.local:8443/"
─────────────────────────────────────────────────────────────────────────────
Saved the plan to: plan
To perform exactly these actions, run the following command to apply:
terraform apply "plan"
network kubernetes_config_map_v1.config (config): Creating...
network kubernetes_config_map_v1.config (config): Creation complete after 0s [id=default/test]
network
Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
Outputs:
test = "https://cluster.local:8443/"
network
test = https://cluster.local:8443/
✨ Done in 5.61s.
import { Construct } from "constructs";
import { Fn, TerraformOutput, TerraformStack, TerraformVariable } from "cdktf";
import { ConfigMapV1 } from "@cdktf/provider-kubernetes/lib/config-map-v1";
import { KubernetesProvider } from "@cdktf/provider-kubernetes/lib/provider";
export class TestStack extends TerraformStack {
constructor(scope: Construct, id: string, props?: {}) {
super(scope, id);
new KubernetesProvider(this, "kubernetes", {});
const clusterDomain = new TerraformVariable(this, "CLUSTER_DOMAIN", {
type: "string",
sensitive: false,
});
const clusterPortHttps = new TerraformVariable(this, "CLUSTER_PORT_HTTPS", {
type: "number",
sensitive: false,
});
new TerraformOutput(this, "test", {
value: `https://${clusterDomain.stringValue}:${clusterPortHttps.numberValue}/`,
sensitive: false,
});
new ConfigMapV1(this, "config", {
metadata: {
name: "test",
},
data: {
config: Fn.yamlencode({
url: `https://${clusterDomain.stringValue}:${clusterPortHttps.numberValue}/`,
}),
},
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment