Skip to content

INTMDB-468: Hide current_certificate when X.509 Authentication Database Users are Created #985

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/stale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
stale:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v6
- uses: actions/stale@v7
id: stale
with:
stale-issue-message: 'This issue has gone 30 days without any activity and meets the project’s definition of "stale". This will be auto-closed if there is no new activity over the next 30 days. If the issue is still relevant and active, you can simply comment with a "bump" to keep it open, or add the label "not_stale". Thanks for keeping our repository healthy!'
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.18

require (
github.com/go-test/deep v1.1.0
github.com/gruntwork-io/terratest v0.41.6
github.com/gruntwork-io/terratest v0.41.7
github.com/hashicorp/terraform-plugin-sdk/v2 v2.24.1
github.com/hashicorp/terraform-provider-google v1.20.1-0.20210625223728-379bcb41c06b
github.com/mongodb-forks/digest v1.0.4
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -426,8 +426,8 @@ github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t
github.com/grpc-ecosystem/grpc-gateway v1.12.1/go.mod h1:8XEsbTttt/W+VvjtQhLACqCisSPWTxCZ7sBRjU6iH9c=
github.com/gruntwork-io/go-commons v0.8.0 h1:k/yypwrPqSeYHevLlEDmvmgQzcyTwrlZGRaxEM6G0ro=
github.com/gruntwork-io/go-commons v0.8.0/go.mod h1:gtp0yTtIBExIZp7vyIV9I0XQkVwiQZze678hvDXof78=
github.com/gruntwork-io/terratest v0.41.6 h1:BlZOu8GUzLEA2aODnyszCXSoF/jgo2AuVhk41vsqUQI=
github.com/gruntwork-io/terratest v0.41.6/go.mod h1:qH1xkPTTGx30XkMHw8jAVIbzqheSjIa5IyiTwSV2vKI=
github.com/gruntwork-io/terratest v0.41.7 h1:Vc0hb7ajWHutGA++gu/a9FSkuf+IuQuGDRymiWdrA04=
github.com/gruntwork-io/terratest v0.41.7/go.mod h1:qH1xkPTTGx30XkMHw8jAVIbzqheSjIa5IyiTwSV2vKI=
github.com/hashicorp/aws-sdk-go-base v0.7.1 h1:7s/aR3hFn74tYPVihzDyZe7y/+BorN70rr9ZvpV3j3o=
github.com/hashicorp/aws-sdk-go-base v0.7.1/go.mod h1:2fRjWDv3jJBeN6mVWFHV6hFTNeFBx2gpDLQaZNxUVAY=
github.com/hashicorp/consul/api v1.1.0/go.mod h1:VmuI/Lkw1nC05EYQWNKwWGbkg+FbDBtguAZLlVdkD9Q=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,18 @@ func resourceMongoDBAtlasX509AuthDBUserCreate(ctx context.Context, d *schema.Res
projectID := d.Get("project_id").(string)
username := d.Get("username").(string)

var currentCertificate string
var serialNumber string

if expirationMonths, ok := d.GetOk("months_until_expiration"); ok {
res, _, err := conn.X509AuthDBUsers.CreateUserCertificate(ctx, projectID, username, expirationMonths.(int))
if err != nil {
return diag.FromErr(fmt.Errorf(errorX509AuthDBUsersCreate, username, projectID, err))
}

currentCertificate = res.Certificate
serialNumber = cast.ToString(res.ID)
if err := d.Set("current_certificate", cast.ToString(res.Certificate)); err != nil {
return diag.FromErr(fmt.Errorf(errorX509AuthDBUsersSetting, "current_certificate", username, err))
}
} else {
customerX509Cas := d.Get("customer_x509_cas").(string)
_, _, err := conn.X509AuthDBUsers.SaveConfiguration(ctx, projectID, &matlas.CustomerX509{Cas: customerX509Cas})
Expand All @@ -120,9 +123,9 @@ func resourceMongoDBAtlasX509AuthDBUserCreate(ctx context.Context, d *schema.Res
}

d.SetId(encodeStateID(map[string]string{
"project_id": projectID,
"username": username,
"current_certificate": currentCertificate,
"project_id": projectID,
"username": username,
"serial_number": serialNumber,
}))

return resourceMongoDBAtlasX509AuthDBUserRead(ctx, d, meta)
Expand All @@ -134,11 +137,11 @@ func resourceMongoDBAtlasX509AuthDBUserRead(ctx context.Context, d *schema.Resou
ids := decodeStateID(d.Id())
projectID := ids["project_id"]
username := ids["username"]
currentCertificate := ids["current_certificate"]

var (
certificates []matlas.UserCertificate
err error
serialNumber string
)

if username != "" {
Expand All @@ -152,16 +155,21 @@ func resourceMongoDBAtlasX509AuthDBUserRead(ctx context.Context, d *schema.Resou
}
return diag.FromErr(fmt.Errorf(errorX509AuthDBUsersRead, username, projectID, err))
}
}

if err := d.Set("current_certificate", cast.ToString(currentCertificate)); err != nil {
return diag.FromErr(fmt.Errorf(errorX509AuthDBUsersSetting, "current_certificate", username, err))
for _, val := range certificates {
serialNumber = cast.ToString(val.ID)
}
}

if err := d.Set("certificates", flattenCertificates(certificates)); err != nil {
return diag.FromErr(fmt.Errorf(errorX509AuthDBUsersSetting, "certificates", username, err))
}

d.SetId(encodeStateID(map[string]string{
"project_id": projectID,
"username": username,
"serial_number": serialNumber,
}))

return nil
}

Expand Down