diff --git a/.gitignore b/.gitignore index a1a4a4f..87d7a9e 100644 --- a/.gitignore +++ b/.gitignore @@ -68,4 +68,5 @@ gen temp/** -.vscode/ \ No newline at end of file +.vscode/ +sa_key.json diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7a5410b..b23dd88 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -21,3 +21,36 @@ If you would like to contribute code to this project, fork the repository and se | MacOS(amd64) | ~/.terraform.d/plugins/registry.terraform.io/streamnative/streamnative/0.1.0/darwin_amd64/ | - Run `make build-dev`, it will build the binary and copy it to the plugin directory automatically. + +## OR + +## Using .terraformrc + +- Make sure GOBIN is set (if not set it to `/Users//go/bin`) +- Create a file in `~` named `.terraformrc` +- Add the following into the file +``` +provider_installation { + + dev_overrides { + "terraform.local/local/streamnative" = "/Users//go/bin" #Or your GOBIN if it's defined as a different path + } + + # For all other providers, install them directly from their origin provider + # registries as normal. If you omit this, Terraform will _only_ use + # the dev_overrides block, and so no other providers will be available. + direct {} +} +``` +- Run `go install .` in the provider root +- Use the provider in terraform like so +``` +terraform { + required_providers { + streamnative = { + source = "terraform.local/local/streamnative" + } + } +} +``` +- Run a terraform plan and terraform should use the newly built copy \ No newline at end of file diff --git a/cloud/cloud_connection_cloud_provider.go b/cloud/cloud_connection_cloud_provider.go index 2e3cf4b..a34192b 100644 --- a/cloud/cloud_connection_cloud_provider.go +++ b/cloud/cloud_connection_cloud_provider.go @@ -35,3 +35,24 @@ func flattenCloudConnectionGCP(in *cloudv1alpha1.GCPCloudConnection) []interface return []interface{}{att} } + +func flattenCloudConnectionAzure(in *cloudv1alpha1.AzureConnection) []interface{} { + att := make(map[string]interface{}) + if in.SubscriptionId != "" { + att["subscription_id"] = in.SubscriptionId + } + + if in.TenantId != "" { + att["tenant_id"] = in.TenantId + } + + if in.ClientId != "" { + att["client_id"] = in.ClientId + } + + if in.SupportClientId != "" { + att["support_client_id"] = in.SupportClientId + } + + return []interface{}{att} +} diff --git a/cloud/data_source_cloud_connection.go b/cloud/data_source_cloud_connection.go index 01721a9..e33a0b6 100644 --- a/cloud/data_source_cloud_connection.go +++ b/cloud/data_source_cloud_connection.go @@ -82,6 +82,31 @@ func dataSourceCloudConnection() *schema.Resource { }, }, }, + "azure": { + Type: schema.TypeList, + Computed: true, + Description: descriptions["azure"], + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "subscription_id": { + Type: schema.TypeString, + Optional: true, + }, + "tenant_id": { + Type: schema.TypeString, + Optional: true, + }, + "client_id": { + Type: schema.TypeString, + Optional: true, + }, + "support_client_id": { + Type: schema.TypeString, + Optional: true, + }, + }, + }, + }, }, } } @@ -116,6 +141,13 @@ func dataSourceCloudConnectionRead(ctx context.Context, d *schema.ResourceData, } } + if cloudConnection.Spec.Azure != nil { + err = d.Set("azure", flattenCloudConnectionAzure(cloudConnection.Spec.Azure)) + if err != nil { + return diag.FromErr(fmt.Errorf("ERROR_READ_CLOUD_CONNECTION_CONFIG: %w", err)) + } + } + d.SetId(fmt.Sprintf("%s/%s", cloudConnection.Namespace, cloudConnection.Name)) return nil diff --git a/cloud/provider.go b/cloud/provider.go index 9492e2d..c9b7b58 100644 --- a/cloud/provider.go +++ b/cloud/provider.go @@ -89,6 +89,7 @@ func init() { "type": "Type of cloud connection, one of aws or gcp", "aws": "AWS configuration for the connection", "gcp": "GCP configuration for the connection", + "azure": "Azure configuration for the connection", "cloud_connection_name": "Name of the cloud connection", "cloud_environment_name": "Name of the cloud environment", } diff --git a/cloud/resource_cloud_connection.go b/cloud/resource_cloud_connection.go index 5b9cccf..41277ac 100644 --- a/cloud/resource_cloud_connection.go +++ b/cloud/resource_cloud_connection.go @@ -106,6 +106,31 @@ func resourceCloudConnection() *schema.Resource { }, }, }, + "azure": { + Type: schema.TypeList, + Optional: true, + Description: descriptions["azure"], + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "subscription_id": { + Type: schema.TypeString, + Optional: true, + }, + "tenant_id": { + Type: schema.TypeString, + Optional: true, + }, + "client_id": { + Type: schema.TypeString, + Optional: true, + }, + "support_client_id": { + Type: schema.TypeString, + Optional: true, + }, + }, + }, + }, }, } } @@ -116,6 +141,7 @@ func resourceCloudConnectionCreate(ctx context.Context, d *schema.ResourceData, connectionType := d.Get("type").(string) aws := d.Get("aws").([]interface{}) gcp := d.Get("gcp").([]interface{}) + azure := d.Get("azure").([]interface{}) clientSet, err := getClientSet(getFactoryFromMeta(meta)) if err != nil { return diag.FromErr(fmt.Errorf("ERROR_INIT_CLIENT_ON_CLOUD_CONNECTION: %w", err)) @@ -135,6 +161,7 @@ func resourceCloudConnectionCreate(ctx context.Context, d *schema.ResourceData, ConnectionType: cloudv1alpha1.ConnectionType(connectionType), AWS: nil, GCP: nil, + Azure: nil, }, } @@ -160,8 +187,27 @@ func resourceCloudConnectionCreate(ctx context.Context, d *schema.ResourceData, } } - if cloudConnection.Spec.AWS == nil && cloudConnection.Spec.GCP == nil { - return diag.FromErr(fmt.Errorf("ERROR_CREATE_CLOUD_CONNECTION: " + "One of aws.accountId or gcp.project_id must be set")) + if len(azure) > 0 { + cloudConnection.Spec.Azure = &cloudv1alpha1.AzureConnection{} + for _, azureItem := range azure { + azureItemMap := azureItem.(map[string]interface{}) + if azureItemMap["subscription_id"] != nil { + cloudConnection.Spec.Azure.SubscriptionId = azureItemMap["subscription_id"].(string) + } + if azureItemMap["tenant_id"] != nil { + cloudConnection.Spec.Azure.TenantId = azureItemMap["tenant_id"].(string) + } + if azureItemMap["client_id"] != nil { + cloudConnection.Spec.Azure.ClientId = azureItemMap["client_id"].(string) + } + if azureItemMap["support_client_id"] != nil { + cloudConnection.Spec.Azure.SupportClientId = azureItemMap["support_client_id"].(string) + } + } + } + + if cloudConnection.Spec.AWS == nil && cloudConnection.Spec.GCP == nil && cloudConnection.Spec.Azure == nil { + return diag.FromErr(fmt.Errorf("ERROR_CREATE_CLOUD_CONNECTION: " + "One of aws.account_id, gcp.project_id or azure block must be set")) } cc, err := clientSet.CloudV1alpha1().CloudConnections(namespace).Create(ctx, cloudConnection, metav1.CreateOptions{ @@ -221,6 +267,14 @@ func resourceCloudConnectionRead(ctx context.Context, d *schema.ResourceData, me return diag.FromErr(fmt.Errorf("ERROR_READ_CLOUD_CONNECTION_GCP: %w", err)) } } + + if cloudConnection.Spec.Azure != nil { + err = d.Set("azure", flattenCloudConnectionAzure(cloudConnection.Spec.Azure)) + if err != nil { + return diag.FromErr(fmt.Errorf("ERROR_READ_CLOUD_CONNECTION_AZURE: %w", err)) + } + } + d.SetId(fmt.Sprintf("%s/%s", cloudConnection.Namespace, cloudConnection.Name)) return nil } diff --git a/docs/data-sources/cloud_connection.md b/docs/data-sources/cloud_connection.md index 7df7431..2494315 100644 --- a/docs/data-sources/cloud_connection.md +++ b/docs/data-sources/cloud_connection.md @@ -23,6 +23,7 @@ description: |- ### Read-Only - `aws` (List of Object) AWS configuration for the connection (see [below for nested schema](#nestedatt--aws)) +- `azure` (List of Object) Azure configuration for the connection (see [below for nested schema](#nestedatt--azure)) - `gcp` (List of Object) GCP configuration for the connection (see [below for nested schema](#nestedatt--gcp)) - `id` (String) The ID of this resource. - `type` (String) Type of cloud connection, one of aws or gcp @@ -35,6 +36,17 @@ Read-Only: - `account_id` (String) + +### Nested Schema for `azure` + +Read-Only: + +- `client_id` (String) +- `subscription_id` (String) +- `support_client_id` (String) +- `tenant_id` (String) + + ### Nested Schema for `gcp` diff --git a/docs/index.md b/docs/index.md index c025f95..33fb5d1 100644 --- a/docs/index.md +++ b/docs/index.md @@ -15,6 +15,6 @@ description: |- ## Schema -### Optional +### Required - `key_file_path` (String) The path of the private key file diff --git a/docs/resources/cloud_connection.md b/docs/resources/cloud_connection.md index ff6806c..bd81bd0 100644 --- a/docs/resources/cloud_connection.md +++ b/docs/resources/cloud_connection.md @@ -24,6 +24,7 @@ description: |- ### Optional - `aws` (Block List) AWS configuration for the connection (see [below for nested schema](#nestedblock--aws)) +- `azure` (Block List) Azure configuration for the connection (see [below for nested schema](#nestedblock--azure)) - `gcp` (Block List) GCP configuration for the connection (see [below for nested schema](#nestedblock--gcp)) ### Read-Only @@ -38,6 +39,17 @@ Optional: - `account_id` (String) + +### Nested Schema for `azure` + +Optional: + +- `client_id` (String) +- `subscription_id` (String) +- `support_client_id` (String) +- `tenant_id` (String) + + ### Nested Schema for `gcp`