@@ -66,11 +66,21 @@ func ResourceTencentCloudKeyPair() *schema.Resource {
66
66
Optional : true ,
67
67
Description : "Tags of the key pair." ,
68
68
},
69
+ "private_key" : {
70
+ Type : schema .TypeString ,
71
+ Computed : true ,
72
+ Description : "Content of private key in a key pair. Tencent Cloud do not keep private keys. Please keep it properly." ,
73
+ },
74
+ "created_time" : {
75
+ Type : schema .TypeString ,
76
+ Computed : true ,
77
+ Description : "Creation time, which follows the `ISO8601` standard and uses `UTC` time in the format of `YYYY-MM-DDThh:mm:ssZ`." ,
78
+ },
69
79
},
70
80
}
71
81
}
72
82
73
- func cvmCreateKeyPair (ctx context.Context , d * schema.ResourceData , meta interface {}) (keyId string , err error ) {
83
+ func cvmCreateKeyPair (ctx context.Context , d * schema.ResourceData , meta interface {}) (keyId , privateKey string , err error ) {
74
84
logId := tccommon .GetLogId (ctx )
75
85
request := cvm .NewCreateKeyPairRequest ()
76
86
response := cvm .NewCreateKeyPairResponse ()
@@ -98,6 +108,9 @@ func cvmCreateKeyPair(ctx context.Context, d *schema.ResourceData, meta interfac
98
108
}
99
109
100
110
keyId = * response .Response .KeyPair .KeyId
111
+ if response .Response .KeyPair .PrivateKey != nil {
112
+ privateKey = * response .Response .KeyPair .PrivateKey
113
+ }
101
114
return
102
115
}
103
116
@@ -139,20 +152,24 @@ func resourceTencentCloudKeyPairCreate(d *schema.ResourceData, meta interface{})
139
152
logId := tccommon .GetLogId (tccommon .ContextNil )
140
153
ctx := context .WithValue (context .TODO (), tccommon .LogIdKey , logId )
141
154
var (
142
- keyId string
143
- err error
155
+ keyId , privateKey string
156
+ err error
144
157
)
145
158
146
159
if _ , ok := d .GetOk ("public_key" ); ok {
147
160
keyId , err = cvmCreateKeyPairByImportPublicKey (ctx , d , meta )
148
161
} else {
149
- keyId , err = cvmCreateKeyPair (ctx , d , meta )
162
+ keyId , privateKey , err = cvmCreateKeyPair (ctx , d , meta )
150
163
}
151
164
if err != nil {
152
165
return err
153
166
}
154
167
d .SetId (keyId )
155
168
169
+ if privateKey != "" {
170
+ _ = d .Set ("private_key" , privateKey )
171
+ }
172
+
156
173
if tags := helper .GetTags (d , "tags" ); len (tags ) > 0 {
157
174
tcClient := meta .(tccommon.ProviderMeta ).GetAPIV3Conn ()
158
175
tagService := svctag .NewTagService (tcClient )
@@ -204,6 +221,14 @@ func resourceTencentCloudKeyPairRead(d *schema.ResourceData, meta interface{}) e
204
221
_ = d .Set ("public_key" , publicKey )
205
222
}
206
223
224
+ if keyPair .PrivateKey != nil {
225
+ _ = d .Set ("private_key" , keyPair .PrivateKey )
226
+ }
227
+
228
+ if keyPair .CreatedTime != nil {
229
+ _ = d .Set ("created_time" , keyPair .CreatedTime )
230
+ }
231
+
207
232
client := meta .(tccommon.ProviderMeta ).GetAPIV3Conn ()
208
233
tagService := svctag .NewTagService (client )
209
234
0 commit comments