@@ -2,6 +2,8 @@ package cloudprovider
2
2
3
3
import (
4
4
"context"
5
+ "fmt"
6
+ "strings"
5
7
6
8
"github.com/grafana/terraform-provider-grafana/v3/internal/common"
7
9
"github.com/grafana/terraform-provider-grafana/v3/internal/common/cloudproviderapi"
@@ -109,6 +111,36 @@ func (r *resourceAzureCredential) Schema(ctx context.Context, req resource.Schem
109
111
}
110
112
}
111
113
114
+ func (r * resourceAzureCredential ) ImportState (ctx context.Context , req resource.ImportStateRequest , resp * resource.ImportStateResponse ) {
115
+ parts := strings .SplitN (req .ID , ":" , 2 )
116
+ if len (parts ) != 2 || parts [0 ] == "" || parts [1 ] == "" {
117
+ resp .Diagnostics .AddError ("Invalid ID" , fmt .Sprintf ("Invalid ID: %s" , req .ID ))
118
+ return
119
+ }
120
+ stackID := parts [0 ]
121
+ resourceID := parts [1 ]
122
+
123
+ credentials , err := r .client .GetAzureCredential (
124
+ ctx ,
125
+ stackID ,
126
+ resourceID ,
127
+ )
128
+ if err != nil {
129
+ resp .Diagnostics .AddError ("Failed to get Azure credential" , err .Error ())
130
+ return
131
+ }
132
+
133
+ resp .State .Set (ctx , & resourceAzureCredentialModel {
134
+ ID : types .StringValue (req .ID ),
135
+ Name : types .StringValue (credentials .Name ),
136
+ TenantID : types .StringValue (credentials .TenantID ),
137
+ ClientID : types .StringValue (credentials .ClientID ),
138
+ StackID : types .StringValue (stackID ),
139
+ ResourceID : types .StringValue (resourceID ),
140
+ ClientSecret : types .StringValue ("" ), // We don't import the client secret
141
+ })
142
+ }
143
+
112
144
func (r * resourceAzureCredential ) Create (ctx context.Context , req resource.CreateRequest , resp * resource.CreateResponse ) {
113
145
var data resourceAzureCredentialModel
114
146
diags := req .Plan .Get (ctx , & data )
0 commit comments