Skip to content

support for loadbalancer resource, description and timeout #55

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,19 @@ jobs:
terraform -chdir="$dir" validate
done

- name: Run unit tests
run: |
go test -v ./pkg/itacservices/tests \
-coverpkg=./pkg/itacservices,./pkg/itacservices/common \
-coverprofile=coverage.out


- name: Upload unit test coverage report
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: coverage.out


# TODO
#- name: Run unit tests
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ terraform {
required_providers {
intelcloud = {
source = "intel/intelcloud"
version = "0.0.9"
version = "0.0.19"
}
}
}
Expand Down
155 changes: 155 additions & 0 deletions examples/resources/iks/cluster_multi_nogegroup/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
# Intel Tiber AI Cloud Terraform Provider
### This example is to demonstrate to the users, how an IKS clusters with multiple nodegroups can be deployed (with nodegroup details being configurable)

### Pre-requisites
- Please see this page for getting setup correctly before running this example [Setting up provider locally](../../../../README.md)

## Explanation of the example [main.tf](main.tf)

### Creating the resource
```
locals {
...
...
# list of nodegroups user wants to create
node_group_list = {
"ng1" = {
node_type = "vm-spr-sml"
node_count = 1
ssh_keys = ["rk-win-key", "rk-tf-key"]
}
"ng2" = {
node_type = "vm-spr-sml"
node_count = 1
ssh_keys = ["rk-win-key"]
}
}
...
...
}
```

The above block is used to define a local variable for represnting a list of nodegroups, in the main.tf file, this will be looped through and values will picked up for each nodegroup, namely `ng1` and `ng2` in this case.

When the user runs `terraform apply` in the current directory, the user should see the following:

```
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:

# intelcloud_iks_cluster.cluster will be created
+ resource "intelcloud_iks_cluster" "cluster" {
+ cloudaccount = (known after apply)
+ cluster_status = (known after apply)
+ id = (known after apply)
+ kubernetes_version = "1.30"
+ name = (known after apply)
+ network = (known after apply)
+ storage = {
+ size_in_tb = 30
+ state = (known after apply)
+ storage_provider = (known after apply)
}
+ upgrade_available = (known after apply)

+ timeouts {
+ resource_timeout = "30m"
}
}

# intelcloud_iks_node_group.node_group["ng1"] will be created
+ resource "intelcloud_iks_node_group" "node_group" {
+ cluster_uuid = (known after apply)
+ id = (known after apply)
+ imiid = (known after apply)
+ name = "ng1"
+ node_count = 1
+ node_type = "vm-spr-sml"
+ ssh_public_key_names = [
+ "rk-tf-key",
+ "rk-win-key",
]
+ state = (known after apply)
+ userdata_url = (known after apply)
+ vnets = (known after apply)
}

# intelcloud_iks_node_group.node_group["ng2"] will be created
+ resource "intelcloud_iks_node_group" "node_group" {
+ cluster_uuid = (known after apply)
+ id = (known after apply)
+ imiid = (known after apply)
+ name = "ng2"
+ node_count = 1
+ node_type = "vm-spr-sml"
+ ssh_public_key_names = [
+ "rk-win-key",
]
+ state = (known after apply)
+ userdata_url = (known after apply)
+ vnets = (known after apply)
}

# random_pet.prefix will be created
+ resource "random_pet" "prefix" {
+ id = (known after apply)
+ length = 2
+ separator = "-"
}

Plan: 4 to add, 0 to change, 0 to destroy.
```

As you can see, each nodegroup is treated as a separate resource to be created.

### Modifying the resource
- Assume `terraform apply` is executed by the user and completes successfully.
- The user can change the nodegroup count and run `terraform apply` to modify the nodegroup
```
locals {
...
...
# list of nodegroups user wants to create
node_group_list = {
"ng1" = {
node_type = "vm-spr-sml"
node_count = 2
ssh_keys = ["rk-win-key", "rk-tf-key"]
}
"ng2" = {
node_type = "vm-spr-sml"
node_count = 3
ssh_keys = ["rk-win-key"]
}
}
...
...
}
```
- After `terraform apply` the node count in nodegroups `ng1` and `ng2` will updated to 2 and 3 respectively

### Modification with deletion included
- If after that user edits the local variable to have just one nodegroup in the list, for example
```
locals {
...
...
# list of nodegroups user wants to create
node_group_list = {
"ng1" = {
node_type = "vm-spr-sml"
node_count = 1
ssh_keys = ["rk-win-key", "rk-tf-key"]
}
...
...
}
```

- If after this the user runs `terraform apply` then nodegroup `ng2` will be deleted as the provider will assume it as such


### Destroying the resource
- The resource can be destroyed (once created successfully) by simply running `terraform destroy`
65 changes: 65 additions & 0 deletions examples/resources/iks/cluster_multi_nogegroup/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/************* Terraform provider and version number ***************/
terraform {
required_providers {
intelcloud = {
source = "intel/intelcloud"
version = "0.0.19"
}
}
}

provider "intelcloud" {
region = var.idc_region
}

provider "random" {
# Configuration options
}

/**** Random provider used to generate random names (like pet names) ****/
resource "random_pet" "prefix" {}

locals {
name = random_pet.prefix.id
availability_zone = var.idc_availability_zone
tags = {
environment = "demo"
}
# list of nodegroups user wants to create
node_group_list = {
"ng1" = {
node_type = "vm-spr-sml"
node_count = 1
ssh_keys = ["rk-win-key", "rk-tf-key"]
}
"ng2" = {
node_type = "vm-spr-sml"
node_count = 1
ssh_keys = ["rk-win-key"]
}
}
}

/***** Create an Intel Cloud IKS (Intel Kubernetes Service) cluster *******/
resource "intelcloud_iks_cluster" "cluster" {
name = "${local.name}-iks"
kubernetes_version = var.kubernetes_version

storage = {
size_in_tb = var.size_in_tb
}
# specify custom timeouts for the resource
timeouts {
resource_timeout = "30m"
}
}


resource "intelcloud_iks_node_group" "node_group" {
for_each = { for k, v in local.node_group_list : k => v if var.node_groups_create }
name = try(each.value.name, each.key)
cluster_uuid = intelcloud_iks_cluster.cluster.id
node_count = try(each.value.node_count, var.node_group_defaults.node_count, 1)
node_type = try(each.value.node_type, var.node_group_defaults.node_type, "vm-spr-sml")
ssh_public_key_names = try(each.value.ssh_keys, var.node_group_defaults.ssh_keys, [])
}
52 changes: 52 additions & 0 deletions examples/resources/iks/cluster_multi_nogegroup/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
variable "idc_region" {
type = string
default = "us-region-2"
}

variable "idc_availability_zone" {
type = string
default = "us-region-2a"
}

variable "kubernetes_version" {
type = string
default = "1.30"
}

variable "ssh_public_key_names" {
type = list(string)
default = ["your-public-key-name"]
}

variable "node_type" {
type = string
default = "vm-spr-sml"
}

variable "node_count" {
type = number
default = 1
}

variable "size_in_tb" {
type = number
default = 30
}

variable "node_groups_create" {
type = bool
default = true
}

variable "node_group_defaults" {
type = object({
node_count = number
node_type = string
ssh_keys = list(string)
})
default = {
node_count = 1
node_type = "vm-spr-sml"
ssh_keys = []
}
}
2 changes: 1 addition & 1 deletion examples/resources/iks/create/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ terraform {
required_providers {
intelcloud = {
source = "intel/intelcloud"
version = "0.0.15"
version = "0.0.19"
}
}
}
Expand Down
42 changes: 21 additions & 21 deletions examples/resources/iks/nodegroup/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ terraform {
required_providers {
intelcloud = {
source = "intel/intelcloud"
version = "0.0.15"
version = "0.0.18"
}
}
}
Expand All @@ -12,28 +12,28 @@ provider "intelcloud" {
region = "us-region-2"
}

provider "random" {
# Configuration options
}

/**** Random provider used to generate random names (like pet names) ****/
resource "random_pet" "prefix" {}

locals {
name = random_pet.prefix.id
availability_zone = "us-region-2a"
tags = {
environment = "Demo"
}
}
#provider "random" {
# # Configuration options
#}
#
#/**** Random provider used to generate random names (like pet names) ****/
#resource "random_pet" "prefix" {}
#
#locals {
# name = random_pet.prefix.id
# availability_zone = "us-region-2a"
# tags = {
# environment = "Demo"
# }
#}

resource "intelcloud_iks_node_group" "ng1" {
cluster_uuid = "<your-cluster-uuid>"
name = "${local.name}-ng"
node_count = 2
node_type = "vm-spr-sml"
userdata_url = ""
ssh_public_key_names = ["rk-win-key"]
cluster_uuid = "cl-2agtscgbmy"
name = "bright-stinkbug-ng-new"
node_count = 4
node_type = "vm-spr-sml"
#userdata_url = "https://test.com/userdata"
ssh_public_key_names = ["rk-win-key", "rk-tf-key"]
}

output "iks_order" {
Expand Down
4 changes: 4 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ go 1.23.0
toolchain go1.23.7

require (
github.com/golang/mock v1.6.0
github.com/hashicorp/terraform-plugin-docs v0.19.2
github.com/hashicorp/terraform-plugin-framework v1.8.0
github.com/hashicorp/terraform-plugin-log v0.9.0
github.com/sethvargo/go-retry v0.2.4
github.com/stretchr/testify v1.8.2
)

require (
Expand All @@ -23,6 +25,7 @@ require (
github.com/bgentry/speakeasy v0.1.0 // indirect
github.com/bmatcuk/doublestar/v4 v4.6.1 // indirect
github.com/cloudflare/circl v1.3.7 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fatih/color v1.16.0 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/uuid v1.6.0 // indirect
Expand Down Expand Up @@ -51,6 +54,7 @@ require (
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/oklog/run v1.0.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/posener/complete v1.2.3 // indirect
github.com/shopspring/decimal v1.3.1 // indirect
github.com/spf13/cast v1.5.0 // indirect
Expand Down
Loading
Loading