Skip to content

Commit

Permalink
add support for endpoint parameter in cluster_config (IBM-Cloud#4793)
Browse files Browse the repository at this point in the history
* add support for endpoint parameter in cluster_config

* adding unit tests for endpoint_type parameter

* remove default value "true" as the would be invalid

* update documentation
remove bluemix-go replace

* update bluemix-go + run go mod tidy
  • Loading branch information
mihivagyok authored Sep 17, 2023
1 parent 0a7ebd9 commit e644eed
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 24 deletions.
11 changes: 2 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/IBM-Cloud/terraform-provider-ibm
go 1.18

require (
github.com/IBM-Cloud/bluemix-go v0.0.0-20230601050310-eecebfbff63e
github.com/IBM-Cloud/bluemix-go v0.0.0-20230914140903-40534e34a2a5
github.com/IBM-Cloud/container-services-go-sdk v0.0.0-20230822142550-30562e113de9
github.com/IBM-Cloud/power-go-client v1.2.4
github.com/IBM/apigateway-go-sdk v0.0.0-20210714141226-a5d5d49caaca
Expand All @@ -24,8 +24,8 @@ require (
github.com/IBM/ibm-hpcs-uko-sdk v0.0.20-beta
github.com/IBM/keyprotect-go-client v0.12.2
github.com/IBM/networking-go-sdk v0.42.2
github.com/IBM/project-go-sdk v0.0.10
github.com/IBM/platform-services-go-sdk v0.48.1
github.com/IBM/project-go-sdk v0.0.10
github.com/IBM/push-notifications-go-sdk v0.0.0-20210310100607-5790b96c47f5
github.com/IBM/scc-go-sdk/v5 v5.0.2
github.com/IBM/schematics-go-sdk v0.2.1
Expand Down Expand Up @@ -63,13 +63,6 @@ require (
)

require (
github.com/IBM/go-sdk-core/v3 v3.2.4
github.com/IBM/project-go-sdk v0.0.10
github.com/akamai/AkamaiOPEN-edgegrid-golang v1.2.2
github.com/akamai/AkamaiOPEN-edgegrid-golang/v5 v5.0.0
github.com/pkg/errors v0.9.1
github.com/rook/rook v1.11.4
gopkg.in/yaml.v3 v3.0.1
k8s.io/utils v0.0.0-20230313181309-38a27ef9d749
sigs.k8s.io/controller-runtime v0.14.1
)
Expand Down
11 changes: 2 additions & 9 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,11 @@ github.com/DataDog/datadog-go v2.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3
github.com/DataDog/datadog-go v3.2.0+incompatible h1:qSG2N4FghB1He/r2mFrWKCaL7dXCilEuNEeAn20fdD4=
github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
github.com/DataDog/zstd v1.4.4/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo=
github.com/IBM-Cloud/bluemix-go v0.0.0-20230601050310-eecebfbff63e h1:0GNM+YmWoFcq8/cih+oZAv+cdvNt8ZdFO807QbBzm1Y=
github.com/IBM-Cloud/bluemix-go v0.0.0-20230601050310-eecebfbff63e/go.mod h1:cO5KCpiop9eP/pM/5W07TprYUkv/kHtajW1FiZgE59k=
github.com/IBM-Cloud/bluemix-go v0.0.0-20230914140903-40534e34a2a5 h1:1hjspcKEce53NnIT+byrqy6Bre1ZNmsbl+IZw8AqKsQ=
github.com/IBM-Cloud/bluemix-go v0.0.0-20230914140903-40534e34a2a5/go.mod h1:cO5KCpiop9eP/pM/5W07TprYUkv/kHtajW1FiZgE59k=
github.com/IBM-Cloud/container-services-go-sdk v0.0.0-20230822142550-30562e113de9 h1:sXRzCK3Glxpyu66Tu2NjztLdT5sDwj4qly+MJKRhdWY=
github.com/IBM-Cloud/container-services-go-sdk v0.0.0-20230822142550-30562e113de9/go.mod h1:xUQL9SGAjoZFd4GNjrjjtEpjpkgU7RFXRyHesbKTjiY=
github.com/IBM-Cloud/ibm-cloud-cli-sdk v0.5.3/go.mod h1:RiUvKuHKTBmBApDMUQzBL14pQUGKcx/IioKQPIcRQjs=
github.com/IBM-Cloud/power-go-client v1.2.2 h1:VNlzizoG2x06c3nL1ZBILF701QcvXcu6nEH3hmEKCkw=
github.com/IBM-Cloud/power-go-client v1.2.2/go.mod h1:Qfx0fNi+9hms+xu9Z6Euhu9088ByW6C/TCMLECTRWNE=
github.com/IBM-Cloud/power-go-client v1.2.4 h1:4y/ubiOXpMg3xyBryfgfsa8hae/9Dn5WLdvphoxvgsQ=
github.com/IBM-Cloud/power-go-client v1.2.4/go.mod h1:0YVWoIQN5I5IvyhO/m4yxgPJqCh9QjceN2FNlVpYlOQ=
github.com/IBM-Cloud/softlayer-go v1.0.5-tf h1:koUAyF9b6X78lLLruGYPSOmrfY2YcGYKOj/Ug9nbKNw=
Expand Down Expand Up @@ -459,7 +457,6 @@ github.com/go-git/go-billy/v5 v5.2.0/go.mod h1:pmpqyWchKfYfrkb/UVH4otLvyi/5gJlGI
github.com/go-git/go-billy/v5 v5.3.1 h1:CPiOUAzKtMRvolEKw+bG1PLRpT7D3LIs3/3ey4Aiu34=
github.com/go-git/go-billy/v5 v5.3.1/go.mod h1:pmpqyWchKfYfrkb/UVH4otLvyi/5gJlGI4Hb3ZqZ3W0=
github.com/go-git/go-git-fixtures/v4 v4.2.1/go.mod h1:K8zd3kDUAykwTdDCr+I0per6Y6vMiRR/nnVTBtavnB0=
github.com/go-git/go-git/v5 v5.0.0/go.mod h1:oYD8y9kWsGINPFJoLdaScGCN6dlKg23blmClfZwtUVA=
github.com/go-git/go-git/v5 v5.4.2 h1:BXyZu9t0VkbiHtqrsvdq39UDhGJTl1h55VW6CSC4aY4=
github.com/go-git/go-git/v5 v5.4.2/go.mod h1:gQ1kArt6d+n+BGd+/B/I74HwRTLhth2+zti4ihgckDc=
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
Expand Down Expand Up @@ -1065,8 +1062,6 @@ github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9Y
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8=
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
github.com/johnstarich/go/gopages v0.1.8/go.mod h1:OaSRjfHdFfN+LS7u6xqgNO7C2Uxjlvpm17DcKcvLBhY=
github.com/johnstarich/go/pipe v0.2.0/go.mod h1:3X9IdVJJnI7pkpzEH6np98wqHl55zFmbilKG+9+koMo=
github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc=
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
Expand Down Expand Up @@ -1096,7 +1091,6 @@ github.com/karrick/godirwalk v1.8.0/go.mod h1:H5KPZjojv4lE+QYImBI8xVtrBRgYrIVsaR
github.com/karrick/godirwalk v1.10.3/go.mod h1:RoGL9dQei4vP9ilrpETWE8CLOZ1kiN0LhBygSwrAsHA=
github.com/kelseyhightower/envconfig v1.3.0/go.mod h1:cccZRl6mQpaq41TPp5QxidR+Sa3axMbJDNb//FQX6Gg=
github.com/kelseyhightower/envconfig v1.4.0 h1:Im6hONhd3pLkfDFsbRgu68RDNkGF1r3dvMUtDTo2cv8=
github.com/kevinburke/ssh_config v0.0.0-20190725054713-01f96b0aa0cd/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM=
github.com/kevinburke/ssh_config v0.0.0-20201106050909-4977a11b4351 h1:DowS9hvgyYSX4TO5NpyC606/Z4SxnNYbT+WX27or6Ck=
github.com/kevinburke/ssh_config v0.0.0-20201106050909-4977a11b4351/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM=
github.com/keybase/go-crypto v0.0.0-20190403132359-d65b6b94177f/go.mod h1:ghbZscTyKdM07+Fw3KSi0hcJm+AlEUWj8QLlPtijN/M=
Expand Down Expand Up @@ -1540,7 +1534,6 @@ github.com/vmihailenco/msgpack/v4 v4.3.12/go.mod h1:gborTTJjAo/GWTqqRjrLCn9pgNN+
github.com/vmihailenco/tagparser v0.1.1 h1:quXMXlA39OCbd2wAdTsGDlK9RkOk6Wuw+x37wVyIuWY=
github.com/vmihailenco/tagparser v0.1.1/go.mod h1:OeAg3pn3UbLjkWt+rN9oFYB6u/cQgqMEUPoW2WPyhdI=
github.com/vmware/govmomi v0.18.0 h1:f7QxSmP7meCtoAmiKZogvVbLInT+CZx6Px6K5rYsJZo=
github.com/xanzy/ssh-agent v0.2.1/go.mod h1:mLlQY/MoOhWBj+gOGMQkOeiEvkx+8pJSI+0Bx9h2kr4=
github.com/xanzy/ssh-agent v0.3.0 h1:wUMzuKtKilRgBAD1sUb8gOwwRr2FGoBVumcjoOACClI=
github.com/xanzy/ssh-agent v0.3.0/go.mod h1:3s9xbODqPuuhK9JV1R321M/FlMZSBvE5aY6eAcqrDh0=
github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI=
Expand Down
16 changes: 11 additions & 5 deletions ibm/service/kubernetes/data_source_ibm_container_cluster_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ func DataSourceIBMContainerClusterConfig() *schema.Resource {
Optional: true,
Default: false,
},
"endpoint_type": {
Description: "It can specify what kind of server URL will be used for the cluster context",
Type: schema.TypeString,
Optional: true,
},
"config_file_path": {
Description: "The absolute path to the kubernetes config yml file ",
Type: schema.TypeString,
Expand Down Expand Up @@ -151,6 +156,7 @@ func dataSourceIBMContainerClusterConfigRead(d *schema.ResourceData, meta interf
admin := d.Get("admin").(bool)
configDir := d.Get("config_dir").(string)
network := d.Get("network").(bool)
endpointType := d.Get("endpoint_type").(string)

clusterId := "Cluster_Config_" + name
conns.IbmMutexKV.Lock(clusterId)
Expand All @@ -170,7 +176,7 @@ func dataSourceIBMContainerClusterConfigRead(d *schema.ResourceData, meta interf
expectedDir := v1.ComputeClusterConfigDir(configDir, name, admin)
configPath = filepath.Join(expectedDir, "config.yml")
if !helpers.FileExists(configPath) {
return fmt.Errorf(`[ERROR] Couldn't find the cluster config at expected path %s. Please set "download" to true to download the new config`, configPath)
return fmt.Errorf(`[ERROR] Couldn't find the cluster config at expected path %s. Please set "download" to true to download the new config`, configPath)
}
d.Set("config_file_path", configPath)

Expand All @@ -185,7 +191,7 @@ func dataSourceIBMContainerClusterConfigRead(d *schema.ResourceData, meta interf
var clusterKeyDetails v1.ClusterKeyInfo
err = resource.Retry(5*time.Minute, func() *resource.RetryError {
var err error
calicoConfigFilePath, clusterKeyDetails, err = csAPI.StoreConfigDetail(name, configDir, admin || true, network, targetEnv)
calicoConfigFilePath, clusterKeyDetails, err = csAPI.StoreConfigDetail(name, configDir, admin || true, network, targetEnv, endpointType)
if err != nil {
log.Printf("[DEBUG] Failed to fetch cluster config err %s", err)
if strings.Contains(err.Error(), "Could not login to openshift account runtime error:") {
Expand All @@ -200,7 +206,7 @@ func dataSourceIBMContainerClusterConfigRead(d *schema.ResourceData, meta interf
return nil
})
if conns.IsResourceTimeoutError(err) {
calicoConfigFilePath, clusterKeyDetails, err = csAPI.StoreConfigDetail(name, configDir, admin || true, network, targetEnv)
calicoConfigFilePath, clusterKeyDetails, err = csAPI.StoreConfigDetail(name, configDir, admin || true, network, targetEnv, endpointType)
}
if err != nil {
return fmt.Errorf("[ERROR] Error downloading the cluster config [%s]: %s", name, err)
Expand All @@ -217,7 +223,7 @@ func dataSourceIBMContainerClusterConfigRead(d *schema.ResourceData, meta interf
var clusterKeyDetails v1.ClusterKeyInfo
err = resource.Retry(5*time.Minute, func() *resource.RetryError {
var err error
clusterKeyDetails, err = csAPI.GetClusterConfigDetail(name, configDir, admin, targetEnv)
clusterKeyDetails, err = csAPI.GetClusterConfigDetail(name, configDir, admin, targetEnv, endpointType)
if err != nil {
log.Printf("[DEBUG] Failed to fetch cluster config err %s", err)
if strings.Contains(err.Error(), "Could not login to openshift account runtime error:") {
Expand All @@ -232,7 +238,7 @@ func dataSourceIBMContainerClusterConfigRead(d *schema.ResourceData, meta interf
return nil
})
if conns.IsResourceTimeoutError(err) {
clusterKeyDetails, err = csAPI.GetClusterConfigDetail(name, configDir, admin, targetEnv)
clusterKeyDetails, err = csAPI.GetClusterConfigDetail(name, configDir, admin, targetEnv, endpointType)
}
if err != nil {
return fmt.Errorf("[ERROR] Error downloading the cluster config [%s]: %s", name, err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package kubernetes_test

import (
"fmt"
"regexp"
"testing"

acc "github.com/IBM-Cloud/terraform-provider-ibm/ibm/acctest"
Expand Down Expand Up @@ -76,6 +77,8 @@ func TestAccIBMContainer_ClusterConfigCalicoDataSourceBasic(t *testing.T) {
"data.ibm_container_cluster_config.testacc_ds_cluster", "config_file_path"),
resource.TestCheckResourceAttrSet(
"data.ibm_container_cluster_config.testacc_ds_cluster", "calico_config_file_path"),
resource.TestMatchResourceAttr(
"data.ibm_container_cluster_config.testacc_ds_cluster", "host", regexp.MustCompile("^https://.*private.*")),
),
},
},
Expand Down Expand Up @@ -129,10 +132,12 @@ resource "ibm_container_cluster" "testacc_cluster" {
wait_till = "Normal"
public_vlan_id = "%s"
private_vlan_id = "%s"
private_service_endpoint = true
}
data "ibm_container_cluster_config" "testacc_ds_cluster" {
cluster_name_id = ibm_container_cluster.testacc_cluster.id
network = true
endpoint_type = "private"
}`, clustername, acc.Datacenter, acc.MachineType, acc.PublicVlanID, acc.PrivateVlanID)
}
15 changes: 14 additions & 1 deletion website/docs/d/container_cluster_config.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ resource "kubernetes_namespace" "example" {
}
}
```
## Example usage
## Example usage5
Example usage for connecting to Kubernetes provider for classic OpenShift cluster with host and token.

```terraform
Expand All @@ -103,6 +103,18 @@ resource "kubernetes_namespace" "example" {
}
```

## Example usage6
Example for getting kubeconfig for VPC Kubernetes cluster with admin certificates and with VPE Gateway as server URL

```terraform
data "ibm_container_cluster_config" "cluster_foo" {
cluster_name_id = "FOO"
config_dir = "/home/foo_config"
admint = "true"
endpoint_type = "vpe"
}
```


## Argument reference
Review the argument references that you can specify for your data source.
Expand All @@ -113,6 +125,7 @@ Review the argument references that you can specify for your data source.
- `download` - (Optional, Bool) Set the value to **false** to skip downloading the configuration for the administrator. The default value is **true**. The configuration files and certificates are downloaded to the directory that you specified in `config_dir` every time that you run your infrastructure code.
- `network` - (Optional, Bool) If set to **true**, the Calico configuration file, TLS certificates, and permission files that are required to run `calicoctl` commands in your cluster are downloaded in addition to the configuration files for the administrator. The default value is **false**.
- `resource_group_id` - (Optional, String) The ID of the resource group where your cluster is provisioned into. To find the resource group, run `ibmcloud resource groups` or use the `ibm_resource_group` data source. If this parameter is not provided, the `default` resource group is used.
- `endpoint_type` - (Optional, String) The server URL for the cluster context. If you do not include this parameter, the default cluster service endpoint is used. Available options: `private`, `link` (Satellite), `vpe` (VPC). For Satellite clusters, the `link` endpoint is the default.

**Deprecated reference**

Expand Down

0 comments on commit e644eed

Please sign in to comment.