Reputation: 1
I'm new to cloudformation- I have manual created EC2 instance2 and another EC2 instance1 using cloudformation sample yaml file. I want to add the manually created instance2 using "import existing resource" option.
but i'm getting below error-
You have modified resources [MyInstance] in your template that are not being imported. Update, create or delete operations cannot be executed during import operations.
below is the yaml file
AWSTemplateFormatVersion: "2010-09-09"
Metadata:
Generator: "former2"
Description: ""
Resources:
EC2Instance:
Type: "AWS::EC2::Instance"
Properties:
ImageId: "ami-0742b4e673072006f"
InstanceType: "t2.micro"
AvailabilityZone: !GetAtt EC2Instance2.AvailabilityZone
Tenancy: "default"
SubnetId: "subnet-09ec4c74f9226b0a5"
EbsOptimized: false
SecurityGroupIds:
- "sg-0ba5c892cb4456045"
SourceDestCheck: true
BlockDeviceMappings:
-
DeviceName: "/dev/xvda"
Ebs:
Encrypted: false
VolumeSize: 8
SnapshotId: "snap-097c45e6d3c6e0d1b"
VolumeType: "gp2"
DeleteOnTermination: true
HibernationOptions:
Configured: false
EnclaveOptions:
Enabled: false
EC2Instance2:
Type: "AWS::EC2::Instance"
DeletionPolicy: "Retain"
Properties:
ImageId: "ami-05fa00d4c63e32076"
InstanceType: "t2.micro"
KeyName: "ThisIsTestKeyPair"
AvailabilityZone: !Sub "${AWS::Region}a"
Tenancy: "default"
SubnetId: "subnet-09ec4c74f9226b0a5"
EbsOptimized: false
SecurityGroupIds:
- "sg-0847c55c903c6b01d"
SourceDestCheck: true
BlockDeviceMappings:
-
DeviceName: "/dev/xvda"
Ebs:
Encrypted: false
VolumeSize: 8
SnapshotId: "snap-0834d7afbcb68e0b7"
VolumeType: "gp2"
DeleteOnTermination: true
Tags:
-
Key: "Name"
Value: "EC-manual-for-CF-testing"
HibernationOptions:
Configured: false
EnclaveOptions:
Enabled: false
Upvotes: 0
Views: 728
Reputation: 1
If you are using SAML or any other transformer, CloudFormation won't let you import new resources. https://repost.aws/knowledge-center/cloudformation-template-resources-error
Upvotes: 0
Reputation: 238985
You can't create/updated resources in CFN at the same time as you import other resources. You have to do it one, by one:
EC2Instance2
from your template and deploy EC2Instance
EC2Instance
and import the second instance.Upvotes: 2