@@ -66,11 +66,21 @@ func ResourceTencentCloudKeyPair() *schema.Resource {
6666 Optional : true ,
6767 Description : "Tags of the key pair." ,
6868 },
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+ },
6979 },
7080 }
7181}
7282
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 ) {
7484 logId := tccommon .GetLogId (ctx )
7585 request := cvm .NewCreateKeyPairRequest ()
7686 response := cvm .NewCreateKeyPairResponse ()
@@ -98,6 +108,9 @@ func cvmCreateKeyPair(ctx context.Context, d *schema.ResourceData, meta interfac
98108 }
99109
100110 keyId = * response .Response .KeyPair .KeyId
111+ if response .Response .KeyPair .PrivateKey != nil {
112+ privateKey = * response .Response .KeyPair .PrivateKey
113+ }
101114 return
102115}
103116
@@ -139,20 +152,24 @@ func resourceTencentCloudKeyPairCreate(d *schema.ResourceData, meta interface{})
139152 logId := tccommon .GetLogId (tccommon .ContextNil )
140153 ctx := context .WithValue (context .TODO (), tccommon .LogIdKey , logId )
141154 var (
142- keyId string
143- err error
155+ keyId , privateKey string
156+ err error
144157 )
145158
146159 if _ , ok := d .GetOk ("public_key" ); ok {
147160 keyId , err = cvmCreateKeyPairByImportPublicKey (ctx , d , meta )
148161 } else {
149- keyId , err = cvmCreateKeyPair (ctx , d , meta )
162+ keyId , privateKey , err = cvmCreateKeyPair (ctx , d , meta )
150163 }
151164 if err != nil {
152165 return err
153166 }
154167 d .SetId (keyId )
155168
169+ if privateKey != "" {
170+ _ = d .Set ("private_key" , privateKey )
171+ }
172+
156173 if tags := helper .GetTags (d , "tags" ); len (tags ) > 0 {
157174 tcClient := meta .(tccommon.ProviderMeta ).GetAPIV3Conn ()
158175 tagService := svctag .NewTagService (tcClient )
@@ -204,6 +221,14 @@ func resourceTencentCloudKeyPairRead(d *schema.ResourceData, meta interface{}) e
204221 _ = d .Set ("public_key" , publicKey )
205222 }
206223
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+
207232 client := meta .(tccommon.ProviderMeta ).GetAPIV3Conn ()
208233 tagService := svctag .NewTagService (client )
209234
0 commit comments