Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Commit

Permalink
Merge pull request #2 from jhernand/add_htpasswd_and_ldap_identity_pr…
Browse files Browse the repository at this point in the history
…oviders

Add initial support for identity providers
  • Loading branch information
jhernand authored Nov 10, 2021
2 parents f2b2bfc + 753ad85 commit 2eba41e
Show file tree
Hide file tree
Showing 8 changed files with 792 additions and 33 deletions.
6 changes: 2 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
*.log
.terraform.d/
.terraform.lock.hcl
.terraform/
terraform.tfstate
.terraform*
terraform.tfstate*
12 changes: 12 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Attach to provider",
"type": "go",
"request": "attach",
"mode": "local",
"processId": "${command:pickGoProcess}"
},
]
}
25 changes: 25 additions & 0 deletions examples/create_cluster/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,28 @@ resource "ocm_cluster" "my_cluster" {
fake_cluster = "true"
}
}

resource "ocm_identity_provider" "my_htpasswd" {
cluster_id = ocm_cluster.my_cluster.id
name = "my-htpasswd"
htpasswd {
user = "my-user"
password = "my-password"
}
}

resource "ocm_identity_provider" "my_ldap" {
cluster_id = ocm_cluster.my_cluster.id
name = "my-ldap"
ldap {
bind_dn = "my-bind-dn"
bind_password = "my-bind-password"
url = "https://my-server.com"
attributes {
id = ["my-id"]
email = ["my-email"]
name = ["my-name"]
preferred_username = ["my-preferred-username"]
}
}
}
43 changes: 26 additions & 17 deletions ocm/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,30 @@ limitations under the License.
package ocm

const (
clientIDKey = "client_id"
clientSecretKey = "client_secret"
cloudProviderKey = "cloud_provider"
cloudRegionKey = "cloud_region"
desiredStateKey = "desired_state"
idsKey = "ids"
insecureKey = "insecure"
nameKey = "name"
passwordKey = "password"
propertiesKey = "properties"
stateKey = "state"
tokenKey = "token"
tokenURLKey = "token_url"
trustedCAsKey = "trusted_cas"
urlKey = "url"
userKey = "user"
waitKey = "wait"
attributesKey = "attributes"
bindDNKey = "bind_dn"
bindPasswordKey = "bind_password"
caKey = "ca"
clientIDKey = "client_id"
clientSecretKey = "client_secret"
cloudProviderKey = "cloud_provider"
cloudRegionKey = "cloud_region"
clusterIDKey = "cluster_id"
emailKey = "email"
htpasswdKey = "htpasswd"
idKey = "id"
idsKey = "ids"
insecureKey = "insecure"
ldapKey = "ldap"
nameKey = "name"
passwordKey = "password"
preferredUsernameKey = "preferred_username"
propertiesKey = "properties"
stateKey = "state"
tokenKey = "token"
tokenURLKey = "token_url"
trustedCAsKey = "trusted_cas"
urlKey = "url"
userKey = "user"
waitKey = "wait"
)
3 changes: 2 additions & 1 deletion ocm/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ func Provider() *schema.Provider {
},
},
ResourcesMap: map[string]*schema.Resource{
"ocm_cluster": resourceCluster(),
"ocm_cluster": resourceCluster(),
"ocm_identity_provider": resourceIdentityProvider(),
},
DataSourcesMap: map[string]*schema.Resource{
"ocm_cloud_providers": dataSourceCloudProviders(),
Expand Down
15 changes: 4 additions & 11 deletions ocm/resource_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,6 @@ func resourceClusterCreate(ctx context.Context, data *schema.ResourceData,
return
}
cluster = addResponse.Body()
result = resourceClusterParse(cluster, data)
if result.HasError() {
return
}
}

// Wait till the cluster is ready:
Expand All @@ -126,10 +122,6 @@ func resourceClusterCreate(ctx context.Context, data *schema.ResourceData,

// Copy the cluster data:
result = resourceClusterParse(cluster, data)
if result.HasError() {
return
}

return
}

Expand Down Expand Up @@ -320,8 +312,9 @@ func resourceClusterLookup(ctx context.Context, connection *sdk.Connection,
}

// Try to locate the cluster using the name:
clusterName := data.Get("name").(string)
if clusterName != "" {
value, ok := data.GetOk(nameKey)
if ok {
clusterName := value.(string)
listResponse, err := clustersResource.List().
Search(fmt.Sprintf("name = '%s'", clusterName)).
Size(1).
Expand All @@ -330,7 +323,7 @@ func resourceClusterLookup(ctx context.Context, connection *sdk.Connection,
result = append(result, diag.Diagnostic{
Severity: diag.Error,
Summary: fmt.Sprintf(
"can't fetch clusters with name '%s'",
"can't find clusters with name '%s'",
clusterName,
),
Detail: err.Error(),
Expand Down
Loading

0 comments on commit 2eba41e

Please sign in to comment.