1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package organizations
4
5import (
6	"context"
7	awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware"
8	"github.com/aws/aws-sdk-go-v2/aws/signer/v4"
9	"github.com/aws/aws-sdk-go-v2/service/organizations/types"
10	"github.com/aws/smithy-go/middleware"
11	smithyhttp "github.com/aws/smithy-go/transport/http"
12)
13
14// Creates a policy of a specified type that you can attach to a root, an
15// organizational unit (OU), or an individual AWS account. For more information
16// about policies and their use, see Managing Organization Policies
17// (https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies.html).
18// If the request includes tags, then the requester must have the
19// organizations:TagResource permission. This operation can be called only from the
20// organization's management account.
21func (c *Client) CreatePolicy(ctx context.Context, params *CreatePolicyInput, optFns ...func(*Options)) (*CreatePolicyOutput, error) {
22	if params == nil {
23		params = &CreatePolicyInput{}
24	}
25
26	result, metadata, err := c.invokeOperation(ctx, "CreatePolicy", params, optFns, c.addOperationCreatePolicyMiddlewares)
27	if err != nil {
28		return nil, err
29	}
30
31	out := result.(*CreatePolicyOutput)
32	out.ResultMetadata = metadata
33	return out, nil
34}
35
36type CreatePolicyInput struct {
37
38	// The policy text content to add to the new policy. The text that you supply must
39	// adhere to the rules of the policy type you specify in the Type parameter.
40	//
41	// This member is required.
42	Content *string
43
44	// An optional description to assign to the policy.
45	//
46	// This member is required.
47	Description *string
48
49	// The friendly name to assign to the policy. The regex pattern
50	// (http://wikipedia.org/wiki/regex) that is used to validate this parameter is a
51	// string of any of the characters in the ASCII character range.
52	//
53	// This member is required.
54	Name *string
55
56	// The type of policy to create. You can specify one of the following values:
57	//
58	// *
59	// AISERVICES_OPT_OUT_POLICY
60	// (https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_ai-opt-out.html)
61	//
62	// *
63	// BACKUP_POLICY
64	// (https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_backup.html)
65	//
66	// *
67	// SERVICE_CONTROL_POLICY
68	// (https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_scp.html)
69	//
70	// *
71	// TAG_POLICY
72	// (https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_tag-policies.html)
73	//
74	// This member is required.
75	Type types.PolicyType
76
77	// A list of tags that you want to attach to the newly created policy. For each tag
78	// in the list, you must specify both a tag key and a value. You can set the value
79	// to an empty string, but you can't set it to null. For more information about
80	// tagging, see Tagging AWS Organizations resources
81	// (https://docs.aws.amazon.com/organizations/latest/userguide/orgs_tagging.html)
82	// in the AWS Organizations User Guide. If any one of the tags is invalid or if you
83	// exceed the allowed number of tags for a policy, then the entire request fails
84	// and the policy is not created.
85	Tags []types.Tag
86
87	noSmithyDocumentSerde
88}
89
90type CreatePolicyOutput struct {
91
92	// A structure that contains details about the newly created policy.
93	Policy *types.Policy
94
95	// Metadata pertaining to the operation's result.
96	ResultMetadata middleware.Metadata
97
98	noSmithyDocumentSerde
99}
100
101func (c *Client) addOperationCreatePolicyMiddlewares(stack *middleware.Stack, options Options) (err error) {
102	err = stack.Serialize.Add(&awsAwsjson11_serializeOpCreatePolicy{}, middleware.After)
103	if err != nil {
104		return err
105	}
106	err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpCreatePolicy{}, middleware.After)
107	if err != nil {
108		return err
109	}
110	if err = addSetLoggerMiddleware(stack, options); err != nil {
111		return err
112	}
113	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
114		return err
115	}
116	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
117		return err
118	}
119	if err = addResolveEndpointMiddleware(stack, options); err != nil {
120		return err
121	}
122	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
123		return err
124	}
125	if err = addRetryMiddlewares(stack, options); err != nil {
126		return err
127	}
128	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
129		return err
130	}
131	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
132		return err
133	}
134	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
135		return err
136	}
137	if err = addClientUserAgent(stack); err != nil {
138		return err
139	}
140	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
141		return err
142	}
143	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
144		return err
145	}
146	if err = addOpCreatePolicyValidationMiddleware(stack); err != nil {
147		return err
148	}
149	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opCreatePolicy(options.Region), middleware.Before); err != nil {
150		return err
151	}
152	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
153		return err
154	}
155	if err = addResponseErrorMiddleware(stack); err != nil {
156		return err
157	}
158	if err = addRequestResponseLogging(stack, options); err != nil {
159		return err
160	}
161	return nil
162}
163
164func newServiceMetadataMiddleware_opCreatePolicy(region string) *awsmiddleware.RegisterServiceMetadata {
165	return &awsmiddleware.RegisterServiceMetadata{
166		Region:        region,
167		ServiceID:     ServiceID,
168		SigningName:   "organizations",
169		OperationName: "CreatePolicy",
170	}
171}
172