Skip to content
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

Transaction-Id support by resource #3224

Closed
zhenwan opened this issue Oct 19, 2021 · 1 comment · Fixed by #3518
Closed

Transaction-Id support by resource #3224

zhenwan opened this issue Oct 19, 2021 · 1 comment · Fixed by #3518
Labels
service/IAMPAP Issues related to IAM Policy Management

Comments

@zhenwan
Copy link
Contributor

zhenwan commented Oct 19, 2021

Some SDKs permit users to enter a custom header Transaction-Id for debugging purpose, for example IAM Policy Management:
https://test.cloud.ibm.com/apidocs/iam-policy-management#additional-headers

but this service's Terraform Provider's resource creation does not support header Transaction-Id
https://github.com/IBM-Cloud/terraform-provider-ibm/blob/master/ibm/resource_ibm_iam_user_policy.go

Question: Does IBM Terraform Provider support custom header, i.e. Transaction-Id?

It seems Google's Terraform Provider support custom header:
hashicorp/terraform-provider-google#7299

@zhenwan
Copy link
Contributor Author

zhenwan commented Oct 19, 2021

To support Transaction-Id in our service Terraform Provider, I need to do following steps:

  • Get transaction-id in xxxCreate method:
	if _, ok := d.GetOk("transaction_id"); ok {
		createRuleOptions.SetTransactionID(d.Get("transaction_id").(string))
	}
  • In xxxRead method. I retrieve transaction-id passed in from xxxCreate, and set getxxxOptions object which is used to read the resource back:
	if _, ok := d.GetOk("transaction_id"); ok {
		transactionIDFromInput = d.Get("transaction_id").(string)
		getRuleOptions.SetTransactionID(transactionIDFromInput)
	}
  • In xxxRead method read the transaction-id from response, and set call d.Set
	transactionIDFromResponse := response.GetHeaders()["Transaction-Id"][0]
	if transactionIDFromInput != "" {
		if err = d.Set("transaction_id", transactionIDFromResponse); err != nil {
			return diag.FromErr(fmt.Errorf("Error setting transaction_id: %s", err))
		}
	}

Please let me know if this is the right way to support transaction-id in header

@kavya498 kavya498 added service/IAM Issues related to IAM service/IAMPAP Issues related to IAM Policy Management and removed service/IAM Issues related to IAM labels Oct 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
service/IAMPAP Issues related to IAM Policy Management
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants