github.com/pulumi/pulumi-aws/sdk/v6@v6.32.0/go/aws/ec2/defaultSecurityGroup.go (about) 1 // Code generated by the Pulumi Terraform Bridge (tfgen) Tool DO NOT EDIT. 2 // *** WARNING: Do not edit by hand unless you're certain you know what you are doing! *** 3 4 package ec2 5 6 import ( 7 "context" 8 "reflect" 9 10 "github.com/pulumi/pulumi-aws/sdk/v6/go/aws/internal" 11 "github.com/pulumi/pulumi/sdk/v3/go/pulumi" 12 ) 13 14 // Provides a resource to manage a default security group. This resource can manage the default security group of the default or a non-default VPC. 15 // 16 // > **NOTE:** This is an advanced resource with special caveats. Please read this document in its entirety before using this resource. The `ec2.DefaultSecurityGroup` resource behaves differently from normal resources. This provider does not _create_ this resource but instead attempts to "adopt" it into management. 17 // 18 // When the provider first begins managing the default security group, it **immediately removes all ingress and egress rules in the Security Group**. It then creates any rules specified in the configuration. This way only the rules specified in the configuration are created. 19 // 20 // This resource treats its inline rules as absolute; only the rules defined inline are created, and any additions/removals external to this resource will result in diff shown. For these reasons, this resource is incompatible with the `ec2.SecurityGroupRule` resource. 21 // 22 // For more information about default security groups, see the AWS documentation on [Default Security Groups][aws-default-security-groups]. To manage normal security groups, see the `ec2.SecurityGroup` resource. 23 // 24 // ## Example Usage 25 // 26 // The following config gives the default security group the same rules that AWS provides by default but under management by this provider. This means that any ingress or egress rules added or changed will be detected as drift. 27 // 28 // <!--Start PulumiCodeChooser --> 29 // ```go 30 // package main 31 // 32 // import ( 33 // 34 // "github.com/pulumi/pulumi-aws/sdk/v6/go/aws/ec2" 35 // "github.com/pulumi/pulumi/sdk/v3/go/pulumi" 36 // 37 // ) 38 // 39 // func main() { 40 // pulumi.Run(func(ctx *pulumi.Context) error { 41 // mainvpc, err := ec2.NewVpc(ctx, "mainvpc", &ec2.VpcArgs{ 42 // CidrBlock: pulumi.String("10.1.0.0/16"), 43 // }) 44 // if err != nil { 45 // return err 46 // } 47 // _, err = ec2.NewDefaultSecurityGroup(ctx, "default", &ec2.DefaultSecurityGroupArgs{ 48 // VpcId: mainvpc.ID(), 49 // Ingress: ec2.DefaultSecurityGroupIngressArray{ 50 // &ec2.DefaultSecurityGroupIngressArgs{ 51 // Protocol: pulumi.String("-1"), 52 // Self: pulumi.Bool(true), 53 // FromPort: pulumi.Int(0), 54 // ToPort: pulumi.Int(0), 55 // }, 56 // }, 57 // Egress: ec2.DefaultSecurityGroupEgressArray{ 58 // &ec2.DefaultSecurityGroupEgressArgs{ 59 // FromPort: pulumi.Int(0), 60 // ToPort: pulumi.Int(0), 61 // Protocol: pulumi.String("-1"), 62 // CidrBlocks: pulumi.StringArray{ 63 // pulumi.String("0.0.0.0/0"), 64 // }, 65 // }, 66 // }, 67 // }) 68 // if err != nil { 69 // return err 70 // } 71 // return nil 72 // }) 73 // } 74 // 75 // ``` 76 // <!--End PulumiCodeChooser --> 77 // 78 // ### Example Config To Deny All Egress Traffic, Allowing Ingress 79 // 80 // The following denies all Egress traffic by omitting any `egress` rules, while including the default `ingress` rule to allow all traffic. 81 // 82 // <!--Start PulumiCodeChooser --> 83 // ```go 84 // package main 85 // 86 // import ( 87 // 88 // "github.com/pulumi/pulumi-aws/sdk/v6/go/aws/ec2" 89 // "github.com/pulumi/pulumi/sdk/v3/go/pulumi" 90 // 91 // ) 92 // 93 // func main() { 94 // pulumi.Run(func(ctx *pulumi.Context) error { 95 // mainvpc, err := ec2.NewVpc(ctx, "mainvpc", &ec2.VpcArgs{ 96 // CidrBlock: pulumi.String("10.1.0.0/16"), 97 // }) 98 // if err != nil { 99 // return err 100 // } 101 // _, err = ec2.NewDefaultSecurityGroup(ctx, "default", &ec2.DefaultSecurityGroupArgs{ 102 // VpcId: mainvpc.ID(), 103 // Ingress: ec2.DefaultSecurityGroupIngressArray{ 104 // &ec2.DefaultSecurityGroupIngressArgs{ 105 // Protocol: pulumi.String("-1"), 106 // Self: pulumi.Bool(true), 107 // FromPort: pulumi.Int(0), 108 // ToPort: pulumi.Int(0), 109 // }, 110 // }, 111 // }) 112 // if err != nil { 113 // return err 114 // } 115 // return nil 116 // }) 117 // } 118 // 119 // ``` 120 // <!--End PulumiCodeChooser --> 121 // 122 // ### Removing `ec2.DefaultSecurityGroup` From Your Configuration 123 // 124 // Removing this resource from your configuration will remove it from your statefile and management, but will not destroy the Security Group. All ingress or egress rules will be left as they are at the time of removal. You can resume managing them via the AWS Console. 125 // 126 // ## Import 127 // 128 // Using `pulumi import`, import Security Groups using the security group `id`. For example: 129 // 130 // ```sh 131 // $ pulumi import aws:ec2/defaultSecurityGroup:DefaultSecurityGroup default_sg sg-903004f8 132 // ``` 133 type DefaultSecurityGroup struct { 134 pulumi.CustomResourceState 135 136 // ARN of the security group. 137 Arn pulumi.StringOutput `pulumi:"arn"` 138 // Description of this rule. 139 Description pulumi.StringOutput `pulumi:"description"` 140 // Configuration block. Detailed below. 141 Egress DefaultSecurityGroupEgressArrayOutput `pulumi:"egress"` 142 // Configuration block. Detailed below. 143 Ingress DefaultSecurityGroupIngressArrayOutput `pulumi:"ingress"` 144 // Name of the security group. 145 Name pulumi.StringOutput `pulumi:"name"` 146 NamePrefix pulumi.StringOutput `pulumi:"namePrefix"` 147 // Owner ID. 148 OwnerId pulumi.StringOutput `pulumi:"ownerId"` 149 RevokeRulesOnDelete pulumi.BoolPtrOutput `pulumi:"revokeRulesOnDelete"` 150 // Map of tags to assign to the resource. If configured with a provider `defaultTags` configuration block present, tags with matching keys will overwrite those defined at the provider-level. 151 Tags pulumi.StringMapOutput `pulumi:"tags"` 152 // A map of tags assigned to the resource, including those inherited from the provider `defaultTags` configuration block. 153 // 154 // Deprecated: Please use `tags` instead. 155 TagsAll pulumi.StringMapOutput `pulumi:"tagsAll"` 156 // VPC ID. **Note that changing the `vpcId` will _not_ restore any default security group rules that were modified, added, or removed.** It will be left in its current state. 157 VpcId pulumi.StringOutput `pulumi:"vpcId"` 158 } 159 160 // NewDefaultSecurityGroup registers a new resource with the given unique name, arguments, and options. 161 func NewDefaultSecurityGroup(ctx *pulumi.Context, 162 name string, args *DefaultSecurityGroupArgs, opts ...pulumi.ResourceOption) (*DefaultSecurityGroup, error) { 163 if args == nil { 164 args = &DefaultSecurityGroupArgs{} 165 } 166 167 opts = internal.PkgResourceDefaultOpts(opts) 168 var resource DefaultSecurityGroup 169 err := ctx.RegisterResource("aws:ec2/defaultSecurityGroup:DefaultSecurityGroup", name, args, &resource, opts...) 170 if err != nil { 171 return nil, err 172 } 173 return &resource, nil 174 } 175 176 // GetDefaultSecurityGroup gets an existing DefaultSecurityGroup resource's state with the given name, ID, and optional 177 // state properties that are used to uniquely qualify the lookup (nil if not required). 178 func GetDefaultSecurityGroup(ctx *pulumi.Context, 179 name string, id pulumi.IDInput, state *DefaultSecurityGroupState, opts ...pulumi.ResourceOption) (*DefaultSecurityGroup, error) { 180 var resource DefaultSecurityGroup 181 err := ctx.ReadResource("aws:ec2/defaultSecurityGroup:DefaultSecurityGroup", name, id, state, &resource, opts...) 182 if err != nil { 183 return nil, err 184 } 185 return &resource, nil 186 } 187 188 // Input properties used for looking up and filtering DefaultSecurityGroup resources. 189 type defaultSecurityGroupState struct { 190 // ARN of the security group. 191 Arn *string `pulumi:"arn"` 192 // Description of this rule. 193 Description *string `pulumi:"description"` 194 // Configuration block. Detailed below. 195 Egress []DefaultSecurityGroupEgress `pulumi:"egress"` 196 // Configuration block. Detailed below. 197 Ingress []DefaultSecurityGroupIngress `pulumi:"ingress"` 198 // Name of the security group. 199 Name *string `pulumi:"name"` 200 NamePrefix *string `pulumi:"namePrefix"` 201 // Owner ID. 202 OwnerId *string `pulumi:"ownerId"` 203 RevokeRulesOnDelete *bool `pulumi:"revokeRulesOnDelete"` 204 // Map of tags to assign to the resource. If configured with a provider `defaultTags` configuration block present, tags with matching keys will overwrite those defined at the provider-level. 205 Tags map[string]string `pulumi:"tags"` 206 // A map of tags assigned to the resource, including those inherited from the provider `defaultTags` configuration block. 207 // 208 // Deprecated: Please use `tags` instead. 209 TagsAll map[string]string `pulumi:"tagsAll"` 210 // VPC ID. **Note that changing the `vpcId` will _not_ restore any default security group rules that were modified, added, or removed.** It will be left in its current state. 211 VpcId *string `pulumi:"vpcId"` 212 } 213 214 type DefaultSecurityGroupState struct { 215 // ARN of the security group. 216 Arn pulumi.StringPtrInput 217 // Description of this rule. 218 Description pulumi.StringPtrInput 219 // Configuration block. Detailed below. 220 Egress DefaultSecurityGroupEgressArrayInput 221 // Configuration block. Detailed below. 222 Ingress DefaultSecurityGroupIngressArrayInput 223 // Name of the security group. 224 Name pulumi.StringPtrInput 225 NamePrefix pulumi.StringPtrInput 226 // Owner ID. 227 OwnerId pulumi.StringPtrInput 228 RevokeRulesOnDelete pulumi.BoolPtrInput 229 // Map of tags to assign to the resource. If configured with a provider `defaultTags` configuration block present, tags with matching keys will overwrite those defined at the provider-level. 230 Tags pulumi.StringMapInput 231 // A map of tags assigned to the resource, including those inherited from the provider `defaultTags` configuration block. 232 // 233 // Deprecated: Please use `tags` instead. 234 TagsAll pulumi.StringMapInput 235 // VPC ID. **Note that changing the `vpcId` will _not_ restore any default security group rules that were modified, added, or removed.** It will be left in its current state. 236 VpcId pulumi.StringPtrInput 237 } 238 239 func (DefaultSecurityGroupState) ElementType() reflect.Type { 240 return reflect.TypeOf((*defaultSecurityGroupState)(nil)).Elem() 241 } 242 243 type defaultSecurityGroupArgs struct { 244 // Configuration block. Detailed below. 245 Egress []DefaultSecurityGroupEgress `pulumi:"egress"` 246 // Configuration block. Detailed below. 247 Ingress []DefaultSecurityGroupIngress `pulumi:"ingress"` 248 RevokeRulesOnDelete *bool `pulumi:"revokeRulesOnDelete"` 249 // Map of tags to assign to the resource. If configured with a provider `defaultTags` configuration block present, tags with matching keys will overwrite those defined at the provider-level. 250 Tags map[string]string `pulumi:"tags"` 251 // VPC ID. **Note that changing the `vpcId` will _not_ restore any default security group rules that were modified, added, or removed.** It will be left in its current state. 252 VpcId *string `pulumi:"vpcId"` 253 } 254 255 // The set of arguments for constructing a DefaultSecurityGroup resource. 256 type DefaultSecurityGroupArgs struct { 257 // Configuration block. Detailed below. 258 Egress DefaultSecurityGroupEgressArrayInput 259 // Configuration block. Detailed below. 260 Ingress DefaultSecurityGroupIngressArrayInput 261 RevokeRulesOnDelete pulumi.BoolPtrInput 262 // Map of tags to assign to the resource. If configured with a provider `defaultTags` configuration block present, tags with matching keys will overwrite those defined at the provider-level. 263 Tags pulumi.StringMapInput 264 // VPC ID. **Note that changing the `vpcId` will _not_ restore any default security group rules that were modified, added, or removed.** It will be left in its current state. 265 VpcId pulumi.StringPtrInput 266 } 267 268 func (DefaultSecurityGroupArgs) ElementType() reflect.Type { 269 return reflect.TypeOf((*defaultSecurityGroupArgs)(nil)).Elem() 270 } 271 272 type DefaultSecurityGroupInput interface { 273 pulumi.Input 274 275 ToDefaultSecurityGroupOutput() DefaultSecurityGroupOutput 276 ToDefaultSecurityGroupOutputWithContext(ctx context.Context) DefaultSecurityGroupOutput 277 } 278 279 func (*DefaultSecurityGroup) ElementType() reflect.Type { 280 return reflect.TypeOf((**DefaultSecurityGroup)(nil)).Elem() 281 } 282 283 func (i *DefaultSecurityGroup) ToDefaultSecurityGroupOutput() DefaultSecurityGroupOutput { 284 return i.ToDefaultSecurityGroupOutputWithContext(context.Background()) 285 } 286 287 func (i *DefaultSecurityGroup) ToDefaultSecurityGroupOutputWithContext(ctx context.Context) DefaultSecurityGroupOutput { 288 return pulumi.ToOutputWithContext(ctx, i).(DefaultSecurityGroupOutput) 289 } 290 291 // DefaultSecurityGroupArrayInput is an input type that accepts DefaultSecurityGroupArray and DefaultSecurityGroupArrayOutput values. 292 // You can construct a concrete instance of `DefaultSecurityGroupArrayInput` via: 293 // 294 // DefaultSecurityGroupArray{ DefaultSecurityGroupArgs{...} } 295 type DefaultSecurityGroupArrayInput interface { 296 pulumi.Input 297 298 ToDefaultSecurityGroupArrayOutput() DefaultSecurityGroupArrayOutput 299 ToDefaultSecurityGroupArrayOutputWithContext(context.Context) DefaultSecurityGroupArrayOutput 300 } 301 302 type DefaultSecurityGroupArray []DefaultSecurityGroupInput 303 304 func (DefaultSecurityGroupArray) ElementType() reflect.Type { 305 return reflect.TypeOf((*[]*DefaultSecurityGroup)(nil)).Elem() 306 } 307 308 func (i DefaultSecurityGroupArray) ToDefaultSecurityGroupArrayOutput() DefaultSecurityGroupArrayOutput { 309 return i.ToDefaultSecurityGroupArrayOutputWithContext(context.Background()) 310 } 311 312 func (i DefaultSecurityGroupArray) ToDefaultSecurityGroupArrayOutputWithContext(ctx context.Context) DefaultSecurityGroupArrayOutput { 313 return pulumi.ToOutputWithContext(ctx, i).(DefaultSecurityGroupArrayOutput) 314 } 315 316 // DefaultSecurityGroupMapInput is an input type that accepts DefaultSecurityGroupMap and DefaultSecurityGroupMapOutput values. 317 // You can construct a concrete instance of `DefaultSecurityGroupMapInput` via: 318 // 319 // DefaultSecurityGroupMap{ "key": DefaultSecurityGroupArgs{...} } 320 type DefaultSecurityGroupMapInput interface { 321 pulumi.Input 322 323 ToDefaultSecurityGroupMapOutput() DefaultSecurityGroupMapOutput 324 ToDefaultSecurityGroupMapOutputWithContext(context.Context) DefaultSecurityGroupMapOutput 325 } 326 327 type DefaultSecurityGroupMap map[string]DefaultSecurityGroupInput 328 329 func (DefaultSecurityGroupMap) ElementType() reflect.Type { 330 return reflect.TypeOf((*map[string]*DefaultSecurityGroup)(nil)).Elem() 331 } 332 333 func (i DefaultSecurityGroupMap) ToDefaultSecurityGroupMapOutput() DefaultSecurityGroupMapOutput { 334 return i.ToDefaultSecurityGroupMapOutputWithContext(context.Background()) 335 } 336 337 func (i DefaultSecurityGroupMap) ToDefaultSecurityGroupMapOutputWithContext(ctx context.Context) DefaultSecurityGroupMapOutput { 338 return pulumi.ToOutputWithContext(ctx, i).(DefaultSecurityGroupMapOutput) 339 } 340 341 type DefaultSecurityGroupOutput struct{ *pulumi.OutputState } 342 343 func (DefaultSecurityGroupOutput) ElementType() reflect.Type { 344 return reflect.TypeOf((**DefaultSecurityGroup)(nil)).Elem() 345 } 346 347 func (o DefaultSecurityGroupOutput) ToDefaultSecurityGroupOutput() DefaultSecurityGroupOutput { 348 return o 349 } 350 351 func (o DefaultSecurityGroupOutput) ToDefaultSecurityGroupOutputWithContext(ctx context.Context) DefaultSecurityGroupOutput { 352 return o 353 } 354 355 // ARN of the security group. 356 func (o DefaultSecurityGroupOutput) Arn() pulumi.StringOutput { 357 return o.ApplyT(func(v *DefaultSecurityGroup) pulumi.StringOutput { return v.Arn }).(pulumi.StringOutput) 358 } 359 360 // Description of this rule. 361 func (o DefaultSecurityGroupOutput) Description() pulumi.StringOutput { 362 return o.ApplyT(func(v *DefaultSecurityGroup) pulumi.StringOutput { return v.Description }).(pulumi.StringOutput) 363 } 364 365 // Configuration block. Detailed below. 366 func (o DefaultSecurityGroupOutput) Egress() DefaultSecurityGroupEgressArrayOutput { 367 return o.ApplyT(func(v *DefaultSecurityGroup) DefaultSecurityGroupEgressArrayOutput { return v.Egress }).(DefaultSecurityGroupEgressArrayOutput) 368 } 369 370 // Configuration block. Detailed below. 371 func (o DefaultSecurityGroupOutput) Ingress() DefaultSecurityGroupIngressArrayOutput { 372 return o.ApplyT(func(v *DefaultSecurityGroup) DefaultSecurityGroupIngressArrayOutput { return v.Ingress }).(DefaultSecurityGroupIngressArrayOutput) 373 } 374 375 // Name of the security group. 376 func (o DefaultSecurityGroupOutput) Name() pulumi.StringOutput { 377 return o.ApplyT(func(v *DefaultSecurityGroup) pulumi.StringOutput { return v.Name }).(pulumi.StringOutput) 378 } 379 380 func (o DefaultSecurityGroupOutput) NamePrefix() pulumi.StringOutput { 381 return o.ApplyT(func(v *DefaultSecurityGroup) pulumi.StringOutput { return v.NamePrefix }).(pulumi.StringOutput) 382 } 383 384 // Owner ID. 385 func (o DefaultSecurityGroupOutput) OwnerId() pulumi.StringOutput { 386 return o.ApplyT(func(v *DefaultSecurityGroup) pulumi.StringOutput { return v.OwnerId }).(pulumi.StringOutput) 387 } 388 389 func (o DefaultSecurityGroupOutput) RevokeRulesOnDelete() pulumi.BoolPtrOutput { 390 return o.ApplyT(func(v *DefaultSecurityGroup) pulumi.BoolPtrOutput { return v.RevokeRulesOnDelete }).(pulumi.BoolPtrOutput) 391 } 392 393 // Map of tags to assign to the resource. If configured with a provider `defaultTags` configuration block present, tags with matching keys will overwrite those defined at the provider-level. 394 func (o DefaultSecurityGroupOutput) Tags() pulumi.StringMapOutput { 395 return o.ApplyT(func(v *DefaultSecurityGroup) pulumi.StringMapOutput { return v.Tags }).(pulumi.StringMapOutput) 396 } 397 398 // A map of tags assigned to the resource, including those inherited from the provider `defaultTags` configuration block. 399 // 400 // Deprecated: Please use `tags` instead. 401 func (o DefaultSecurityGroupOutput) TagsAll() pulumi.StringMapOutput { 402 return o.ApplyT(func(v *DefaultSecurityGroup) pulumi.StringMapOutput { return v.TagsAll }).(pulumi.StringMapOutput) 403 } 404 405 // VPC ID. **Note that changing the `vpcId` will _not_ restore any default security group rules that were modified, added, or removed.** It will be left in its current state. 406 func (o DefaultSecurityGroupOutput) VpcId() pulumi.StringOutput { 407 return o.ApplyT(func(v *DefaultSecurityGroup) pulumi.StringOutput { return v.VpcId }).(pulumi.StringOutput) 408 } 409 410 type DefaultSecurityGroupArrayOutput struct{ *pulumi.OutputState } 411 412 func (DefaultSecurityGroupArrayOutput) ElementType() reflect.Type { 413 return reflect.TypeOf((*[]*DefaultSecurityGroup)(nil)).Elem() 414 } 415 416 func (o DefaultSecurityGroupArrayOutput) ToDefaultSecurityGroupArrayOutput() DefaultSecurityGroupArrayOutput { 417 return o 418 } 419 420 func (o DefaultSecurityGroupArrayOutput) ToDefaultSecurityGroupArrayOutputWithContext(ctx context.Context) DefaultSecurityGroupArrayOutput { 421 return o 422 } 423 424 func (o DefaultSecurityGroupArrayOutput) Index(i pulumi.IntInput) DefaultSecurityGroupOutput { 425 return pulumi.All(o, i).ApplyT(func(vs []interface{}) *DefaultSecurityGroup { 426 return vs[0].([]*DefaultSecurityGroup)[vs[1].(int)] 427 }).(DefaultSecurityGroupOutput) 428 } 429 430 type DefaultSecurityGroupMapOutput struct{ *pulumi.OutputState } 431 432 func (DefaultSecurityGroupMapOutput) ElementType() reflect.Type { 433 return reflect.TypeOf((*map[string]*DefaultSecurityGroup)(nil)).Elem() 434 } 435 436 func (o DefaultSecurityGroupMapOutput) ToDefaultSecurityGroupMapOutput() DefaultSecurityGroupMapOutput { 437 return o 438 } 439 440 func (o DefaultSecurityGroupMapOutput) ToDefaultSecurityGroupMapOutputWithContext(ctx context.Context) DefaultSecurityGroupMapOutput { 441 return o 442 } 443 444 func (o DefaultSecurityGroupMapOutput) MapIndex(k pulumi.StringInput) DefaultSecurityGroupOutput { 445 return pulumi.All(o, k).ApplyT(func(vs []interface{}) *DefaultSecurityGroup { 446 return vs[0].(map[string]*DefaultSecurityGroup)[vs[1].(string)] 447 }).(DefaultSecurityGroupOutput) 448 } 449 450 func init() { 451 pulumi.RegisterInputType(reflect.TypeOf((*DefaultSecurityGroupInput)(nil)).Elem(), &DefaultSecurityGroup{}) 452 pulumi.RegisterInputType(reflect.TypeOf((*DefaultSecurityGroupArrayInput)(nil)).Elem(), DefaultSecurityGroupArray{}) 453 pulumi.RegisterInputType(reflect.TypeOf((*DefaultSecurityGroupMapInput)(nil)).Elem(), DefaultSecurityGroupMap{}) 454 pulumi.RegisterOutputType(DefaultSecurityGroupOutput{}) 455 pulumi.RegisterOutputType(DefaultSecurityGroupArrayOutput{}) 456 pulumi.RegisterOutputType(DefaultSecurityGroupMapOutput{}) 457 }