@@ -2,7 +2,6 @@ package datadog
2
2
3
3
import (
4
4
"context"
5
- "net/http"
6
5
7
6
"github.com/terraform-providers/terraform-provider-datadog/datadog/internal/utils"
8
7
@@ -28,12 +27,6 @@ func resourceDatadogApplicationKey() *schema.Resource {
28
27
Type : schema .TypeString ,
29
28
Required : true ,
30
29
},
31
- "service_account" : {
32
- Description : "ID of a service account that owns the Application Key." ,
33
- Type : schema .TypeString ,
34
- ForceNew : true ,
35
- Optional : true ,
36
- },
37
30
"key" : {
38
31
Description : "The value of the Application Key." ,
39
32
Type : schema .TypeString ,
@@ -73,32 +66,12 @@ func updateApplicationKeyState(d *schema.ResourceData, applicationKeyData *datad
73
66
return nil
74
67
}
75
68
76
- func updatePartialApplicationKeyState (d * schema.ResourceData , applicationKeyData * datadogV2.PartialApplicationKey ) diag.Diagnostics {
77
- applicationKeyAttributes := applicationKeyData .GetAttributes ()
78
-
79
- if err := d .Set ("name" , applicationKeyAttributes .GetName ()); err != nil {
80
- return diag .FromErr (err )
81
- }
82
- return nil
83
- }
84
-
85
69
func resourceDatadogApplicationKeyCreate (ctx context.Context , d * schema.ResourceData , meta interface {}) diag.Diagnostics {
86
70
providerConf := meta .(* ProviderConfiguration )
87
71
apiInstances := providerConf .DatadogApiInstances
88
72
auth := providerConf .Auth
89
73
90
- var resp datadogV2.ApplicationKeyResponse
91
- var httpResponse * http.Response
92
- var err error
93
-
94
- req := buildDatadogApplicationKeyCreateV2Struct (d )
95
-
96
- if v , ok := d .GetOk ("service_account" ); ok {
97
- resp , httpResponse , err = apiInstances .GetServiceAccountsApiV2 ().CreateServiceAccountApplicationKey (auth , v .(string ), * req )
98
- } else {
99
- resp , httpResponse , err = apiInstances .GetKeyManagementApiV2 ().CreateCurrentUserApplicationKey (auth , * req )
100
- }
101
-
74
+ resp , httpResponse , err := apiInstances .GetKeyManagementApiV2 ().CreateCurrentUserApplicationKey (auth , * buildDatadogApplicationKeyCreateV2Struct (d ))
102
75
if err != nil {
103
76
return utils .TranslateClientErrorDiag (err , httpResponse , "error creating application key" )
104
77
}
@@ -114,68 +87,37 @@ func resourceDatadogApplicationKeyRead(ctx context.Context, d *schema.ResourceDa
114
87
apiInstances := providerConf .DatadogApiInstances
115
88
auth := providerConf .Auth
116
89
117
- if v , ok := d .GetOk ("service_account" ); ok {
118
- resp , httpResponse , err := apiInstances .GetServiceAccountsApiV2 ().GetServiceAccountApplicationKey (auth , v .(string ), d .Id ())
119
- if err != nil {
120
- if httpResponse != nil && httpResponse .StatusCode == 404 {
121
- d .SetId ("" )
122
- return nil
123
- }
124
- return utils .TranslateClientErrorDiag (err , httpResponse , "error getting application key" )
125
- }
126
- applicationKeyData := resp .GetData ()
127
- return updatePartialApplicationKeyState (d , & applicationKeyData )
128
- } else {
129
- resp , httpResponse , err := apiInstances .GetKeyManagementApiV2 ().GetCurrentUserApplicationKey (auth , d .Id ())
130
- if err != nil {
131
- if httpResponse != nil && httpResponse .StatusCode == 404 {
132
- d .SetId ("" )
133
- return nil
134
- }
135
- return utils .TranslateClientErrorDiag (err , httpResponse , "error getting application key" )
90
+ resp , httpResponse , err := apiInstances .GetKeyManagementApiV2 ().GetCurrentUserApplicationKey (auth , d .Id ())
91
+ if err != nil {
92
+ if httpResponse != nil && httpResponse .StatusCode == 404 {
93
+ d .SetId ("" )
94
+ return nil
136
95
}
137
- applicationKeyData := resp .GetData ()
138
- return updateApplicationKeyState (d , & applicationKeyData )
96
+ return utils .TranslateClientErrorDiag (err , httpResponse , "error getting application key" )
139
97
}
98
+ applicationKeyData := resp .GetData ()
99
+ return updateApplicationKeyState (d , & applicationKeyData )
140
100
}
141
101
142
102
func resourceDatadogApplicationKeyUpdate (ctx context.Context , d * schema.ResourceData , meta interface {}) diag.Diagnostics {
143
103
providerConf := meta .(* ProviderConfiguration )
144
104
apiInstances := providerConf .DatadogApiInstances
145
105
auth := providerConf .Auth
146
106
147
- if v , ok := d .GetOk ("service_account" ); ok {
148
- resp , httpResponse , err := apiInstances .GetServiceAccountsApiV2 ().UpdateServiceAccountApplicationKey (auth , v .(string ), d .Id (), * buildDatadogApplicationKeyUpdateV2Struct (d ))
149
- if err != nil {
150
- return utils .TranslateClientErrorDiag (err , httpResponse , "error updating application key" )
151
- }
152
- applicationKeyData := resp .GetData ()
153
- return updatePartialApplicationKeyState (d , & applicationKeyData )
154
- } else {
155
- resp , httpResponse , err := apiInstances .GetKeyManagementApiV2 ().UpdateCurrentUserApplicationKey (auth , d .Id (), * buildDatadogApplicationKeyUpdateV2Struct (d ))
156
- if err != nil {
157
- return utils .TranslateClientErrorDiag (err , httpResponse , "error updating application key" )
158
- }
159
- applicationKeyData := resp .GetData ()
160
- return updateApplicationKeyState (d , & applicationKeyData )
107
+ resp , httpResponse , err := apiInstances .GetKeyManagementApiV2 ().UpdateCurrentUserApplicationKey (auth , d .Id (), * buildDatadogApplicationKeyUpdateV2Struct (d ))
108
+ if err != nil {
109
+ return utils .TranslateClientErrorDiag (err , httpResponse , "error updating application key" )
161
110
}
111
+ applicationKeyData := resp .GetData ()
112
+ return updateApplicationKeyState (d , & applicationKeyData )
162
113
}
163
114
164
115
func resourceDatadogApplicationKeyDelete (ctx context.Context , d * schema.ResourceData , meta interface {}) diag.Diagnostics {
165
116
providerConf := meta .(* ProviderConfiguration )
166
117
apiInstances := providerConf .DatadogApiInstances
167
118
auth := providerConf .Auth
168
119
169
- var httpResponse * http.Response
170
- var err error
171
-
172
- if v , ok := d .GetOk ("service_account" ); ok {
173
- httpResponse , err = apiInstances .GetServiceAccountsApiV2 ().DeleteServiceAccountApplicationKey (auth , v .(string ), d .Id ())
174
- } else {
175
- httpResponse , err = apiInstances .GetKeyManagementApiV2 ().DeleteCurrentUserApplicationKey (auth , d .Id ())
176
- }
177
-
178
- if err != nil {
120
+ if httpResponse , err := apiInstances .GetKeyManagementApiV2 ().DeleteCurrentUserApplicationKey (auth , d .Id ()); err != nil {
179
121
return utils .TranslateClientErrorDiag (err , httpResponse , "error deleting application key" )
180
122
}
181
123
0 commit comments