Skip to content

Commit

Permalink
Feat: env0_api_key resource and data source don't store apiKeyId (#582)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomerHeber committed Jan 31, 2023
1 parent 1f213c0 commit 5bf6b2d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
5 changes: 5 additions & 0 deletions env0/data_api_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ func dataApiKey() *schema.Resource {
Optional: true,
ExactlyOneOf: []string{"name", "id"},
},
"api_key_id": {
Type: schema.TypeString,
Computed: true,
Description: "the api key id",
},
},
}
}
Expand Down
1 change: 1 addition & 0 deletions env0/data_api_key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func TestApiKeyDataSource(t *testing.T) {
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(accessor, "id", apiKey.Id),
resource.TestCheckResourceAttr(accessor, "name", apiKey.Name),
resource.TestCheckResourceAttr(accessor, "api_key_id", apiKey.ApiKeyId),
),
},
},
Expand Down
13 changes: 9 additions & 4 deletions env0/resource_api_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ func resourceApiKey() *schema.Resource {
Optional: true,
ForceNew: true,
},
"api_key_id": {
Type: schema.TypeString,
Computed: true,
Description: "the api key id",
},
},
}
}
Expand All @@ -66,14 +71,14 @@ func resourceApiKeyCreate(ctx context.Context, d *schema.ResourceData, meta inte
return diag.Errorf("could not create api key: %v", err)
}

if err := writeResourceData(apiKey, d); err != nil {
return diag.Errorf("schema resource data serialization failed: %v", err)
}

if omit, ok := d.GetOk("omit_api_key_secret"); ok && omit.(bool) {
d.Set("api_key_secret", "omitted")
} else {
d.Set("api_key_secret", apiKey.ApiKeySecret)
}

d.SetId(apiKey.Id)

return nil
}

Expand Down
3 changes: 3 additions & 0 deletions env0/resource_api_key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func TestUnitApiKeyResource(t *testing.T) {
resource.TestCheckResourceAttr(accessor, "name", apiKey.Name),
resource.TestCheckResourceAttr(accessor, "organization_role", apiKey.OrganizationRole),
resource.TestCheckResourceAttr(accessor, "api_key_secret", apiKey.ApiKeySecret),
resource.TestCheckResourceAttr(accessor, "api_key_id", apiKey.ApiKeyId),
),
},
{
Expand All @@ -68,6 +69,7 @@ func TestUnitApiKeyResource(t *testing.T) {
resource.TestCheckResourceAttr(accessor, "name", updatedApiKey.Name),
resource.TestCheckResourceAttr(accessor, "organization_role", updatedApiKey.OrganizationRole),
resource.TestCheckResourceAttr(accessor, "api_key_secret", updatedApiKey.ApiKeySecret),
resource.TestCheckResourceAttr(accessor, "api_key_id", updatedApiKey.ApiKeyId),
),
},
},
Expand Down Expand Up @@ -135,6 +137,7 @@ func TestUnitApiKeyResource(t *testing.T) {
resource.TestCheckResourceAttr(accessor, "name", apiKey.Name),
resource.TestCheckResourceAttr(accessor, "organization_role", apiKey.OrganizationRole),
resource.TestCheckResourceAttr(accessor, "api_key_secret", "omitted"),
resource.TestCheckResourceAttr(accessor, "api_key_id", apiKey.ApiKeyId),
),
},
},
Expand Down

0 comments on commit 5bf6b2d

Please sign in to comment.