Skip to content

Commit 3a16d2f

Browse files
authored
Merge branch 'main' into feat-drift-remediation-#1011
2 parents 19ddb3f + 47014e9 commit 3a16d2f

File tree

12 files changed

+453
-0
lines changed

12 files changed

+453
-0
lines changed

client/cloud_account.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ type AWSCloudAccountConfiguration struct {
2121
ShouldPrefixUnderLogsFolder bool `json:"shouldPrefixUnderLogsFolder"`
2222
}
2323

24+
type AzureCloudAccountConfiguration struct {
25+
TenantId string `json:"tenantId"`
26+
ClientId string `json:"clientId"`
27+
LogAnalyticsWorkspaceId string `json:"logAnalyticsWorkspaceId"`
28+
}
29+
2430
type CloudAccount struct {
2531
Id string `json:"id"`
2632
Provider string `json:"provider"`

client/cloud_account_test.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,30 @@ var _ = Describe("CloudAccount", func() {
4545
Configuration: []string{"some random configuration"},
4646
}
4747

48+
azureConfiguration := AzureCloudAccountConfiguration{
49+
TenantId: "tenant123",
50+
ClientId: "client123",
51+
LogAnalyticsWorkspaceId: "workspace123",
52+
}
53+
54+
azureConfigurationUpdated := AzureCloudAccountConfiguration{
55+
TenantId: "tenant456",
56+
ClientId: "client456",
57+
LogAnalyticsWorkspaceId: "workspace456",
58+
}
59+
60+
azureAccount := CloudAccount{
61+
Id: "id3",
62+
Provider: "Azure",
63+
Name: "azure1",
64+
Health: true,
65+
Configuration: &azureConfiguration,
66+
}
67+
68+
azureAccountUpdated := azureAccount
69+
azureAccountUpdated.Name = "updatedazure1"
70+
azureAccountUpdated.Configuration = azureConfigurationUpdated
71+
4872
Describe("create", func() {
4973
BeforeEach(func() {
5074
mockOrganizationIdCall()
@@ -83,6 +107,40 @@ var _ = Describe("CloudAccount", func() {
83107
It("should not return error", func() {
84108
Expect(err).To(BeNil())
85109
})
110+
111+
Context("when creating an Azure configuration", func() {
112+
BeforeEach(func() {
113+
payload := CloudAccountCreatePayload{
114+
Provider: azureAccount.Provider,
115+
Name: azureAccount.Name,
116+
Configuration: azureAccount.Configuration,
117+
}
118+
119+
payloadWithOrganizationId := struct {
120+
*CloudAccountCreatePayload
121+
OrganizationId string `json:"organizationId"`
122+
}{
123+
&payload,
124+
organizationId,
125+
}
126+
127+
httpCall = mockHttpClient.EXPECT().
128+
Post("/cloud/configurations", &payloadWithOrganizationId, gomock.Any()).
129+
Do(func(path string, request interface{}, response *CloudAccount) {
130+
*response = azureAccount
131+
}).Times(1)
132+
133+
account, err = apiClient.CloudAccountCreate(&payload)
134+
})
135+
136+
It("should return azure account", func() {
137+
Expect(*account).To(Equal(azureAccount))
138+
})
139+
140+
It("should not return error", func() {
141+
Expect(err).To(BeNil())
142+
})
143+
})
86144
})
87145

88146
Describe("update", func() {
@@ -148,6 +206,7 @@ var _ = Describe("CloudAccount", func() {
148206
mockedAccounts := []CloudAccount{
149207
account1,
150208
account2,
209+
azureAccount,
151210
}
152211

153212
BeforeEach(func() {
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "env0_azure_cloud_configuration Resource - terraform-provider-env0"
4+
subcategory: ""
5+
description: |-
6+
configure an Azure cloud account (Cloud Compass)
7+
---
8+
9+
# env0_azure_cloud_configuration (Resource)
10+
11+
configure an Azure cloud account (Cloud Compass)
12+
13+
## Example Usage
14+
15+
```terraform
16+
resource "env0_azure_cloud_configuration" "example" {
17+
name = "example"
18+
tenant_id = "11111111-2222-3333-4444-555555555555"
19+
client_id = "66666666-7777-8888-9999-000000000000"
20+
log_analytics_workspace_id = "12345678-90ab-cdef-1234-567890abcdef"
21+
}
22+
```
23+
24+
<!-- schema generated by tfplugindocs -->
25+
## Schema
26+
27+
### Required
28+
29+
- `client_id` (String) the Azure client ID
30+
- `log_analytics_workspace_id` (String) the Azure Log Analytics Workspace ID
31+
- `name` (String) name for the cloud configuration for insights
32+
- `tenant_id` (String) the Azure tenant ID
33+
34+
### Read-Only
35+
36+
- `health` (Boolean) an indicator if the configuration is valid
37+
- `id` (String) The ID of this resource.
38+
39+
## Import
40+
41+
Import is supported using the following syntax:
42+
43+
```shell
44+
terraform import env0_azure_cloud_configuration.by_id d31a6b30-5f69-4d24-937c-22322754934e
45+
terraform import env0_azure_cloud_configuration.by_name "azure cloud configuration name"
46+
```

env0/cloud_configuration.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ func getCloudConfigurationFromSchema(d *schema.ResourceData, provider string) (i
1919
switch provider {
2020
case "AWS":
2121
configuration = &client.AWSCloudAccountConfiguration{}
22+
case "AzureLAW":
23+
configuration = &client.AzureCloudAccountConfiguration{}
2224
default:
2325
return nil, fmt.Errorf("unhandled provider: %s", provider)
2426
}
@@ -69,6 +71,8 @@ func getCloudConfigurationFromApi(apiClient client.ApiClientInterface, id string
6971
switch cloudAccount.Provider {
7072
case "AWS":
7173
configuration = &client.AWSCloudAccountConfiguration{}
74+
case "AzureLAW":
75+
configuration = &client.AzureCloudAccountConfiguration{}
7276
default:
7377
return nil, fmt.Errorf("unhandled provider: %s", cloudAccount.Provider)
7478
}

env0/provider.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ func Provider(version string) plugin.ProviderFunc {
162162
"env0_variable_set_assignment": resourceVariableSetAssignment(),
163163
"env0_environment_output_configuration_variable": resourceEnvironmentOutputConfigurationVariable(),
164164
"env0_aws_cloud_configuration": resourceAwsCloudConfiguration(),
165+
"env0_azure_cloud_configuration": resourceAzureCloudConfiguration(),
165166
"env0_vcs_connection": resourceVcsConnection(),
166167
},
167168
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package env0
2+
3+
import (
4+
"context"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
7+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
8+
)
9+
10+
func resourceAzureCloudConfiguration() *schema.Resource {
11+
return &schema.Resource{
12+
CreateContext: resourceAzureCloudConfigurationCreate,
13+
UpdateContext: resourceAzureCloudConfigurationUpdate,
14+
ReadContext: readCloudConfiguration,
15+
DeleteContext: deleteCloudConfiguration,
16+
17+
Importer: &schema.ResourceImporter{StateContext: importCloudConfiguration},
18+
19+
Description: "configure an Azure cloud account (Cloud Compass)",
20+
21+
Schema: map[string]*schema.Schema{
22+
"name": {
23+
Type: schema.TypeString,
24+
Description: "name for the cloud configuration for insights",
25+
Required: true,
26+
},
27+
"tenant_id": {
28+
Type: schema.TypeString,
29+
Description: "the Azure tenant ID",
30+
Required: true,
31+
},
32+
"client_id": {
33+
Type: schema.TypeString,
34+
Description: "the Azure client ID",
35+
Required: true,
36+
},
37+
"log_analytics_workspace_id": {
38+
Type: schema.TypeString,
39+
Description: "the Azure Log Analytics Workspace ID",
40+
Required: true,
41+
},
42+
"health": {
43+
Type: schema.TypeBool,
44+
Computed: true,
45+
Description: "an indicator if the configuration is valid",
46+
},
47+
},
48+
}
49+
}
50+
51+
func resourceAzureCloudConfigurationCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
52+
return createCloudConfiguration(d, meta, "AzureLAW")
53+
}
54+
55+
func resourceAzureCloudConfigurationUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
56+
return updateCloudConfiguration(d, meta, "AzureLAW")
57+
}

0 commit comments

Comments
 (0)