I'm testing Terraform script to create some test commands:
terraform {
required_providers {
rancher2 = {
source = "rancher/rancher2"
version = "1.24.1"
}
}
}
provider "rancher2" {
api_url = "https://192.168.1.128/v3"
access_key = "token-vdzvv"
secret_key = "kl4tx6vfmhbbv8ctjp6hnct7dggmrdttsxjl6xr4sz5wgr8k47s864"
}
resource "kubernetes_namespace" "example" {
metadata {
annotations = {
name = "example-annotation"
}
labels = {
mylabel = "label-value"
}
name = "terraform-example-namespace"
}
}
output:
C:\ter>terraform init -upgrade
Initializing the backend...
Initializing provider plugins...
- Finding rancher/rancher2 versions matching "1.24.1"...
- Finding latest version of hashicorp/kubernetes...
- Using previously-installed rancher/rancher2 v1.24.1
- Using previously-installed hashicorp/kubernetes v2.13.1
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.
C:\ter>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:
# kubernetes_namespace.example will be created
+ resource "kubernetes_namespace" "example" {
+ id = (known after apply)
+ metadata {
+ annotations = {
+ "name" = "example-annotation"
}
+ generation = (known after apply)
+ labels = {
+ "mylabel" = "label-value"
}
+ name = "terraform-example-namespace"
+ resource_version = (known after apply)
+ uid = (known after apply)
}
}
Plan: 1 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
kubernetes_namespace.example: Creating...
╷
│ Error: Post "http://localhost/api/v1/namespaces": dial tcp [::1]:80: connectex: No connection could be made because the target machine actively refused it.
│
│ with kubernetes_namespace.example,
│ on main.tf line 16, in resource "kubernetes_namespace" "example":
│ 16: resource "kubernetes_namespace" "example" {
│
╵
C:\ter>
Rancher is connected to 4 node native Kubernetes cluster. For some reason I get this error:
Error: Post "http://localhost/api/v1/namespaces": dial tcp [::1]:80: connectex: No connection could be made because the target machine actively refused it.
Any idea why localhost is hardcoded?