Skip to content

Commit d413bbd

Browse files
authored
Service principal fix and plugin name fixes (#7)
* Fix for service principal auth (#7) Signed-off-by: Viorel Dodin <vdodin@cisco.com> * Fix naming from cop to observability (#8) Various errors were encountered during testing. Binnary plugin name and provider name must match. Signed-off-by: Viorel Dodin <vdodin@cisco.com> --------- Signed-off-by: Viorel Dodin <vdodin@cisco.com>
1 parent 6b8870c commit d413bbd

File tree

8 files changed

+38
-43
lines changed

8 files changed

+38
-43
lines changed

examples/data-sources/cop_example/data-source.tf

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,24 @@
66

77
terraform {
88
required_providers {
9-
cop = {
10-
source = "testTerraform.com/appd/cop"
9+
observability = {
10+
source = "testTerraform.com/appd/observability"
1111
}
1212
}
1313
}
1414

15-
provider "cop" {
16-
tenant = "47a01df9-54a0-472b-96b8-7c8f64eb7cbf"
17-
auth_method = "oauth"
18-
url = "https://alameda-c0-test-02.saas.appd-test.com"
15+
provider "observability" {
16+
tenant="0eb4e853-34fb-4f77-b3fc-b9cd3b462366"
17+
auth_method="service-principal"
18+
url="https://aiops-dev.saas.appd-test.com"
19+
secrets_file="/home/vdodin/aiops_secret.json"
1920
}
2021

2122

22-
data "cop_type" "ns" {
23+
data "observability_type" "ns" {
2324
type_name = "fmm:namespace"
2425
}
2526

2627
output "myType" {
27-
value = data.cop_type.ns
28+
value = data.observability_type.ns
2829
}

examples/provider/provider_oauth.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66

77
terraform {
88
required_providers {
9-
cop = {
10-
source = "testTerraform.com/appd/cop"
9+
observability = {
10+
source = "testTerraform.com/appd/observability"
1111
}
1212
}
1313
}
1414

15-
provider "cop" {
15+
provider "observability" {
1616
tenant="47a01df9-54a0-472b-96b8-7c8f64eb7cbf"
1717
auth_method="oauth"
1818
url="https://alameda-c0-test-02.saas.appd-test.com"

examples/provider/provider_service_principal.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66

77
terraform {
88
required_providers {
9-
cop = {
10-
source = "testTerraform.com/appd/cop"
9+
observability = {
10+
source = "testTerraform.com/appd/observability"
1111
}
1212
}
1313
}
1414

15-
provider "cop" {
15+
provider "observability" {
1616
tenant="47a01df9-54a0-472b-96b8-7c8f64eb7cbf"
1717
auth_method="service-principal"
1818
url="https://alameda-c0-test-02.saas.appd-test.com"

examples/resources/cop_example/resource.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@
66

77
terraform {
88
required_providers {
9-
cop = {
10-
source = "testTerraform.com/appd/cop"
9+
observability = {
10+
source = "testTerraform.com/appd/observability"
1111
}
1212
}
1313
}
1414

15-
provider "cop" {
15+
provider "observability" {
1616
tenant = "47a01df9-54a0-472b-96b8-7c8f64eb7cbf"
1717
auth_method = "oauth"
1818
url = "https://alameda-c0-test-02.saas.appd-test.com"
1919
}
2020

21-
resource "cop_object" "ns" {
21+
resource "observability_object" "ns" {
2222
type_name = "fmm:namespace"
2323
object_id = "aws"
2424
layer_type = "TENANT"

internal/api/objectapi.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,7 @@ func (ac *AppdClient) GetObject(fullyQualifiedTypeName, objectID, layerID, layer
3434

3535
req.Header.Add("Content-Type", contentType)
3636
req.Header.Add("Accept", contentType)
37-
38-
if ac.AuthMethod == authMethodOAuth {
39-
req.Header.Add("Authorization", "Bearer "+ac.Token)
40-
}
37+
req.Header.Add("Authorization", "Bearer "+ac.Token)
4138

4239
req.Header.Add("layer-id", layerID)
4340
req.Header.Add("layer-type", layerType)

internal/api/typeapi.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,7 @@ func (ac *AppdClient) GetType(fullyQualifiedTypeName string) ([]byte, error) {
2727

2828
req.Header.Add("Content-Type", contentType)
2929
req.Header.Add("Accept", contentType)
30-
31-
if ac.AuthMethod == authMethodOAuth {
32-
req.Header.Add("Authorization", "Bearer "+ac.Token)
33-
}
30+
req.Header.Add("Authorization", "Bearer "+ac.Token)
3431

3532
// Do request
3633
resp, err := ac.APIClient.Do(req)

internal/provider/provider.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ type COPProviderModel struct {
4141
}
4242

4343
func (p *COPProvider) Metadata(_ context.Context, _ provider.MetadataRequest, resp *provider.MetadataResponse) {
44-
resp.TypeName = "cop"
44+
resp.TypeName = "observability"
4545
resp.Version = p.version
4646
}
4747

4848
func (p *COPProvider) Schema(_ context.Context, _ provider.SchemaRequest, resp *provider.SchemaResponse) {
4949
resp.Schema = schema.Schema{
5050
Attributes: map[string]schema.Attribute{
5151
"auth_method": schema.StringAttribute{
52-
MarkdownDescription: "Authentication type selected for COP API requests. Possible values(oauth, headless, service-principal)",
52+
MarkdownDescription: "Authentication type selected for observability API requests. Possible values(oauth, headless, service-principal)",
5353
Required: true,
5454
},
5555
"tenant": schema.StringAttribute{
@@ -92,47 +92,47 @@ func (p *COPProvider) Configure(ctx context.Context, req provider.ConfigureReque
9292
if data.AuthMethod.IsUnknown() {
9393
resp.Diagnostics.AddAttributeError(
9494
path.Root("auth_method"),
95-
"Unknown cop API auth_method",
95+
"Unknown observability API auth_method",
9696
"Please make sure you configure the auth_method field",
9797
)
9898
}
9999

100100
if data.Tenant.IsUnknown() {
101101
resp.Diagnostics.AddAttributeError(
102102
path.Root("tenant"),
103-
"Unknown cop API tenant",
103+
"Unknown observability API tenant",
104104
"Please make sure you configure the tenant field",
105105
)
106106
}
107107

108108
if data.Username.IsUnknown() {
109109
resp.Diagnostics.AddAttributeError(
110110
path.Root("username"),
111-
"Unknown cop API username",
111+
"Unknown observability API username",
112112
"Please make sure you configure the username field",
113113
)
114114
}
115115

116116
if data.Password.IsUnknown() {
117117
resp.Diagnostics.AddAttributeError(
118118
path.Root("password"),
119-
"Unknown cop API password",
119+
"Unknown observability API password",
120120
"Please make sure you configure the password field",
121121
)
122122
}
123123

124124
if data.URL.IsUnknown() {
125125
resp.Diagnostics.AddAttributeError(
126126
path.Root("url"),
127-
"Unknown cop API url",
127+
"Unknown observability API url",
128128
"Please make sure you configure the url field",
129129
)
130130
}
131131

132132
if data.URL.IsUnknown() {
133133
resp.Diagnostics.AddAttributeError(
134134
path.Root("secrets_file"),
135-
"Unknown cop API secrets_file",
135+
"Unknown observability API secrets_file",
136136
"Please make sure you configure the secrets_file field",
137137
)
138138
}
@@ -186,7 +186,7 @@ func (p *COPProvider) Configure(ctx context.Context, req provider.ConfigureReque
186186
if authMethod == "" {
187187
resp.Diagnostics.AddAttributeError(
188188
path.Root("auth_method"),
189-
"Missing cop API auth_method",
189+
"Missing observability API auth_method",
190190
"SET the COP_AUTH_METHOD env var or the config",
191191
)
192192
tflog.Error(ctx, "Missing or empty value for auth_method attribute")
@@ -197,39 +197,39 @@ func (p *COPProvider) Configure(ctx context.Context, req provider.ConfigureReque
197197
if url == "" {
198198
resp.Diagnostics.AddAttributeError(
199199
path.Root("url"),
200-
"Missing cop API url",
200+
"Missing observability API url",
201201
"SET the COP_URL env var or the config",
202202
)
203203
}
204204

205205
if tenantID == "" {
206206
resp.Diagnostics.AddAttributeError(
207207
path.Root("tenant"),
208-
"Missing cop API tenant",
208+
"Missing observability API tenant",
209209
"SET the COP_TENANT env var or the config",
210210
)
211211
}
212212
case "headless":
213213
if username == "" {
214214
resp.Diagnostics.AddAttributeError(
215215
path.Root("username"),
216-
"Missing cop API username",
216+
"Missing observability API username",
217217
"SET the COP_USERNAME env var or the config",
218218
)
219219
}
220220

221221
if password == "" {
222222
resp.Diagnostics.AddAttributeError(
223223
path.Root("password"),
224-
"Missing cop API password",
224+
"Missing observability API password",
225225
"SET the COP_PASSWORD env var or the config",
226226
)
227227
}
228228
case "service-principal":
229229
if secretsFile == "" {
230230
resp.Diagnostics.AddAttributeError(
231231
path.Root("secrets_file"),
232-
"Missing cop API secrets_file",
232+
"Missing observability API secrets_file",
233233
"SET the SECRETS_FILE env var or the config",
234234
)
235235
}
@@ -253,10 +253,10 @@ func (p *COPProvider) Configure(ctx context.Context, req provider.ConfigureReque
253253

254254
err := appdClient.Login()
255255
if err != nil {
256-
tflog.Error(ctx, fmt.Sprintf("Failed to authenticate to COP client: %s", err.Error()))
256+
tflog.Error(ctx, fmt.Sprintf("Failed to authenticate to observability client: %s", err.Error()))
257257
}
258258

259-
tflog.Debug(ctx, fmt.Sprintf("Successful authentication to COP client using %s", appdClient.AuthMethod))
259+
tflog.Debug(ctx, fmt.Sprintf("Successful authentication to observability client using %s", appdClient.AuthMethod))
260260

261261
// TODO change this to a real client
262262
resp.DataSourceData = appdClient

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func main() {
4545
// TODO: Update this string with the published name of your provider.
4646
// Also update the tfplugindocs generate command to either remove the
4747
// -provider-name flag or set its value to the updated provider name.
48-
Address: "testTerraform.com/appd/cop",
48+
Address: "testTerraform.com/appd/observability",
4949
Debug: debug,
5050
}
5151

0 commit comments

Comments
 (0)