-
Notifications
You must be signed in to change notification settings - Fork 249
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
fix: get the linked account if already linked #2735
Conversation
Hi @chmoder, thank you for the contribution. We're currently working on a key release, so we shall be able to get to reviewing this hopefully soon. We'll get to this as soon as we can and shall keep you posted. Thanks! |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2735 +/- ##
==========================================
+ Coverage 32.82% 36.50% +3.68%
==========================================
Files 98 98
Lines 26884 21923 -4961
==========================================
- Hits 8824 8003 -821
+ Misses 17902 13756 -4146
- Partials 158 164 +6 ☔ View full report in Codecov by Sentry. |
Hi @chmoder , thanks for the contribution again! We looked deeper in the issue, and decided "resources" block should only be used to create a new resource, based on terraform design principles and the error message "Error: ERR_INVALID_DATA Validation failed: The account has already been linked." would be the right error to show. If you really must need to use
You can pass |
Thank you @gmanandhar-nr, for the review and the sample solution using terraforms graphql provider. Here is my final verison if you are interested: locals {
response = jsondecode(data.graphql_query.account_id_query.query_response)
linked_accounts = local.response["data"]["actor"]["account"]["cloud"]["linkedAccounts"]
linked_account_ids = flatten([
for linked_account in local.linked_accounts :
linked_account.id if linked_account.name == var.project_id && linked_account.nrAccountId == var.nr_account_id
])
linked_account_id = length(local.linked_account_ids) > 0 ? local.linked_account_ids[0] : null
} This is a good solution and maybe this is just my lack of experience. But with other terraform resources like an IP address for example, if I create one with I may need to try using the API to see if there is a |
Hi @chmoder,
The reason we wanted to show the error, and not simply override is because someone else in the user's organization may have linked the gcp account and integrated multiple gcp resources, outside of terraform, and not showing the error would mean someone else might overwrite those without their permission. This is one way of doing it. Another way could be to use terraform import command to import the pre-existing resources. You can read more about it here: However, the first way should satisfy your use case. As discussed, closing this issue and PR. If you have more questions, feel free to reopen it. |
Description
This is my first time working on a "Go" project, terraform provider, and the new relic api. Please review my work and feel free to improve it and/or suggest improvements from me.
Uses
client.Cloud.GetLinkedAccounts
to get the already linked account ifERR_INVALID_DATA
is the response fromclient.Cloud.CloudLinkAccountWithContext
.Fixes #2733
Type of change
Please delete options that are not relevant.
Checklist:
Please delete options that are not relevant.
How to test this change?
Please describe how to test your changes. Include any relevant steps in the UI, HCL file(s), commands, etc
Try to link an already linked account using
newrelic_cloud_gcp_link_account
and reference the outputid
field in another resource.